Use isAcceleratedContext() on the GraphicsContext instead of flags in ImageBuffer
authormdelaney@apple.com <mdelaney@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Sep 2011 06:55:46 +0000 (06:55 +0000)
committermdelaney@apple.com <mdelaney@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Sep 2011 06:55:46 +0000 (06:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=68137

Reviewed by Simon Fraser.

No new tests. No change in behavior.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::isAccelerated): Have all just query the context directly.
(WebCore::CanvasRenderingContext2D::fillAndDisplayTransparencyElsewhere): just use isAccelerated directly
* platform/graphics/ImageBuffer.h:
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::ImageBuffer): Set isAcceleratedContext on the GraphicsContext instead of carrying the
    bit around on the ImageBuffer itself.
(WebCore::ImageBuffer::copyNativeImage): Update the check. Same for all below...
(WebCore::ImageBuffer::drawPattern):
(WebCore::ImageBuffer::getUnmultipliedImageData):
(WebCore::ImageBuffer::getPremultipliedImageData):
(WebCore::ImageBuffer::putUnmultipliedImageData):
(WebCore::ImageBuffer::putPremultipliedImageData):
* platform/graphics/skia/ImageBufferSkia.cpp: Set isAcceleratedContext on the GraphicsContext instead of carrying the
    bit around on the ImageBuffer itself.
(WebCore::ImageBuffer::ImageBuffer): Remove m_acceleratesRendering flag and getter.

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

Source/WebCore/ChangeLog
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/platform/graphics/ImageBuffer.h
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp

index 783332a..5e18402 100644 (file)
@@ -1,3 +1,29 @@
+2011-09-14  Matthew Delaney  <mdelaney@apple.com>
+
+        Use isAcceleratedContext() on the GraphicsContext instead of flags in ImageBuffer
+        https://bugs.webkit.org/show_bug.cgi?id=68137
+
+        Reviewed by Simon Fraser.
+
+        No new tests. No change in behavior.
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::isAccelerated): Have all just query the context directly.
+        (WebCore::CanvasRenderingContext2D::fillAndDisplayTransparencyElsewhere): just use isAccelerated directly
+        * platform/graphics/ImageBuffer.h:
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::ImageBuffer::ImageBuffer): Set isAcceleratedContext on the GraphicsContext instead of carrying the
+            bit around on the ImageBuffer itself.
+        (WebCore::ImageBuffer::copyNativeImage): Update the check. Same for all below...
+        (WebCore::ImageBuffer::drawPattern):
+        (WebCore::ImageBuffer::getUnmultipliedImageData):
+        (WebCore::ImageBuffer::getPremultipliedImageData):
+        (WebCore::ImageBuffer::putUnmultipliedImageData):
+        (WebCore::ImageBuffer::putPremultipliedImageData):
+        * platform/graphics/skia/ImageBufferSkia.cpp: Set isAcceleratedContext on the GraphicsContext instead of carrying the
+            bit around on the ImageBuffer itself.
+        (WebCore::ImageBuffer::ImageBuffer): Remove m_acceleratesRendering flag and getter.
+
 2011-09-14  Jeffrey Pfau  <jeffrey@endrift.com>
 
         libxml2 fragment parser loses prefix namespaces
index 39924d9..68f492c 100644 (file)
@@ -150,10 +150,7 @@ CanvasRenderingContext2D::~CanvasRenderingContext2D()
 
 bool CanvasRenderingContext2D::isAccelerated() const
 {
-#if USE(IOSURFACE_CANVAS_BACKING_STORE)
-    ImageBuffer* buffer = canvas()->buffer();
-    return buffer ? buffer->isAccelerated() : false;
-#elif ENABLE(ACCELERATED_2D_CANVAS)
+#if USE(IOSURFACE_CANVAS_BACKING_STORE) || ENABLE(ACCELERATED_2D_CANVAS)
     return canvas()->hasCreatedImageBuffer() && drawingContext() && drawingContext()->isAcceleratedContext();
 #else
     return false;
@@ -1511,7 +1508,7 @@ template<class T> void CanvasRenderingContext2D::fillAndDisplayTransparencyElsew
     IntRect bufferRect = enclosingIntRect(path.boundingRect());
     path.translate(FloatSize(-bufferRect.x(), -bufferRect.y()));
 
-    RenderingMode renderMode = canvas()->buffer()->isAccelerated() ? Accelerated : Unaccelerated;
+    RenderingMode renderMode = isAccelerated() ? Accelerated : Unaccelerated;
     OwnPtr<ImageBuffer> buffer = ImageBuffer::create(bufferRect.size(), ColorSpaceDeviceRGB, renderMode);
     buffer->context()->setCompositeOperation(CompositeSourceOver);
     state().m_fillStyle->applyFillColor(buffer->context());
index de2de93..66b6cc3 100644 (file)
@@ -90,7 +90,6 @@ namespace WebCore {
         
         GraphicsContext* context() const;
 
-        bool isAccelerated() const { return m_accelerateRendering; }
         PassRefPtr<Image> copyImage(BackingStoreCopy = CopyBackingStore) const;
 
         PassRefPtr<ByteArray> getUnmultipliedImageData(const IntRect&) const;
@@ -132,7 +131,6 @@ namespace WebCore {
         ImageBufferData m_data;
 
         IntSize m_size;
-        bool m_accelerateRendering;
         OwnPtr<GraphicsContext> m_context;
 
 #if !USE(CG)
index b8317e4..7b55d16 100644 (file)
@@ -106,9 +106,9 @@ static void releaseImageData(void*, const void* data, size_t)
 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace imageColorSpace, RenderingMode renderingMode, bool& success)
     : m_data(size)
     , m_size(size)
-    , m_accelerateRendering(renderingMode == Accelerated)
 {
     success = false;  // Make early return mean failure.
+    bool accelerateRendering = renderingMode == Accelerated;
     if (size.width() <= 0 || size.height() <= 0)
         return;
 
@@ -123,7 +123,7 @@ ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace imageColorSpace, Render
 
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
     if (width.unsafeGet() >= maxIOSurfaceDimension || height.unsafeGet() >= maxIOSurfaceDimension || (width * height).unsafeGet() < minIOSurfaceArea)
-        m_accelerateRendering = false;
+        accelerateRendering = false;
 #else
     ASSERT(renderingMode == Unaccelerated);
 #endif
@@ -141,16 +141,16 @@ ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace imageColorSpace, Render
     }
 
     RetainPtr<CGContextRef> cgContext;
-    if (m_accelerateRendering) {
+    if (accelerateRendering) {
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
         m_data.m_surface = createIOSurface(size);
         cgContext.adoptCF(wkIOSurfaceContextCreate(m_data.m_surface.get(), width.unsafeGet(), height.unsafeGet(), m_data.m_colorSpace));
 #endif
         if (!cgContext)
-            m_accelerateRendering = false; // If allocation fails, fall back to non-accelerated path.
+            accelerateRendering = false; // If allocation fails, fall back to non-accelerated path.
     }
 
-    if (!m_accelerateRendering) {
+    if (!accelerateRendering) {
         if (!tryFastCalloc(height.unsafeGet(), m_data.m_bytesPerRow.unsafeGet()).getValue(m_data.m_data))
             return;
         ASSERT(!(reinterpret_cast<size_t>(m_data.m_data) & 2));
@@ -167,6 +167,7 @@ ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace imageColorSpace, Render
     m_context= adoptPtr(new GraphicsContext(cgContext.get()));
     m_context->scale(FloatSize(1, -1));
     m_context->translate(0, -height.unsafeGet());
+    m_context->setIsAcceleratedContext(accelerateRendering);
     success = true;
 }
 
@@ -197,7 +198,7 @@ PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior) const
 NativeImagePtr ImageBuffer::copyNativeImage(BackingStoreCopy copyBehavior) const
 {
     CGImageRef image = 0;
-    if (!m_accelerateRendering) {
+    if (!m_context->isAcceleratedContext()) {
         switch (copyBehavior) {
         case DontCopyBackingStore:
             image = CGImageCreate(m_size.width(), m_size.height(), 8, 32, m_data.m_bytesPerRow.unsafeGet(), m_data.m_colorSpace, m_data.m_bitmapInfo, m_data.m_dataProvider.get(), 0, true, kCGRenderingIntentDefault);
@@ -234,7 +235,7 @@ void ImageBuffer::draw(GraphicsContext* destContext, ColorSpace styleColorSpace,
 
 void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
 {
-    if (!m_accelerateRendering) {
+    if (!m_context->isAcceleratedContext()) {
         if (context == m_context) {
             RefPtr<Image> copy = copyImage(CopyBackingStore); // Drawing into our own buffer, need to deep copy.
             copy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
@@ -261,30 +262,30 @@ void ImageBuffer::clip(GraphicsContext* contextToClip, const FloatRect& rect) co
 
 PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const
 {
-    if (m_accelerateRendering)
+    if (m_context->isAcceleratedContext())
         CGContextFlush(context()->platformContext());
-    return m_data.getData(rect, m_size, m_accelerateRendering, true);
+    return m_data.getData(rect, m_size, m_context->isAcceleratedContext(), true);
 }
 
 PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const
 {
-    if (m_accelerateRendering)
+    if (m_context->isAcceleratedContext())
         CGContextFlush(context()->platformContext());
-    return m_data.getData(rect, m_size, m_accelerateRendering, false);
+    return m_data.getData(rect, m_size, m_context->isAcceleratedContext(), false);
 }
 
 void ImageBuffer::putUnmultipliedImageData(ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint)
 {
-    if (m_accelerateRendering)
+    if (m_context->isAcceleratedContext())
         CGContextFlush(context()->platformContext());
-    m_data.putData(source, sourceSize, sourceRect, destPoint, m_size, m_accelerateRendering, true);
+    m_data.putData(source, sourceSize, sourceRect, destPoint, m_size, m_context->isAcceleratedContext(), true);
 }
 
 void ImageBuffer::putPremultipliedImageData(ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint)
 {
-    if (m_accelerateRendering)
+    if (m_context->isAcceleratedContext())
         CGContextFlush(context()->platformContext());
-    m_data.putData(source, sourceSize, sourceRect, destPoint, m_size, m_accelerateRendering, false);
+    m_data.putData(source, sourceSize, sourceRect, destPoint, m_size, m_context->isAcceleratedContext(), false);
 }
 
 static inline CFStringRef jpegUTI()
index 8b539c0..b5d9d94 100644 (file)
@@ -67,7 +67,6 @@ ImageBufferData::ImageBufferData(const IntSize& size)
 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, RenderingMode renderingMode, bool& success)
     : m_data(size)
     , m_size(size)
-    , m_accelerateRendering(false)
 {
     OwnPtr<SkCanvas> canvas = adoptPtr(skia::TryCreateBitmapCanvas(size.width(), size.height(), false));
     if (!canvas) {
@@ -101,7 +100,7 @@ ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, RenderingMode renderin
                 if (texture.get()) {
                     m_data.m_canvas->setDevice(new SkGpuDevice(gr, texture.get()))->unref();
                     m_context->platformContext()->setGraphicsContext3D(context3D);
-                    m_accelerateRendering = true;
+                    m_context->setIsAcceleratedContext(true);
 #if USE(ACCELERATED_COMPOSITING)
                     m_data.m_platformLayer = Canvas2DLayerChromium::create(context3D);
                     m_data.m_platformLayer->setTextureId(texture.get()->getTextureHandle());