Title: [228052] trunk/Source/WebCore
Revision
228052
Author
zandober...@gmail.com
Date
2018-02-04 00:18:23 -0800 (Sun, 04 Feb 2018)

Log Message

Simplify GraphicsContext3D::paintToCanvas()
https://bugs.webkit.org/show_bug.cgi?id=182459

Reviewed by Michael Catanzaro.

Cairo-specific paintToCanvas() method is dropped in favor of the more
common one that operates on a GraphicsContext object. The platform
context object is then retrieved inside the Cairo-speficic
paintToCanvas() implementation, and not at the call site in
GraphicsContext3D::paintRenderingResultsToCanvas().

GraphicsContext3D::paintToCanvas() is also modified so that the image
and canvas sizes are passed through IntSize objects, and not through
a width-and-height pair of integer values.

No new tests -- no change in behavior.

* platform/graphics/GraphicsContext3D.h:
* platform/graphics/cairo/GraphicsContext3DCairo.cpp:
(WebCore::GraphicsContext3D::paintToCanvas):
* platform/graphics/cg/GraphicsContext3DCG.cpp:
(WebCore::GraphicsContext3D::paintToCanvas):
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228051 => 228052)


--- trunk/Source/WebCore/ChangeLog	2018-02-04 08:17:17 UTC (rev 228051)
+++ trunk/Source/WebCore/ChangeLog	2018-02-04 08:18:23 UTC (rev 228052)
@@ -1,3 +1,30 @@
+2018-02-04  Zan Dobersek  <zdober...@igalia.com>
+
+        Simplify GraphicsContext3D::paintToCanvas()
+        https://bugs.webkit.org/show_bug.cgi?id=182459
+
+        Reviewed by Michael Catanzaro.
+
+        Cairo-specific paintToCanvas() method is dropped in favor of the more
+        common one that operates on a GraphicsContext object. The platform
+        context object is then retrieved inside the Cairo-speficic
+        paintToCanvas() implementation, and not at the call site in
+        GraphicsContext3D::paintRenderingResultsToCanvas().
+
+        GraphicsContext3D::paintToCanvas() is also modified so that the image
+        and canvas sizes are passed through IntSize objects, and not through
+        a width-and-height pair of integer values.
+
+        No new tests -- no change in behavior.
+
+        * platform/graphics/GraphicsContext3D.h:
+        * platform/graphics/cairo/GraphicsContext3DCairo.cpp:
+        (WebCore::GraphicsContext3D::paintToCanvas):
+        * platform/graphics/cg/GraphicsContext3DCG.cpp:
+        (WebCore::GraphicsContext3D::paintToCanvas):
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+        (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
+
 2018-02-03  Alexey Proskuryakov  <a...@apple.com>
 
         Tweak availability macros for CAN_DISALLOW_USER_INSTALLED_FONTS

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (228051 => 228052)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2018-02-04 08:17:17 UTC (rev 228051)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2018-02-04 08:18:23 UTC (rev 228052)
@@ -98,9 +98,6 @@
 class IntRect;
 class IntSize;
 class WebGLRenderingContextBase;
-#if USE(CAIRO)
-class PlatformContextCairo;
-#endif
 #if USE(TEXTURE_MAPPER)
 class TextureMapperGC3DPlatformLayer;
 #endif
@@ -1130,12 +1127,7 @@
     GC3Dboolean isVertexArray(Platform3DObject);
     void bindVertexArray(Platform3DObject);
 
-#if PLATFORM(GTK) || USE(CAIRO)
-    void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
-                       int canvasWidth, int canvasHeight, PlatformContextCairo* context);
-#elif USE(CG)
-    void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, GraphicsContext&);
-#endif
+    void paintToCanvas(const unsigned char* imagePixels, const IntSize& imageSize, const IntSize& canvasSize, GraphicsContext&);
 
     void markContextChanged();
     void markLayerComposited();

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp (228051 => 228052)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp	2018-02-04 08:17:17 UTC (rev 228051)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp	2018-02-04 08:18:23 UTC (rev 228052)
@@ -343,31 +343,35 @@
     return true;
 }
 
-void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, PlatformContextCairo* context)
+void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, const IntSize& imageSize, const IntSize& canvasSize, GraphicsContext& context)
 {
-    if (!imagePixels || imageWidth <= 0 || imageHeight <= 0 || canvasWidth <= 0 || canvasHeight <= 0 || !context)
+    if (!imagePixels || imageSize.isEmpty() || canvasSize.isEmpty())
         return;
 
-    cairo_t *cr = context->cr();
-    context->save();
+    PlatformContextCairo* platformContext = context.platformContext();
+    if (!platformContext)
+        return;
 
-    cairo_rectangle(cr, 0, 0, canvasWidth, canvasHeight);
+    cairo_t* cr = platformContext->cr();
+    platformContext->save();
+
+    cairo_rectangle(cr, 0, 0, canvasSize.width(), canvasSize.height());
     cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
     cairo_paint(cr);
 
     RefPtr<cairo_surface_t> imageSurface = adoptRef(cairo_image_surface_create_for_data(
-        const_cast<unsigned char*>(imagePixels), CAIRO_FORMAT_ARGB32, imageWidth, imageHeight, imageWidth * 4));
+        const_cast<unsigned char*>(imagePixels), CAIRO_FORMAT_ARGB32, imageSize.width(), imageSize.height(), imageSize.width() * 4));
 
     // OpenGL keeps the pixels stored bottom up, so we need to flip the image here.
-    cairo_translate(cr, 0, imageHeight);
+    cairo_translate(cr, 0, imageSize.height());
     cairo_scale(cr, 1, -1);
 
     cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
     cairo_set_source_surface(cr, imageSurface.get(), 0, 0);
-    cairo_rectangle(cr, 0, 0, canvasWidth, -canvasHeight);
+    cairo_rectangle(cr, 0, 0, canvasSize.width(), -canvasSize.height());
 
     cairo_fill(cr);
-    context->restore();
+    platformContext->restore();
 }
 
 void GraphicsContext3D::setContextLostCallback(std::unique_ptr<ContextLostCallback>)

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp (228051 => 228052)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp	2018-02-04 08:17:17 UTC (rev 228051)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp	2018-02-04 08:18:23 UTC (rev 228052)
@@ -500,38 +500,37 @@
     fastFree(const_cast<void*>(data));
 }
 
-void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, GraphicsContext& context)
+void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, const IntSize& imageSize, const IntSize& canvasSize, GraphicsContext& context)
 {
-    if (!imagePixels || imageWidth <= 0 || imageHeight <= 0 || canvasWidth <= 0 || canvasHeight <= 0)
+    if (!imagePixels || imageSize.isEmpty() || canvasSize.isEmpty())
         return;
-    int rowBytes = imageWidth * 4;
+    int rowBytes = imageSize.width() * 4;
     RetainPtr<CGDataProviderRef> dataProvider;
 
     if (context.isAcceleratedContext()) {
         unsigned char* copiedPixels;
 
-        if (!tryFastCalloc(imageHeight, rowBytes).getValue(copiedPixels))
+        if (!tryFastCalloc(imageSize.height(), rowBytes).getValue(copiedPixels))
             return;
 
-        memcpy(copiedPixels, imagePixels, rowBytes * imageHeight);
-        dataProvider = adoptCF(CGDataProviderCreateWithData(0, copiedPixels, rowBytes * imageHeight, releaseImageData));
+        memcpy(copiedPixels, imagePixels, rowBytes * imageSize.height());
+        dataProvider = adoptCF(CGDataProviderCreateWithData(0, copiedPixels, rowBytes * imageSize.height(), releaseImageData));
     } else
-        dataProvider = adoptCF(CGDataProviderCreateWithData(0, imagePixels, rowBytes * imageHeight, 0));
+        dataProvider = adoptCF(CGDataProviderCreateWithData(0, imagePixels, rowBytes * imageSize.height(), 0));
 
-    RetainPtr<CGImageRef> cgImage = adoptCF(CGImageCreate(imageWidth, imageHeight, 8, 32, rowBytes, sRGBColorSpaceRef(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
+    RetainPtr<CGImageRef> cgImage = adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, rowBytes, sRGBColorSpaceRef(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
         dataProvider.get(), 0, false, kCGRenderingIntentDefault));
 
     // CSS styling may cause the canvas's content to be resized on
     // the page. Go back to the Canvas to figure out the correct
     // width and height to draw.
-    FloatRect canvasRect(0, 0, canvasWidth, canvasHeight);
-    FloatSize imageSize(imageWidth, imageHeight);
+    FloatRect canvasRect(FloatPoint(), canvasSize);
     // We want to completely overwrite the previous frame's
     // rendering results.
 
     GraphicsContextStateSaver stateSaver(context);
     context.scale(FloatSize(1, -1));
-    context.translate(0, -imageHeight);
+    context.translate(0, -imageSize.height());
     context.setImageInterpolationQuality(InterpolationNone);
     context.drawNativeImage(cgImage, imageSize, canvasRect, FloatRect(FloatPoint(), imageSize), CompositeCopy);
 }

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (228051 => 228052)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2018-02-04 08:17:17 UTC (rev 228051)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2018-02-04 08:18:23 UTC (rev 228052)
@@ -177,12 +177,7 @@
         }
     }
 
-#if USE(CG)
-    paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight,
-                  imageBuffer->internalSize().width(), imageBuffer->internalSize().height(), imageBuffer->context());
-#else
-    paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight, imageBuffer->internalSize().width(), imageBuffer->internalSize().height(), imageBuffer->context().platformContext());
-#endif
+    paintToCanvas(pixels.get(), IntSize(m_currentWidth, m_currentHeight), imageBuffer->internalSize(), imageBuffer->context());
 
 #if PLATFORM(IOS)
     presentRenderbuffer();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to