Bug 59849

Summary: Avoid allocating a new image buffer in ~CanvasRenderingContext2D()
Product: WebKit Reporter: Simon Fraser (smfr) <simon.fraser>
Component: CanvasAssignee: Simon Fraser (smfr) <simon.fraser>
Status: RESOLVED FIXED    
Severity: Normal CC: aroben, mdelaney7, simon.fraser
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
Patch
none
Patch darin: review+

Description Simon Fraser (smfr) 2011-04-29 17:35:21 PDT
The code I added to ~CanvasRenderingContext2D() to unwind the graphics stack can end up allocating a new image buffer, which is bad.
Comment 1 Simon Fraser (smfr) 2011-04-29 17:35:43 PDT
<rdar://problem/9362156>
Comment 2 Simon Fraser (smfr) 2011-05-04 10:30:12 PDT
Created attachment 92273 [details]
Patch
Comment 3 Darin Adler 2011-05-04 10:32:34 PDT
Comment on attachment 92273 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=92273&action=review

> Source/WebCore/html/HTMLCanvasElement.h:103
> -    GraphicsContext* drawingContext() const;
> +    enum ImageBufferCreation { AllowImageBufferCreation, DisallowImageBufferCreation };
> +    GraphicsContext* drawingContext(ImageBufferCreation allowBufferCreation = AllowImageBufferCreation) const;

Can we just add a second function with this behavior? Or maybe just a function that returns a boolean to tell us if we already have a buffer? I think that adding this argument is unnecessary given how simple the function is.
Comment 4 Darin Adler 2011-05-04 10:33:37 PDT
Comment on attachment 92273 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=92273&action=review

>> Source/WebCore/html/HTMLCanvasElement.h:103
>> +    GraphicsContext* drawingContext(ImageBufferCreation allowBufferCreation = AllowImageBufferCreation) const;
> 
> Can we just add a second function with this behavior? Or maybe just a function that returns a boolean to tell us if we already have a buffer? I think that adding this argument is unnecessary given how simple the function is.

One possible name for a new function would be existingDrawingContext. But I think that the hasImageBuffer solution would be fine.
Comment 5 Simon Fraser (smfr) 2011-05-04 10:39:46 PDT
Comment on attachment 92273 [details]
Patch

Yeah, sounds good.
Comment 6 Simon Fraser (smfr) 2011-05-04 10:42:27 PDT
Created attachment 92278 [details]
Patch
Comment 7 Simon Fraser (smfr) 2011-05-04 10:51:14 PDT
http://trac.webkit.org/changeset/85760