Title: [110483] trunk/Source
Revision
110483
Author
[email protected]
Date
2012-03-12 14:52:14 -0700 (Mon, 12 Mar 2012)

Log Message

[chromium] Restore canvas2D acceleration after context loss.
https://bugs.webkit.org/show_bug.cgi?id=80629

Reviewed by James Robinson.

Covered by existing canvas tests, and manual testing (killing the GPU
process).

Source/WebCore: 

* platform/graphics/chromium/Canvas2DLayerChromium.cpp:
(WebCore::Canvas2DLayerChromium::create):
(WebCore::Canvas2DLayerChromium::Canvas2DLayerChromium):
(WebCore::Canvas2DLayerChromium::setNeedsDisplayRect):
(WebCore::Canvas2DLayerChromium::drawsContent):
(WebCore::Canvas2DLayerChromium::paintContentsIfDirty):
* platform/graphics/chromium/Canvas2DLayerChromium.h:
(Canvas2DLayerChromium):
* platform/graphics/chromium/cc/CCRenderSurface.cpp:
(WebCore::CCRenderSurface::applyFilters):
* platform/graphics/gpu/SharedGraphicsContext3D.cpp:
(SharedGraphicsContext3DImpl):
(WebCore::SharedGraphicsContext3DImpl::SharedGraphicsContext3DImpl):
(WebCore::SharedGraphicsContext3DImpl::get):
(WebCore):
(WebCore::SharedGraphicsContext3D::get):
* platform/graphics/gpu/SharedGraphicsContext3D.h:
(SharedGraphicsContext3D):
* platform/graphics/skia/ImageBufferSkia.cpp:
(WebCore::createAcceleratedCanvas):
* platform/graphics/skia/PlatformContextSkia.cpp:
(WebCore::PlatformContextSkia::PlatformContextSkia):
(WebCore):
* platform/graphics/skia/PlatformContextSkia.h:
(WebCore):
(WebCore::PlatformContextSkia::isAccelerated):
(WebCore::PlatformContextSkia::setAccelerated):
(PlatformContextSkia):

Source/WebKit/chromium: 

* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::sharedGraphicsContext3D):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (110482 => 110483)


--- trunk/Source/WebCore/ChangeLog	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebCore/ChangeLog	2012-03-12 21:52:14 UTC (rev 110483)
@@ -1,3 +1,42 @@
+2012-03-12  Stephen White  <[email protected]>
+
+        [chromium] Restore canvas2D acceleration after context loss.
+        https://bugs.webkit.org/show_bug.cgi?id=80629
+
+        Reviewed by James Robinson.
+
+        Covered by existing canvas tests, and manual testing (killing the GPU
+        process).
+
+        * platform/graphics/chromium/Canvas2DLayerChromium.cpp:
+        (WebCore::Canvas2DLayerChromium::create):
+        (WebCore::Canvas2DLayerChromium::Canvas2DLayerChromium):
+        (WebCore::Canvas2DLayerChromium::setNeedsDisplayRect):
+        (WebCore::Canvas2DLayerChromium::drawsContent):
+        (WebCore::Canvas2DLayerChromium::paintContentsIfDirty):
+        * platform/graphics/chromium/Canvas2DLayerChromium.h:
+        (Canvas2DLayerChromium):
+        * platform/graphics/chromium/cc/CCRenderSurface.cpp:
+        (WebCore::CCRenderSurface::applyFilters):
+        * platform/graphics/gpu/SharedGraphicsContext3D.cpp:
+        (SharedGraphicsContext3DImpl):
+        (WebCore::SharedGraphicsContext3DImpl::SharedGraphicsContext3DImpl):
+        (WebCore::SharedGraphicsContext3DImpl::get):
+        (WebCore):
+        (WebCore::SharedGraphicsContext3D::get):
+        * platform/graphics/gpu/SharedGraphicsContext3D.h:
+        (SharedGraphicsContext3D):
+        * platform/graphics/skia/ImageBufferSkia.cpp:
+        (WebCore::createAcceleratedCanvas):
+        * platform/graphics/skia/PlatformContextSkia.cpp:
+        (WebCore::PlatformContextSkia::PlatformContextSkia):
+        (WebCore):
+        * platform/graphics/skia/PlatformContextSkia.h:
+        (WebCore):
+        (WebCore::PlatformContextSkia::isAccelerated):
+        (WebCore::PlatformContextSkia::setAccelerated):
+        (PlatformContextSkia):
+
 2012-03-12  George Staikos  <[email protected]>
 
         It doesn't make sense to return const unsigned, and GCC warns about it.

Modified: trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp (110482 => 110483)


--- trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp	2012-03-12 21:52:14 UTC (rev 110483)
@@ -45,14 +45,15 @@
 
 namespace WebCore {
 
-PassRefPtr<Canvas2DLayerChromium> Canvas2DLayerChromium::create(GraphicsContext3D* context, const IntSize& size)
+PassRefPtr<Canvas2DLayerChromium> Canvas2DLayerChromium::create(PassRefPtr<GraphicsContext3D> context, const IntSize& size)
 {
     return adoptRef(new Canvas2DLayerChromium(context, size));
 }
 
-Canvas2DLayerChromium::Canvas2DLayerChromium(GraphicsContext3D* context, const IntSize& size)
+Canvas2DLayerChromium::Canvas2DLayerChromium(PassRefPtr<GraphicsContext3D> context, const IntSize& size)
     : CanvasLayerChromium()
     , m_context(context)
+    , m_contextLost(false)
     , m_size(size)
     , m_backTextureId(0)
     , m_fbo(0)
@@ -67,6 +68,8 @@
 {
     if (m_useDoubleBuffering && m_fbo)
        GLC(m_context, m_context->deleteFramebuffer(m_fbo));
+    if (m_context && layerTreeHost())
+        layerTreeHost()->stopRateLimiter(m_context.get());
 }
 
 void Canvas2DLayerChromium::setTextureId(unsigned textureId)
@@ -80,13 +83,13 @@
     LayerChromium::setNeedsDisplayRect(dirtyRect);
 
     if (layerTreeHost())
-        layerTreeHost()->startRateLimiter(m_context);
+        layerTreeHost()->startRateLimiter(m_context.get());
 }
 
 bool Canvas2DLayerChromium::drawsContent() const
 {
     return LayerChromium::drawsContent() && m_backTextureId && !m_size.isEmpty()
-        && m_context && (m_context->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR);
+        && !m_contextLost;
 }
 
 void Canvas2DLayerChromium::setCanvas(SkCanvas* canvas)
@@ -111,6 +114,10 @@
     bool success = m_context->makeContextCurrent();
     ASSERT_UNUSED(success, success);
 
+    m_contextLost = m_context->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
+    if (m_contextLost)
+        return;
+
     if (m_canvas) {
         TRACE_EVENT("SkDeferredCanvas::flush", m_canvas, 0);
         m_canvas->flush();

Modified: trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h (110482 => 110483)


--- trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h	2012-03-12 21:52:14 UTC (rev 110483)
@@ -47,7 +47,7 @@
 // A layer containing an accelerated 2d canvas
 class Canvas2DLayerChromium : public CanvasLayerChromium {
 public:
-    static PassRefPtr<Canvas2DLayerChromium> create(GraphicsContext3D*, const IntSize&);
+    static PassRefPtr<Canvas2DLayerChromium> create(PassRefPtr<GraphicsContext3D>, const IntSize&);
     virtual ~Canvas2DLayerChromium();
 
     void setTextureId(unsigned);
@@ -65,12 +65,13 @@
     void setCanvas(SkCanvas*);
 
 private:
-    Canvas2DLayerChromium(GraphicsContext3D*, const IntSize&);
+    Canvas2DLayerChromium(PassRefPtr<GraphicsContext3D>, const IntSize&);
 
     friend class Canvas2DLayerChromiumTest;
     void setTextureManager(TextureManager*);
 
-    GraphicsContext3D* m_context;
+    RefPtr<GraphicsContext3D> m_context;
+    bool m_contextLost;
     IntSize m_size;
     unsigned m_backTextureId;
     Platform3DObject m_fbo;

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.cpp (110482 => 110483)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.cpp	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.cpp	2012-03-12 21:52:14 UTC (rev 110483)
@@ -225,7 +225,7 @@
         return SkBitmap();
 
     layerRenderer->context()->flush();
-    return CCRenderSurfaceFilters::apply(m_filters, m_contentsTexture->textureId(), m_contentRect.size(), SharedGraphicsContext3D::get());
+    return CCRenderSurfaceFilters::apply(m_filters, m_contentsTexture->textureId(), m_contentRect.size(), SharedGraphicsContext3D::get().get());
 }
 
 String CCRenderSurface::name() const

Modified: trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp (110482 => 110483)


--- trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp	2012-03-12 21:52:14 UTC (rev 110483)
@@ -27,22 +27,43 @@
 #include "config.h"
 
 #include "SharedGraphicsContext3D.h"
+#include "Extensions3D.h"
 
 namespace WebCore {
 
-GraphicsContext3D* SharedGraphicsContext3D::get()
+class SharedGraphicsContext3DImpl {
+public:
+    SharedGraphicsContext3DImpl() : m_context(0) { }
+    PassRefPtr<GraphicsContext3D> get()
+    {
+        // If we lost the context, or can't make it current, create a new one.
+        if (m_context && (!m_context->makeContextCurrent() || (m_context->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR)))
+            m_context.clear();
+
+        if (!m_context) {
+            GraphicsContext3D::Attributes attributes;
+            attributes.depth = false;
+            attributes.stencil = true;
+            attributes.antialias = false;
+            attributes.canRecoverFromContextLoss = false;
+            attributes.shareResources = true;
+            attributes.preferDiscreteGPU = true;
+            m_context = GraphicsContext3D::create(attributes, 0);
+        }
+
+        if (m_context && !m_context->makeContextCurrent())
+            m_context.clear();
+
+        return m_context;
+    }
+private:
+    RefPtr<GraphicsContext3D> m_context;
+};
+
+PassRefPtr<GraphicsContext3D> SharedGraphicsContext3D::get()
 {
-    GraphicsContext3D::Attributes attributes;
-    attributes.depth = false;
-    attributes.stencil = true;
-    attributes.antialias = false;
-    attributes.canRecoverFromContextLoss = false; // Canvas contexts can not handle lost contexts.
-    attributes.shareResources = true;
-    attributes.preferDiscreteGPU = true;
-    static GraphicsContext3D* context = GraphicsContext3D::create(attributes, 0).leakRef();
-    if (context && !context->makeContextCurrent())
-        context = 0;
-    return context;
+    DEFINE_STATIC_LOCAL(SharedGraphicsContext3DImpl, impl, ());
+    return impl.get();
 }
 
 }

Modified: trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h (110482 => 110483)


--- trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h	2012-03-12 21:52:14 UTC (rev 110483)
@@ -34,7 +34,12 @@
 
 class SharedGraphicsContext3D {
 public:
-    static GraphicsContext3D* get();
+    // The caller may ref this pointer, and hang onto it as long as they like.
+    // However, the context should be checked periodically to determine if it
+    // has been lost. The easiest way to do that is to simply call this
+    // function again. Note that the return value may be 0 if the
+    // GPU is unavailable.
+    static PassRefPtr<GraphicsContext3D> get();
 };
 
 }

Modified: trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp (110482 => 110483)


--- trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp	2012-03-12 21:52:14 UTC (rev 110483)
@@ -85,7 +85,7 @@
 
 static SkCanvas* createAcceleratedCanvas(const IntSize& size, ImageBufferData* data, DeferralMode deferralMode)
 {
-    GraphicsContext3D* context3D = SharedGraphicsContext3D::get();
+    RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get();
     if (!context3D)
         return 0;
     GrContext* gr = context3D->grContext();
@@ -104,13 +104,13 @@
     SkCanvas* canvas;
     SkAutoTUnref<SkDevice> device(new SkGpuDevice(gr, texture.get()));
     if (deferralMode == Deferred) {
-        SkAutoTUnref<AcceleratedDeviceContext> deviceContext(new AcceleratedDeviceContext(context3D));
+        SkAutoTUnref<AcceleratedDeviceContext> deviceContext(new AcceleratedDeviceContext(context3D.get()));
         canvas = new SkDeferredCanvas(device.get(), deviceContext.get());
     } else
         canvas = new SkCanvas(device.get());
-    data->m_platformContext.setGraphicsContext3D(context3D);
+    data->m_platformContext.setAccelerated(true);
 #if USE(ACCELERATED_COMPOSITING)
-    data->m_platformLayer = Canvas2DLayerChromium::create(context3D, size);
+    data->m_platformLayer = Canvas2DLayerChromium::create(context3D.release(), size);
     data->m_platformLayer->setTextureId(texture.get()->getTextureHandle());
     data->m_platformLayer->setCanvas(canvas);
 #endif

Modified: trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp (110482 => 110483)


--- trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp	2012-03-12 21:52:14 UTC (rev 110483)
@@ -181,9 +181,9 @@
     : m_canvas(canvas)
     , m_trackOpaqueRegion(false)
     , m_printing(false)
+    , m_accelerated(false)
     , m_deferred(false)
     , m_drawingToImageBuffer(false)
-    , m_gpuContext(0)
 {
     m_stateStack.append(State());
     m_state = &m_stateStack.last();
@@ -602,11 +602,6 @@
     m_canvas->restore();
 }
 
-void PlatformContextSkia::setGraphicsContext3D(GraphicsContext3D* context)
-{
-    m_gpuContext = context;
-}
-
 void PlatformContextSkia::didDrawRect(const SkRect& rect, const SkPaint& paint, const SkBitmap* bitmap)
 {
     if (m_trackOpaqueRegion)

Modified: trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h (110482 => 110483)


--- trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h	2012-03-12 21:52:14 UTC (rev 110483)
@@ -47,7 +47,6 @@
 namespace WebCore {
 
 enum CompositeOperator;
-class GraphicsContext3D;
 class Texture;
 
 // This class holds the platform-specific state for GraphicsContext. We put
@@ -181,8 +180,8 @@
     void clearImageResamplingHint();
     bool hasImageResamplingHint() const;
 
-    bool isAccelerated() const { return m_gpuContext; }
-    void setGraphicsContext3D(GraphicsContext3D*);
+    bool isAccelerated() const { return m_accelerated; }
+    void setAccelerated(bool accelerated) { m_accelerated = accelerated; }
 
     // True if this context is deferring draw calls to be executed later.
     // We need to know this for context-to-context draws, in order to know if
@@ -237,9 +236,9 @@
     IntSize m_imageResamplingHintSrcSize;
     FloatSize m_imageResamplingHintDstSize;
     bool m_printing;
+    bool m_accelerated;
     bool m_deferred;
     bool m_drawingToImageBuffer;
-    GraphicsContext3D* m_gpuContext;
 };
 
 }

Modified: trunk/Source/WebKit/chromium/ChangeLog (110482 => 110483)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-03-12 21:52:14 UTC (rev 110483)
@@ -1,3 +1,16 @@
+2012-03-12  Stephen White  <[email protected]>
+
+        [chromium] Restore canvas2D acceleration after context loss.
+        https://bugs.webkit.org/show_bug.cgi?id=80629
+
+        Reviewed by James Robinson.
+
+        Covered by existing canvas tests, and manual testing (killing the GPU
+        process).
+
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::sharedGraphicsContext3D):
+
 2012-03-12  Nat Duca  <[email protected]>
 
         [Chromium] Force compositeAndReadback through regular scheduling flow

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (110482 => 110483)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-03-12 21:51:01 UTC (rev 110482)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-03-12 21:52:14 UTC (rev 110483)
@@ -3343,7 +3343,7 @@
     if (!m_page->settings()->acceleratedCompositingEnabled() || !allowsAcceleratedCompositing())
         return 0;
 
-    return GraphicsContext3DPrivate::extractWebGraphicsContext3D(SharedGraphicsContext3D::get());
+    return GraphicsContext3DPrivate::extractWebGraphicsContext3D(SharedGraphicsContext3D::get().get());
 }
 
 void WebViewImpl::setVisibilityState(WebPageVisibilityState visibilityState,
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to