12011-08-15 Stephen White <senorblanco@chromium.org>
2
3 Canvas resizing can be slow
4 https://bugs.webkit.org/show_bug.cgi?id=66251
5
6 Canvas resizing was slow due to re-allocation of the ImageBuffer on
7 each size change (width or height). This was introduced inadvertently
8 by calls to isAccelerated() during canvas reset(). Since we won't
9 know if we have successfully accelerated until ImageBuffer creation,
10 move the compositor invalidation to createImageBuffer() as well.
11 This patch also attempts to unify the Skia and CG accelerated canvas
12 paths. The DrawingBuffer used by the Skia path is now owned by
13 ImageBuffer[Skia], similar to how the IOSurface is owned by
14 ImageBuffer[CG]. Some of the logic for when to accelerate was moved
15 into HTMLCanvasElement and unified with the CG path. Acceleration is
16 also now enabled by the same "Accelerated" ImageBuffer create flag
17 used by the CG path. DrawingBuffer is now re-created even for a
18 same-size change (same as the memory buffer), but we speed it up
19 by calling GraphicsContext3D::texImage2D() with a NULL pixels ptr
20 instead of GraphicsContext3D::teximage2DResourceSafe() (no need to
21 clear it, since it's done with a glClear anyway).
22
23 Reviewed by NOBODY (OOPS!).
24
25 Covered by existing tests in fast/canvas and canvas/philip.
26
27 * html/HTMLCanvasElement.cpp:
28 (WebCore::HTMLCanvasElement::reset):
29 Don't call isAccelerated() from reset(), since we don't want to
30 inadvertently create the ImageBuffer. Also, since we won't know if
31 we have successfully accelerated until createImageBuffer() is
32 called, defer the compositor invalidation to createImageBuffer() as
33 well.
34 (WebCore::HTMLCanvasElement::shouldAccelerate):
35 Unify the CG and Skia ports' logic for when to accelerate (Skia
36 logic moved in from CanvasRenderingContext2D).
37 (WebCore::HTMLCanvasElement::createImageBuffer):
38 Use the unified shouldAccelerate() logic, and pass it as a flag
39 to ImageBuffer. Do compositor invalidation as well.
40 * html/HTMLCanvasElement.h:
41 (WebCore::HTMLCanvasElement::hasCreatedImageBuffer):
42 Expose hasCreatedImageBuffer() publically, so
43 CanvasRenderingContext2D::isAccelerated() doesn't inadvertently create
44 it.
45 * html/canvas/CanvasRenderingContext2D.cpp:
46 (WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
47 (WebCore::CanvasRenderingContext2D::~CanvasRenderingContext2D):
48 Remove all acceleration setting and resetting, since it's now done
49 during ImageBuffer creation.
50 (WebCore::CanvasRenderingContext2D::isAccelerated):
51 Check if the image buffer was created, so we don't inadvertently
52 create it here.
53 (WebCore::CanvasRenderingContext2D::paintsIntoCanvasBuffer):
54 Don't call GraphicsContext3D::paintsIntoCanvasBuffer(), since its
55 WebViewImpl may be null. Ask the render tree instead.
56 (WebCore::CanvasRenderingContext2D::reset):
57 Don't reset acceleration here, since we don't own it anymore.
58 (WebCore::CanvasRenderingContext2D::platformLayer):
59 Call into the ImageBuffer to get our PlatformLayer.
60 * html/canvas/CanvasRenderingContext2D.h:
61 Remove m_drawingBuffer, and all acceleration-related calls.
62 * platform/graphics/GraphicsContext.cpp:
63 * platform/graphics/GraphicsContext.h:
64 Remove setGraphicsContext3D(), and paintsIntoImageBuffer().
65 * platform/graphics/ImageBuffer.cpp:
66 (WebCore::ImageBuffer::platformLayer):
67 Implement a dummy platformLayer() call for non-skia ports.
68 * platform/graphics/ImageBuffer.h:
69 Declare a platformLayer() call (USE(ACCELERATED_COMPOSITING) only).
70 * platform/graphics/chromium/ImageBufferDataSkia.h:
71 Add a DrawingBuffer data member.
72 * platform/graphics/gpu/DrawingBuffer.cpp:
73 (WebCore::DrawingBuffer::reset):
74 Use texImage2D() with a NULL ptr, not texImage2DResourceSafe().
75 Since we immediately clear the framebuffer via glClear(), this whole
76 resource safe business is overkill.
77 * platform/graphics/skia/GraphicsContextSkia.cpp:
78 Remove setGraphicsContext3D() and paintsIntoImageBuffer(). This
79 functionality is handled by ImageBuffer now.
80 * platform/graphics/skia/ImageBufferSkia.cpp:
81 (WebCore::ImageBuffer::ImageBuffer):
82 Give the ImageBufferData ownership of the DrawingBuffer.
83 (WebCore::ImageBuffer::platformLayer):
84 Implement an accessor for the DrawingBuffer's PlatformLayer.
85 * platform/graphics/skia/PlatformContextSkia.cpp:
86 (WebCore::PlatformContextSkia::setGraphicsContext3D):
87 * platform/graphics/skia/PlatformContextSkia.h:
88 Remove isPathSkiaSafe() extern (unused).
89 Remove paintsIntoImageBuffer() (now unused). Remove IntSize param
90 from setGraphicsContext3D() (unused).
91