Changeset 228052 in webkit


Ignore:
Timestamp:
Feb 4, 2018 12:18:23 AM (6 years ago)
Author:
zandobersek@gmail.com
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):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r228049 r228052  
     12018-02-04  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        Simplify GraphicsContext3D::paintToCanvas()
     4        https://bugs.webkit.org/show_bug.cgi?id=182459
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Cairo-specific paintToCanvas() method is dropped in favor of the more
     9        common one that operates on a GraphicsContext object. The platform
     10        context object is then retrieved inside the Cairo-speficic
     11        paintToCanvas() implementation, and not at the call site in
     12        GraphicsContext3D::paintRenderingResultsToCanvas().
     13
     14        GraphicsContext3D::paintToCanvas() is also modified so that the image
     15        and canvas sizes are passed through IntSize objects, and not through
     16        a width-and-height pair of integer values.
     17
     18        No new tests -- no change in behavior.
     19
     20        * platform/graphics/GraphicsContext3D.h:
     21        * platform/graphics/cairo/GraphicsContext3DCairo.cpp:
     22        (WebCore::GraphicsContext3D::paintToCanvas):
     23        * platform/graphics/cg/GraphicsContext3DCG.cpp:
     24        (WebCore::GraphicsContext3D::paintToCanvas):
     25        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
     26        (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
     27
    1282018-02-03  Alexey Proskuryakov  <ap@apple.com>
    229
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h

    r226581 r228052  
    9999class IntSize;
    100100class WebGLRenderingContextBase;
    101 #if USE(CAIRO)
    102 class PlatformContextCairo;
    103 #endif
    104101#if USE(TEXTURE_MAPPER)
    105102class TextureMapperGC3DPlatformLayer;
     
    11311128    void bindVertexArray(Platform3DObject);
    11321129
    1133 #if PLATFORM(GTK) || USE(CAIRO)
    1134     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
    1135                        int canvasWidth, int canvasHeight, PlatformContextCairo* context);
    1136 #elif USE(CG)
    1137     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, GraphicsContext&);
    1138 #endif
     1130    void paintToCanvas(const unsigned char* imagePixels, const IntSize& imageSize, const IntSize& canvasSize, GraphicsContext&);
    11391131
    11401132    void markContextChanged();
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp

    r225638 r228052  
    344344}
    345345
    346 void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, PlatformContextCairo* context)
    347 {
    348     if (!imagePixels || imageWidth <= 0 || imageHeight <= 0 || canvasWidth <= 0 || canvasHeight <= 0 || !context)
     346void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, const IntSize& imageSize, const IntSize& canvasSize, GraphicsContext& context)
     347{
     348    if (!imagePixels || imageSize.isEmpty() || canvasSize.isEmpty())
    349349        return;
    350350
    351     cairo_t *cr = context->cr();
    352     context->save();
    353 
    354     cairo_rectangle(cr, 0, 0, canvasWidth, canvasHeight);
     351    PlatformContextCairo* platformContext = context.platformContext();
     352    if (!platformContext)
     353        return;
     354
     355    cairo_t* cr = platformContext->cr();
     356    platformContext->save();
     357
     358    cairo_rectangle(cr, 0, 0, canvasSize.width(), canvasSize.height());
    355359    cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
    356360    cairo_paint(cr);
    357361
    358362    RefPtr<cairo_surface_t> imageSurface = adoptRef(cairo_image_surface_create_for_data(
    359         const_cast<unsigned char*>(imagePixels), CAIRO_FORMAT_ARGB32, imageWidth, imageHeight, imageWidth * 4));
     363        const_cast<unsigned char*>(imagePixels), CAIRO_FORMAT_ARGB32, imageSize.width(), imageSize.height(), imageSize.width() * 4));
    360364
    361365    // OpenGL keeps the pixels stored bottom up, so we need to flip the image here.
    362     cairo_translate(cr, 0, imageHeight);
     366    cairo_translate(cr, 0, imageSize.height());
    363367    cairo_scale(cr, 1, -1);
    364368
    365369    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
    366370    cairo_set_source_surface(cr, imageSurface.get(), 0, 0);
    367     cairo_rectangle(cr, 0, 0, canvasWidth, -canvasHeight);
     371    cairo_rectangle(cr, 0, 0, canvasSize.width(), -canvasSize.height());
    368372
    369373    cairo_fill(cr);
    370     context->restore();
     374    platformContext->restore();
    371375}
    372376
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp

    r225428 r228052  
    501501}
    502502
    503 void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, GraphicsContext& context)
    504 {
    505     if (!imagePixels || imageWidth <= 0 || imageHeight <= 0 || canvasWidth <= 0 || canvasHeight <= 0)
     503void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, const IntSize& imageSize, const IntSize& canvasSize, GraphicsContext& context)
     504{
     505    if (!imagePixels || imageSize.isEmpty() || canvasSize.isEmpty())
    506506        return;
    507     int rowBytes = imageWidth * 4;
     507    int rowBytes = imageSize.width() * 4;
    508508    RetainPtr<CGDataProviderRef> dataProvider;
    509509
     
    511511        unsigned char* copiedPixels;
    512512
    513         if (!tryFastCalloc(imageHeight, rowBytes).getValue(copiedPixels))
     513        if (!tryFastCalloc(imageSize.height(), rowBytes).getValue(copiedPixels))
    514514            return;
    515515
    516         memcpy(copiedPixels, imagePixels, rowBytes * imageHeight);
    517         dataProvider = adoptCF(CGDataProviderCreateWithData(0, copiedPixels, rowBytes * imageHeight, releaseImageData));
     516        memcpy(copiedPixels, imagePixels, rowBytes * imageSize.height());
     517        dataProvider = adoptCF(CGDataProviderCreateWithData(0, copiedPixels, rowBytes * imageSize.height(), releaseImageData));
    518518    } else
    519         dataProvider = adoptCF(CGDataProviderCreateWithData(0, imagePixels, rowBytes * imageHeight, 0));
    520 
    521     RetainPtr<CGImageRef> cgImage = adoptCF(CGImageCreate(imageWidth, imageHeight, 8, 32, rowBytes, sRGBColorSpaceRef(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
     519        dataProvider = adoptCF(CGDataProviderCreateWithData(0, imagePixels, rowBytes * imageSize.height(), 0));
     520
     521    RetainPtr<CGImageRef> cgImage = adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, rowBytes, sRGBColorSpaceRef(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
    522522        dataProvider.get(), 0, false, kCGRenderingIntentDefault));
    523523
     
    525525    // the page. Go back to the Canvas to figure out the correct
    526526    // width and height to draw.
    527     FloatRect canvasRect(0, 0, canvasWidth, canvasHeight);
    528     FloatSize imageSize(imageWidth, imageHeight);
     527    FloatRect canvasRect(FloatPoint(), canvasSize);
    529528    // We want to completely overwrite the previous frame's
    530529    // rendering results.
     
    532531    GraphicsContextStateSaver stateSaver(context);
    533532    context.scale(FloatSize(1, -1));
    534     context.translate(0, -imageHeight);
     533    context.translate(0, -imageSize.height());
    535534    context.setImageInterpolationQuality(InterpolationNone);
    536535    context.drawNativeImage(cgImage, imageSize, canvasRect, FloatRect(FloatPoint(), imageSize), CompositeCopy);
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp

    r226581 r228052  
    178178    }
    179179
    180 #if USE(CG)
    181     paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight,
    182                   imageBuffer->internalSize().width(), imageBuffer->internalSize().height(), imageBuffer->context());
    183 #else
    184     paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight, imageBuffer->internalSize().width(), imageBuffer->internalSize().height(), imageBuffer->context().platformContext());
    185 #endif
     180    paintToCanvas(pixels.get(), IntSize(m_currentWidth, m_currentHeight), imageBuffer->internalSize(), imageBuffer->context());
    186181
    187182#if PLATFORM(IOS)
Note: See TracChangeset for help on using the changeset viewer.