Closed Bug 1289975 Opened 8 years ago Closed 8 years ago

Do not reset layer when setting the same dimension to canvas

Categories

(Core :: Graphics: Canvas2D, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla51
Tracking Status
firefox51 --- fixed

People

(Reporter: ethlin, Assigned: ethlin)

References

Details

Attachments

(2 files, 1 obsolete file)

We always reset layer when doing setDimension. I think we can reuse the layer and buffer if the dimension is the same. Then the layer doesn't need to realloate buffer.
:nical, do you think we should do it?
Flags: needinfo?(nical.bugzilla)
Per spec, touching the canvas size (even without changing it) resets the canvas drawing state. If we want to reuse the buffer, it's fine but we need to be very careful about not keeping around any additional drawing state like transforms, clips or whatnot.

I don't feel very strongly for or against keeping the canvas buffer in that case as long as it doesn't complicate the code too much, although I would rather encourage web authors to not use SetDimension as a way to clear the canvas since it is going to be slower in any case.

Do you have an idea of how often web authors touch the dimensions of a canvas without changing the actual values?
Flags: needinfo?(nical.bugzilla)
(In reply to Nicolas Silva [:nical] from comment #2)
> Per spec, touching the canvas size (even without changing it) resets the
> canvas drawing state. If we want to reuse the buffer, it's fine but we need
> to be very careful about not keeping around any additional drawing state
> like transforms, clips or whatnot.
> 
> I don't feel very strongly for or against keeping the canvas buffer in that
> case as long as it doesn't complicate the code too much, although I would
> rather encourage web authors to not use SetDimension as a way to clear the
> canvas since it is going to be slower in any case.
> 
> Do you have an idea of how often web authors touch the dimensions of a
> canvas without changing the actual values?

I don't know how often the web authors set the same dimension. But I tried this case on chrome and safari and I believe they reused the buffer. From my test, if a page keeps setting the same dimension to a large canvas, firefox will use a lot of CPU resource and will have memory fragment problem in the end, then crash.
So yes, if the code doesn't complicate, I think it's good to have the reusing buffer mechanism.
Attached patch reuse buffer. (obsolete) — Splinter Review
Keep the buffer provider while the dimension is the same.
Attached file testcase
This html keeps setting the same dimension for each frame.
Attached patch reuse bufferSplinter Review
In this patch, I check the dimension before ClearTarget. If the dimension is the same, then keep the BufferProvider and clear the buffer data.
I tried the testcase attachment 8777213 [details] With BufferProviderShared, the FPS increased to 24 from 18 on windows.
Attachment #8776896 - Attachment is obsolete: true
Attachment #8777215 - Flags: review?(nical.bugzilla)
Attachment #8777215 - Flags: review?(nical.bugzilla) → review+
Keywords: checkin-needed
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/e3758ab7ee78
Reuse canvas buffer when setting the same dimension. r=nical
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/e3758ab7ee78
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla51
Depends on: 1341521
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: