Title: [95658] trunk/Source/WebCore
- Revision
- 95658
- Author
- [email protected]
- Date
- 2011-09-21 12:11:40 -0700 (Wed, 21 Sep 2011)
Log Message
[chromium] Optimize ImageBuffer constructor when accelerated
https://bugs.webkit.org/show_bug.cgi?id=68501
If the accelerated rendering mode is passed in to ImageBuffer, instead
of creating a bitmap PlatformCanvas and subsequently replacing its
device with an SkGpuDevice, create an SkCanvas and SkGpuDevice first,
and fall back to raster creation only failure. This saves on system
RAM for the backing store (and possibly GDI resources).
Reviewed by James Robinson.
Covered by existing tests.
* platform/graphics/gpu/SharedGraphicsContext3D.cpp:
(WebCore::SharedGraphicsContext3D::get):
* platform/graphics/gpu/SharedGraphicsContext3D.h:
Rename "SharedGraphicsContext3D::create()" to "get()" to more
accurately reflect its function.
* platform/graphics/skia/ImageBufferSkia.cpp:
(WebCore::createAcceleratedCanvas):
Refactor creation of accelerated ImageBuffer.
(WebCore::ImageBuffer::ImageBuffer):
Attempt creation of accelerated ImageBuffer first, and only fall back
to bitmap-backed canvas creation if it fails.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (95657 => 95658)
--- trunk/Source/WebCore/ChangeLog 2011-09-21 19:06:29 UTC (rev 95657)
+++ trunk/Source/WebCore/ChangeLog 2011-09-21 19:11:40 UTC (rev 95658)
@@ -1,3 +1,30 @@
+2011-09-21 Stephen White <[email protected]>
+
+ [chromium] Optimize ImageBuffer constructor when accelerated
+ https://bugs.webkit.org/show_bug.cgi?id=68501
+
+ If the accelerated rendering mode is passed in to ImageBuffer, instead
+ of creating a bitmap PlatformCanvas and subsequently replacing its
+ device with an SkGpuDevice, create an SkCanvas and SkGpuDevice first,
+ and fall back to raster creation only failure. This saves on system
+ RAM for the backing store (and possibly GDI resources).
+
+ Reviewed by James Robinson.
+
+ Covered by existing tests.
+
+ * platform/graphics/gpu/SharedGraphicsContext3D.cpp:
+ (WebCore::SharedGraphicsContext3D::get):
+ * platform/graphics/gpu/SharedGraphicsContext3D.h:
+ Rename "SharedGraphicsContext3D::create()" to "get()" to more
+ accurately reflect its function.
+ * platform/graphics/skia/ImageBufferSkia.cpp:
+ (WebCore::createAcceleratedCanvas):
+ Refactor creation of accelerated ImageBuffer.
+ (WebCore::ImageBuffer::ImageBuffer):
+ Attempt creation of accelerated ImageBuffer first, and only fall back
+ to bitmap-backed canvas creation if it fails.
+
2011-09-21 Dan Bernstein <[email protected]>
WebCore part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
Modified: trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp (95657 => 95658)
--- trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp 2011-09-21 19:06:29 UTC (rev 95657)
+++ trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp 2011-09-21 19:11:40 UTC (rev 95658)
@@ -30,7 +30,7 @@
namespace WebCore {
-GraphicsContext3D* SharedGraphicsContext3D::create(HostWindow* window)
+GraphicsContext3D* SharedGraphicsContext3D::get()
{
GraphicsContext3D::Attributes attributes;
attributes.depth = false;
@@ -38,7 +38,7 @@
attributes.antialias = false;
attributes.canRecoverFromContextLoss = false; // Canvas contexts can not handle lost contexts.
attributes.shareResources = true;
- static RefPtr<GraphicsContext3D> context = GraphicsContext3D::create(attributes, window);
+ static RefPtr<GraphicsContext3D> context = GraphicsContext3D::create(attributes, 0);
return context.get();
}
Modified: trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h (95657 => 95658)
--- trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h 2011-09-21 19:06:29 UTC (rev 95657)
+++ trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h 2011-09-21 19:11:40 UTC (rev 95658)
@@ -34,7 +34,7 @@
class SharedGraphicsContext3D {
public:
- static GraphicsContext3D* create(HostWindow*);
+ static GraphicsContext3D* get();
};
}
Modified: trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp (95657 => 95658)
--- trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp 2011-09-21 19:06:29 UTC (rev 95657)
+++ trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp 2011-09-21 19:11:40 UTC (rev 95658)
@@ -64,11 +64,46 @@
{
}
+static SkCanvas* createAcceleratedCanvas(const IntSize& size, ImageBufferData* data)
+{
+ GraphicsContext3D* context3D = SharedGraphicsContext3D::get();
+ if (!context3D)
+ return 0;
+ GrContext* gr = context3D->grContext();
+ if (!gr)
+ return 0;
+ gr->resetContext();
+ GrTextureDesc desc;
+ desc.fFlags = kRenderTarget_GrTextureFlagBit;
+ desc.fAALevel = kNone_GrAALevel;
+ desc.fWidth = size.width();
+ desc.fHeight = size.height();
+ desc.fFormat = kRGBA_8888_GrPixelConfig;
+ SkAutoTUnref<GrTexture> texture(gr->createUncachedTexture(desc, 0, 0));
+ if (!texture.get())
+ return 0;
+ SkCanvas* canvas = new SkCanvas();
+ canvas->setDevice(new SkGpuDevice(gr, texture.get()))->unref();
+ data->m_platformContext.setGraphicsContext3D(context3D);
+#if USE(ACCELERATED_COMPOSITING)
+ data->m_platformLayer = Canvas2DLayerChromium::create(context3D);
+ data->m_platformLayer->setTextureId(texture.get()->getTextureHandle());
+#endif
+ return canvas;
+}
+
ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, RenderingMode renderingMode, bool& success)
: m_data(size)
, m_size(size)
{
- OwnPtr<SkCanvas> canvas = adoptPtr(skia::TryCreateBitmapCanvas(size.width(), size.height(), false));
+ OwnPtr<SkCanvas> canvas;
+
+ if (renderingMode == Accelerated)
+ canvas = adoptPtr(createAcceleratedCanvas(size, &m_data));
+
+ if (!canvas)
+ canvas = adoptPtr(skia::TryCreateBitmapCanvas(size.width(), size.height(), false));
+
if (!canvas) {
success = false;
return;
@@ -83,30 +118,6 @@
// required, but the canvas is currently filled with the magic transparency
// color. Can we have another way to manage this?
m_data.m_canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
- if (renderingMode == Accelerated) {
- GraphicsContext3D* context3D = SharedGraphicsContext3D::create(0);
- if (context3D) {
- GrContext* gr = context3D->grContext();
- if (gr) {
- gr->resetContext();
- GrTextureDesc desc;
- desc.fFlags = kRenderTarget_GrTextureFlagBit;
- desc.fAALevel = kNone_GrAALevel;
- desc.fWidth = size.width();
- desc.fHeight = size.height();
- desc.fFormat = kRGBA_8888_GrPixelConfig;
- SkAutoTUnref<GrTexture> texture(gr->createUncachedTexture(desc, 0, 0));
- if (texture.get()) {
- m_data.m_canvas->setDevice(new SkGpuDevice(gr, texture.get()))->unref();
- m_context->platformContext()->setGraphicsContext3D(context3D);
-#if USE(ACCELERATED_COMPOSITING)
- m_data.m_platformLayer = Canvas2DLayerChromium::create(context3D);
- m_data.m_platformLayer->setTextureId(texture.get()->getTextureHandle());
-#endif
- }
- }
- }
- }
success = true;
}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes