Ownership of canvas's GraphicsContext3D should be moved to PlatformContextSkia
authorsenorblanco@chromium.org <senorblanco@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Aug 2011 03:26:43 +0000 (03:26 +0000)
committersenorblanco@chromium.org <senorblanco@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Aug 2011 03:26:43 +0000 (03:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66154

Reviewed by Kenneth Russell.

Covered by existing tests in fast/canvas and canvas/philip.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::isAccelerated):
Plumb this call through GraphicsContext::isAcceleratedContext().
(WebCore::CanvasRenderingContext2D::paintsIntoCanvasBuffer):
For the ACCELERATED_2D_CANVAS path, plumb this call through
(the new) GraphicsContext::paintsIntoCanvasBuffer().
(WebCore::CanvasRenderingContext2D::clearAcceleration):
(WebCore::CanvasRenderingContext2D::resetAcceleration):
Remove the use of the m_context3D member; use a temporary instead.
* html/canvas/CanvasRenderingContext2D.h:
Remove the m_context3D member.
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::isAcceleratedContext):
(WebCore::GraphicsContext::paintsIntoImageBuffer):
Implement stub versions of these functions for other platforms.
* platform/graphics/GraphicsContext.h:
Expose isAcceleratedContext() to all platforms.  Add
paintsIntoImageBuffer() member function.
* platform/graphics/gpu/SharedGraphicsContext3D.cpp:
(WebCore::SharedGraphicsContext3D::create):
* platform/graphics/gpu/SharedGraphicsContext3D.h:
* platform/graphics/skia/GraphicsContextSkia.cpp:
(WebCore::GraphicsContext::setGraphicsContext3D):
(WebCore::GraphicsContext::isAcceleratedContext):
(WebCore::GraphicsContext::paintsIntoImageBuffer):
Basically gut this class leaving only a static creation function.
* platform/graphics/skia/ImageSkia.cpp:
(WebCore::paintSkBitmap):
(WebCore::Image::drawPattern):
Use isAccelerated() in place of useSkiaGpu().
* platform/graphics/skia/PlatformContextSkia.cpp:
(WebCore::PlatformContextSkia::isNativeFontRenderingAllowed):
(WebCore::PlatformContextSkia::paintsIntoImageBuffer):
* platform/graphics/skia/PlatformContextSkia.h:
(WebCore::PlatformContextSkia::isAccelerated):
Rename useSkiaGpu() to isAccelerated().  Plumb through
paintsIntoImageBuffer() to GraphicsContext3D.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@93013 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2D.h
Source/WebCore/platform/graphics/GraphicsContext.cpp
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp
Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h
Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
Source/WebCore/platform/graphics/skia/ImageSkia.cpp
Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
Source/WebCore/platform/graphics/skia/PlatformContextSkia.h

index 6a09138..e79ddd6 100644 (file)
@@ -1,3 +1,50 @@
+2011-08-12  Stephen White  <senorblanco@chromium.org>
+
+        Ownership of canvas's GraphicsContext3D should be moved to PlatformContextSkia
+        https://bugs.webkit.org/show_bug.cgi?id=66154
+
+        Reviewed by Kenneth Russell.
+
+        Covered by existing tests in fast/canvas and canvas/philip.
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::isAccelerated):
+        Plumb this call through GraphicsContext::isAcceleratedContext().
+        (WebCore::CanvasRenderingContext2D::paintsIntoCanvasBuffer):
+        For the ACCELERATED_2D_CANVAS path, plumb this call through
+        (the new) GraphicsContext::paintsIntoCanvasBuffer().
+        (WebCore::CanvasRenderingContext2D::clearAcceleration):
+        (WebCore::CanvasRenderingContext2D::resetAcceleration):
+        Remove the use of the m_context3D member; use a temporary instead.
+        * html/canvas/CanvasRenderingContext2D.h:
+        Remove the m_context3D member.
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::isAcceleratedContext):
+        (WebCore::GraphicsContext::paintsIntoImageBuffer):
+        Implement stub versions of these functions for other platforms.
+        * platform/graphics/GraphicsContext.h:
+        Expose isAcceleratedContext() to all platforms.  Add
+        paintsIntoImageBuffer() member function.
+        * platform/graphics/gpu/SharedGraphicsContext3D.cpp:
+        (WebCore::SharedGraphicsContext3D::create):
+        * platform/graphics/gpu/SharedGraphicsContext3D.h:
+        * platform/graphics/skia/GraphicsContextSkia.cpp:
+        (WebCore::GraphicsContext::setGraphicsContext3D):
+        (WebCore::GraphicsContext::isAcceleratedContext):
+        (WebCore::GraphicsContext::paintsIntoImageBuffer):
+        Basically gut this class leaving only a static creation function.
+        * platform/graphics/skia/ImageSkia.cpp:
+        (WebCore::paintSkBitmap):
+        (WebCore::Image::drawPattern):
+        Use isAccelerated() in place of useSkiaGpu().
+        * platform/graphics/skia/PlatformContextSkia.cpp:
+        (WebCore::PlatformContextSkia::isNativeFontRenderingAllowed):
+        (WebCore::PlatformContextSkia::paintsIntoImageBuffer):
+        * platform/graphics/skia/PlatformContextSkia.h:
+        (WebCore::PlatformContextSkia::isAccelerated):
+        Rename useSkiaGpu() to isAccelerated().  Plumb through 
+        paintsIntoImageBuffer() to GraphicsContext3D.
+
 2011-08-12  Sam Weinig  <sam@webkit.org>
 
         Use __builtin_trap() for CRASH when building with clang
index 6edb838..3b17c96 100644 (file)
@@ -183,7 +183,7 @@ bool CanvasRenderingContext2D::isAccelerated() const
     ImageBuffer* buffer = canvas()->buffer();
     return buffer ? buffer->isAccelerated() : false;
 #elif ENABLE(ACCELERATED_2D_CANVAS)
-    return m_context3D;
+    return drawingContext() && drawingContext()->isAcceleratedContext();
 #else
     return false;
 #endif
@@ -192,8 +192,8 @@ bool CanvasRenderingContext2D::isAccelerated() const
 bool CanvasRenderingContext2D::paintsIntoCanvasBuffer() const
 {
 #if ENABLE(ACCELERATED_2D_CANVAS)
-    if (m_context3D)
-        return m_context3D->context()->paintsIntoCanvasBuffer();
+    if (drawingContext())
+        return drawingContext()->paintsIntoImageBuffer();
 #endif
     return true;
 }
@@ -2029,7 +2029,6 @@ void CanvasRenderingContext2D::clearAcceleration()
         ctx->setGraphicsContext3D(0, 0, IntSize());
 
     m_drawingBuffer.clear();
-    m_context3D.clear();
 }
 
 void CanvasRenderingContext2D::resetAcceleration()
@@ -2046,13 +2045,11 @@ void CanvasRenderingContext2D::resetAcceleration()
         return;
     }
 
-    if (!m_context3D) {
-        Page* page = canvas()->document()->page();
-        m_context3D = SharedGraphicsContext3D::create(page->chrome());
-        if (!m_context3D) {
-            clearAcceleration();
-            return;
-        }
+    Page* page = canvas()->document()->page();
+    GraphicsContext3D* context3D = SharedGraphicsContext3D::create(page->chrome());
+    if (!context3D) {
+        clearAcceleration();
+        return;
     }
 
     if (m_drawingBuffer) {
@@ -2061,14 +2058,14 @@ void CanvasRenderingContext2D::resetAcceleration()
             return;
         }
     } else {
-        m_drawingBuffer = m_context3D->context()->createDrawingBuffer(canvas()->size());
+        m_drawingBuffer = context3D->createDrawingBuffer(canvas()->size());
         if (!m_drawingBuffer) {
             clearAcceleration();
             return;
         }
     }
 
-    ctx->setGraphicsContext3D(m_context3D->context(), m_drawingBuffer.get(), canvas()->size());
+    ctx->setGraphicsContext3D(context3D, m_drawingBuffer.get(), canvas()->size());
 }
 #endif
 
index 5b8623c..bf77681 100644 (file)
@@ -307,7 +307,6 @@ private:
 
 #if ENABLE(ACCELERATED_2D_CANVAS)
     RefPtr<DrawingBuffer> m_drawingBuffer;
-    RefPtr<SharedGraphicsContext3D> m_context3D;
 #endif
 };
 
index 46a56ca..616c965 100644 (file)
@@ -690,6 +690,19 @@ void GraphicsContext::setGraphicsContext3D(GraphicsContext3D*, DrawingBuffer*, c
 }
 #endif
 
+#if !USE(SKIA) && !USE(CG)
+bool GraphicsContext::isAcceleratedContext() const
+{
+    return false;
+}
+#endif
+
+#if !USE(SKIA)
+bool GraphicsContext::paintsIntoImageBuffer() const
+{
+    return true;
+}
+#endif
 
 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle penStyle)
 {
index 9981334..fe86658 100644 (file)
@@ -273,8 +273,9 @@ namespace WebCore {
         bool isCALayerContext() const;
 
         void setIsAcceleratedContext(bool);
-        bool isAcceleratedContext() const;
 #endif
+        bool isAcceleratedContext() const;
+        bool paintsIntoImageBuffer() const;
 
         void save();
         void restore();
index 27f2b74..392f9db 100644 (file)
 
 namespace WebCore {
 
-SharedGraphicsContext3D* SharedGraphicsContext3D::s_instance = 0;
-
-PassRefPtr<SharedGraphicsContext3D> SharedGraphicsContext3D::create(HostWindow* window)
+GraphicsContext3D* SharedGraphicsContext3D::create(HostWindow* window)
 {
-    if (s_instance) {
-        s_instance->ref(); // Manually increment refcount for this caller since adoptRef() does not increase the refcount.
-        return adoptRef(s_instance);
-    }
     GraphicsContext3D::Attributes attributes;
     attributes.depth = false;
     attributes.stencil = true;
     attributes.antialias = false;
     attributes.canRecoverFromContextLoss = false; // Canvas contexts can not handle lost contexts.
-    RefPtr<GraphicsContext3D> context = GraphicsContext3D::create(attributes, window);
-    if (!context)
-        return PassRefPtr<SharedGraphicsContext3D>();
-    RefPtr<SharedGraphicsContext3D> sharedContext = adoptRef(new SharedGraphicsContext3D(context.release()));
-    s_instance = sharedContext.get();
-    return sharedContext;
-}
-
-SharedGraphicsContext3D::SharedGraphicsContext3D(PassRefPtr<GraphicsContext3D> context)
-    : m_context(context)
-{
-}
-
-SharedGraphicsContext3D::~SharedGraphicsContext3D()
-{
-    s_instance = 0;
+    static RefPtr<GraphicsContext3D> context = GraphicsContext3D::create(attributes, window);
+    return context.get();
 }
 
 }
index f3ece7a..6b1dbe8 100644 (file)
 
 namespace WebCore {
 
-class SharedGraphicsContext3D : public RefCounted<SharedGraphicsContext3D> {
+class SharedGraphicsContext3D {
 public:
-    static PassRefPtr<SharedGraphicsContext3D> create(HostWindow*);
-    ~SharedGraphicsContext3D();
-
-    GraphicsContext3D* context() const { return m_context.get(); }
-
-private:
-    explicit SharedGraphicsContext3D(PassRefPtr<GraphicsContext3D>);
-
-    RefPtr<GraphicsContext3D> m_context;
-    static SharedGraphicsContext3D* s_instance;
+    static GraphicsContext3D* create(HostWindow*);
 };
 
 }
index d0ccc00..ff1ea65 100644 (file)
@@ -1203,9 +1203,19 @@ void GraphicsContext::translate(float w, float h)
                                            WebCoreFloatToSkScalar(h));
 }
 
-void GraphicsContext::setGraphicsContext3D(GraphicsContext3D* context, DrawingBuffer* framebuffer, const IntSize& size)
+void GraphicsContext::setGraphicsContext3D(GraphicsContext3D* context, DrawingBuffer* drawingBuffer, const IntSize& size)
 {
-    platformContext()->setGraphicsContext3D(context, framebuffer, size);
+    platformContext()->setGraphicsContext3D(context, drawingBuffer, size);
+}
+
+bool GraphicsContext::isAcceleratedContext() const
+{
+    return platformContext()->isAccelerated();
+}
+
+bool GraphicsContext::paintsIntoImageBuffer() const
+{
+    return platformContext()->paintsIntoImageBuffer();
 }
 
 #if PLATFORM(CHROMIUM) && OS(DARWIN)
index c74a98b..af1b637 100644 (file)
@@ -265,7 +265,7 @@ static void paintSkBitmap(PlatformContextSkia* platformContext, const NativeImag
     SkCanvas* canvas = platformContext->canvas();
 
     ResamplingMode resampling;
-    if (platformContext->useSkiaGPU())
+    if (platformContext->isAccelerated())
         resampling = RESAMPLE_LINEAR;
     else
         resampling = platformContext->printing() ? RESAMPLE_NONE :
@@ -365,7 +365,7 @@ void Image::drawPattern(GraphicsContext* context,
 
     // Compute the resampling mode.
     ResamplingMode resampling;
-    if (context->platformContext()->useSkiaGPU())
+    if (context->platformContext()->isAccelerated())
         resampling = RESAMPLE_LINEAR;
     else {
         if (context->platformContext()->printing())
index 53990ec..78243e4 100644 (file)
@@ -575,7 +575,7 @@ bool PlatformContextSkia::isNativeFontRenderingAllowed()
 #if ENABLE(SKIA_TEXT)
     return false;
 #else
-    if (useSkiaGPU())
+    if (isAccelerated())
         return false;
     return skia::SupportsPlatformPaint(m_canvas);
 #endif
@@ -682,4 +682,9 @@ void PlatformContextSkia::makeGrContextCurrent()
         m_gpuContext->makeContextCurrent();
 }
 
+bool PlatformContextSkia::paintsIntoImageBuffer() const
+{
+    return m_gpuContext ? m_gpuContext->paintsIntoCanvasBuffer() : true;
+}
+
 } // namespace WebCore
index 6982561..668ac24 100644 (file)
@@ -177,8 +177,9 @@ public:
     void clearImageResamplingHint();
     bool hasImageResamplingHint() const;
 
-    bool useSkiaGPU() const { return m_gpuContext; }
+    bool isAccelerated() const { return m_gpuContext; }
     void setGraphicsContext3D(GraphicsContext3D*, DrawingBuffer*, const IntSize&);
+    bool paintsIntoImageBuffer() const;
     void makeGrContextCurrent();
 
 private: