⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 268578 in webkit


Ignore:
Timestamp:
Oct 16, 2020, 3:55:59 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Refactor WebGL implementation to use only GraphicsContextGL part 1
https://bugs.webkit.org/show_bug.cgi?id=217213
<rdar://problem/69876105>

Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2020-10-16
Reviewed by Dean Jackson.

Part 1 of work towards WebGL implementation which uses
GraphicsContextGL abstract base class instead of
GraphicsContextGLOpenGL concrete class.

Move pixel data related static helper funcions from
GraphicsContextGLOpenGL to GraphicsContextGL. These are
normal pixel format calculation functions that do not have
concrete class implementation details. Move pixel pack related
structures to GraphicsContextGL.

Rename GraphicsContextGLOpenGL::ImageExtractor to
GraphicsContextGLImageExtractor. The GraphicsContextGL class
interface is already quite lengthy and the image extractor
is not very tied to the context class.

Introduce a virtual member function in GraphicsContextGL for
each call that is likely needed for the WebGL implementation.

No new tests, a refactor.

  • WebCore.xcodeproj/project.pbxproj:
  • html/canvas/WebGL2RenderingContext.cpp:

(WebCore::WebGL2RenderingContext::getPackPixelStoreParams const):
(WebCore::WebGL2RenderingContext::getUnpackPixelStoreParams const):

  • html/canvas/WebGL2RenderingContext.h:
  • html/canvas/WebGLRenderingContextBase.cpp:

(WebCore::WebGLRenderingContextBase::texImageArrayBufferViewHelper):
(WebCore::WebGLRenderingContextBase::texImageImpl):
(WebCore::WebGLRenderingContextBase::getPackPixelStoreParams const):
(WebCore::WebGLRenderingContextBase::getUnpackPixelStoreParams const):

  • html/canvas/WebGLRenderingContextBase.h:
  • platform/graphics/GraphicsContextGL.cpp:

(WebCore::getDataFormat):
(WebCore::texelBytesForFormat):
(WebCore::packPixels):
(WebCore::GraphicsContextGL::computeFormatAndTypeParameters):
(WebCore::GraphicsContextGL::computeImageSizeInBytes):
(WebCore::GraphicsContextGL::possibleFormatAndTypeForInternalFormat):
(WebCore::GraphicsContextGL::packImageData):
(WebCore::GraphicsContextGL::extractImageData):
(WebCore::GraphicsContextGL::extractTextureData):

  • platform/graphics/GraphicsContextGL.h:

(WebCore::GraphicsContextGL::Client::~Client):
(WebCore::GraphicsContextGL::addClient):
(WebCore::GraphicsContextGL::removeClient):
(WebCore::GraphicsContextGL::getInternalFramebufferSize const):

  • platform/graphics/GraphicsContextGLImageExtractor.cpp: Copied from Source/WebCore/platform/graphics/win/GraphicsContextGLDirect2D.cpp.

(WebCore::GraphicsContextGLImageExtractor::GraphicsContextGLImageExtractor):

  • platform/graphics/GraphicsContextGLImageExtractor.h: Added.

(WebCore::GraphicsContextGLImageExtractor::extractSucceeded):
(WebCore::GraphicsContextGLImageExtractor::imagePixelData):
(WebCore::GraphicsContextGLImageExtractor::imageWidth):
(WebCore::GraphicsContextGLImageExtractor::imageHeight):
(WebCore::GraphicsContextGLImageExtractor::imageSourceFormat):
(WebCore::GraphicsContextGLImageExtractor::imageAlphaOp):
(WebCore::GraphicsContextGLImageExtractor::imageSourceUnpackAlignment):
(WebCore::GraphicsContextGLImageExtractor::imageHtmlDomSource):

  • platform/graphics/angle/GraphicsContextGLANGLE.cpp:
  • platform/graphics/cairo/GraphicsContextGLCairo.cpp:

(WebCore::GraphicsContextGLImageExtractor::extractImage):

  • platform/graphics/cg/GraphicsContextGLCG.cpp:

(WebCore::GraphicsContextGLImageExtractor::extractImage):

  • platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:

(WebCore::GraphicsContextGLOpenGL::texImage2DResourceSafe):

  • platform/graphics/opengl/GraphicsContextGLOpenGL.h:
  • platform/graphics/opengl/GraphicsContextGLOpenGLCommon.cpp:
  • platform/graphics/win/GraphicsContextGLDirect2D.cpp:

(WebCore::GraphicsContextGLImageExtractor::extractImage):

Location:
trunk/Source/WebCore
Files:
1 added
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268577 r268578  
     12020-10-16  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        Refactor WebGL implementation to use only GraphicsContextGL part 1
     4        https://bugs.webkit.org/show_bug.cgi?id=217213
     5        <rdar://problem/69876105>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Part 1 of work towards WebGL implementation which uses
     10        GraphicsContextGL abstract base class instead of
     11        GraphicsContextGLOpenGL concrete class.
     12
     13        Move pixel data related static helper funcions from
     14        GraphicsContextGLOpenGL to GraphicsContextGL. These are
     15        normal pixel format calculation functions that do not have
     16        concrete class implementation details. Move pixel pack related
     17        structures to GraphicsContextGL.
     18
     19        Rename GraphicsContextGLOpenGL::ImageExtractor to
     20        GraphicsContextGLImageExtractor. The GraphicsContextGL class
     21        interface is already quite lengthy and the image extractor
     22        is not very tied to the context class.
     23
     24        Introduce a virtual member function in GraphicsContextGL for
     25        each call that is likely needed for the WebGL implementation.
     26
     27        No new tests, a refactor.
     28
     29        * WebCore.xcodeproj/project.pbxproj:
     30        * html/canvas/WebGL2RenderingContext.cpp:
     31        (WebCore::WebGL2RenderingContext::getPackPixelStoreParams const):
     32        (WebCore::WebGL2RenderingContext::getUnpackPixelStoreParams const):
     33        * html/canvas/WebGL2RenderingContext.h:
     34        * html/canvas/WebGLRenderingContextBase.cpp:
     35        (WebCore::WebGLRenderingContextBase::texImageArrayBufferViewHelper):
     36        (WebCore::WebGLRenderingContextBase::texImageImpl):
     37        (WebCore::WebGLRenderingContextBase::getPackPixelStoreParams const):
     38        (WebCore::WebGLRenderingContextBase::getUnpackPixelStoreParams const):
     39        * html/canvas/WebGLRenderingContextBase.h:
     40        * platform/graphics/GraphicsContextGL.cpp:
     41        (WebCore::getDataFormat):
     42        (WebCore::texelBytesForFormat):
     43        (WebCore::packPixels):
     44        (WebCore::GraphicsContextGL::computeFormatAndTypeParameters):
     45        (WebCore::GraphicsContextGL::computeImageSizeInBytes):
     46        (WebCore::GraphicsContextGL::possibleFormatAndTypeForInternalFormat):
     47        (WebCore::GraphicsContextGL::packImageData):
     48        (WebCore::GraphicsContextGL::extractImageData):
     49        (WebCore::GraphicsContextGL::extractTextureData):
     50        * platform/graphics/GraphicsContextGL.h:
     51        (WebCore::GraphicsContextGL::Client::~Client):
     52        (WebCore::GraphicsContextGL::addClient):
     53        (WebCore::GraphicsContextGL::removeClient):
     54        (WebCore::GraphicsContextGL::getInternalFramebufferSize const):
     55        * platform/graphics/GraphicsContextGLImageExtractor.cpp: Copied from Source/WebCore/platform/graphics/win/GraphicsContextGLDirect2D.cpp.
     56        (WebCore::GraphicsContextGLImageExtractor::GraphicsContextGLImageExtractor):
     57        * platform/graphics/GraphicsContextGLImageExtractor.h: Added.
     58        (WebCore::GraphicsContextGLImageExtractor::extractSucceeded):
     59        (WebCore::GraphicsContextGLImageExtractor::imagePixelData):
     60        (WebCore::GraphicsContextGLImageExtractor::imageWidth):
     61        (WebCore::GraphicsContextGLImageExtractor::imageHeight):
     62        (WebCore::GraphicsContextGLImageExtractor::imageSourceFormat):
     63        (WebCore::GraphicsContextGLImageExtractor::imageAlphaOp):
     64        (WebCore::GraphicsContextGLImageExtractor::imageSourceUnpackAlignment):
     65        (WebCore::GraphicsContextGLImageExtractor::imageHtmlDomSource):
     66        * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
     67        * platform/graphics/cairo/GraphicsContextGLCairo.cpp:
     68        (WebCore::GraphicsContextGLImageExtractor::extractImage):
     69        * platform/graphics/cg/GraphicsContextGLCG.cpp:
     70        (WebCore::GraphicsContextGLImageExtractor::extractImage):
     71        * platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
     72        (WebCore::GraphicsContextGLOpenGL::texImage2DResourceSafe):
     73        * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
     74        * platform/graphics/opengl/GraphicsContextGLOpenGLCommon.cpp:
     75        * platform/graphics/win/GraphicsContextGLDirect2D.cpp:
     76        (WebCore::GraphicsContextGLImageExtractor::extractImage):
     77
    1782020-10-16  Youenn Fablet  <youenn@apple.com>
    279
  • trunk/Source/WebCore/Sources.txt

    r268560 r268578  
    18961896platform/graphics/GraphicsContext.cpp
    18971897platform/graphics/GraphicsContextGL.cpp
     1898platform/graphics/GraphicsContextGLImageExtractor.cpp
    18981899platform/graphics/GraphicsContextImpl.cpp
    18991900platform/graphics/GraphicsLayer.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r268577 r268578  
    22192219                7BB34A152534579100029D08 /* WebGLLayerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A132534579100029D08 /* WebGLLayerClient.h */; };
    22202220                7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */; };
     2221                7BB34A48253776CA00029D08 /* GraphicsContextGLImageExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */; settings = {ATTRIBUTES = (Private, ); }; };
    22212222                7BE7427381FA906FBB4F0F2C /* JSSVGGraphicsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 950C4C02BED8936F818E2F99 /* JSSVGGraphicsElement.h */; };
    22222223                7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C029C6D2493C8F800268204 /* ColorTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1007110072                7BB34A132534579100029D08 /* WebGLLayerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLLayerClient.h; sourceTree = "<group>"; };
    1007210073                7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLANGLEUtilities.h; sourceTree = "<group>"; };
     10074                7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLImageExtractor.h; sourceTree = "<group>"; };
     10075                7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextGLImageExtractor.cpp; sourceTree = "<group>"; };
    1007310076                7C011F3D24FAD360005BEF10 /* Settings.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Settings.cpp.erb; sourceTree = "<group>"; };
    1007410077                7C011F3E24FAD360005BEF10 /* InternalSettingsGenerated.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = InternalSettingsGenerated.cpp.erb; sourceTree = "<group>"; };
     
    2614726150                                313DE86F23A96967008FC47B /* GraphicsContextGL.h */,
    2614826151                                7C330A011DF8FAC600D3395C /* GraphicsContextGLAttributes.h */,
     26152                                7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */,
     26153                                7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */,
    2614926154                                0F0012401FAD881000531D76 /* GraphicsContextImpl.cpp */,
    2615026155                                0F00123F1FAD87D600531D76 /* GraphicsContextImpl.h */,
     
    3162331628                                7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */,
    3162431629                                7C330A021DF8FAC600D3395C /* GraphicsContextGLAttributes.h in Headers */,
     31630                                7BB34A48253776CA00029D08 /* GraphicsContextGLImageExtractor.h in Headers */,
    3162531631                                49C7B9FC1042D3650009D447 /* GraphicsContextGLOpenGL.h in Headers */,
    3162631632                                319A728823C267FE0085353C /* GraphicsContextGLOpenGLManager.h in Headers */,
  • trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp

    r268502 r268578  
    30033003}
    30043004
    3005 GraphicsContextGLOpenGL::PixelStoreParams WebGL2RenderingContext::getPackPixelStoreParams() const
    3006 {
    3007     GraphicsContextGLOpenGL::PixelStoreParams params;
     3005WebGLRenderingContextBase::PixelStoreParams WebGL2RenderingContext::getPackPixelStoreParams() const
     3006{
     3007    PixelStoreParams params;
    30083008    params.alignment = m_packAlignment;
    30093009    params.rowLength = m_packRowLength;
     
    30133013}
    30143014
    3015 GraphicsContextGLOpenGL::PixelStoreParams WebGL2RenderingContext::getUnpackPixelStoreParams(TexImageDimension dimension) const
    3016 {
    3017     GraphicsContextGLOpenGL::PixelStoreParams params;
     3015WebGLRenderingContextBase::PixelStoreParams WebGL2RenderingContext::getUnpackPixelStoreParams(TexImageDimension dimension) const
     3016{
     3017    PixelStoreParams params;
    30183018    params.alignment = m_unpackAlignment;
    30193019    params.rowLength = m_unpackRowLength;
  • trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.h

    r268198 r268578  
    257257    GCGLuint maxTransformFeedbackSeparateAttribs() const;
    258258
    259     GraphicsContextGLOpenGL::PixelStoreParams getPackPixelStoreParams() const override;
    260     GraphicsContextGLOpenGL::PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const override;
     259    PixelStoreParams getPackPixelStoreParams() const override;
     260    PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const override;
    261261
    262262    bool checkAndTranslateAttachments(const char* functionName, GCGLenum, Vector<GCGLenum>&);
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

    r268255 r268578  
    5151#include "FrameView.h"
    5252#include "GraphicsContext.h"
     53#include "GraphicsContextGLImageExtractor.h"
    5354#include "HTMLCanvasElement.h"
    5455#include "HTMLImageElement.h"
     
    48894890        // Only enter here if width or height is non-zero. Otherwise, call to the
    48904891        // underlying driver to generate appropriate GL errors if needed.
    4891         GraphicsContextGLOpenGL::PixelStoreParams unpackParams = getUnpackPixelStoreParams(TexImageDimension::Tex2D);
     4892        PixelStoreParams unpackParams = getUnpackPixelStoreParams(TexImageDimension::Tex2D);
    48924893        GCGLint dataStoreWidth = unpackParams.rowLength ? unpackParams.rowLength : width;
    48934894        if (unpackParams.skipPixels + width > dataStoreWidth) {
     
    49464947        adjustedSourceImageRect.setY(image->height() - adjustedSourceImageRect.maxY());
    49474948
    4948     GraphicsContextGLOpenGL::ImageExtractor imageExtractor(image, domSource, premultiplyAlpha, m_unpackColorspaceConversion == GraphicsContextGL::NONE, ignoreNativeImageAlphaPremultiplication);
     4949    GraphicsContextGLImageExtractor imageExtractor(image, domSource, premultiplyAlpha, m_unpackColorspaceConversion == GraphicsContextGL::NONE, ignoreNativeImageAlphaPremultiplication);
    49494950    if (!imageExtractor.extractSucceeded()) {
    49504951        synthesizeGLError(GraphicsContextGL::INVALID_VALUE, functionName, "bad image data");
     
    63086309}
    63096310
    6310 GraphicsContextGLOpenGL::PixelStoreParams WebGLRenderingContextBase::getPackPixelStoreParams() const
    6311 {
    6312     GraphicsContextGLOpenGL::PixelStoreParams params;
     6311WebGLRenderingContextBase::PixelStoreParams WebGLRenderingContextBase::getPackPixelStoreParams() const
     6312{
     6313    PixelStoreParams params;
    63136314    params.alignment = m_packAlignment;
    63146315    return params;
    63156316}
    63166317
    6317 GraphicsContextGLOpenGL::PixelStoreParams WebGLRenderingContextBase::getUnpackPixelStoreParams(TexImageDimension dimension) const
     6318WebGLRenderingContextBase::PixelStoreParams WebGLRenderingContextBase::getUnpackPixelStoreParams(TexImageDimension dimension) const
    63186319{
    63196320    UNUSED_PARAM(dimension);
    6320     GraphicsContextGLOpenGL::PixelStoreParams params;
     6321    PixelStoreParams params;
    63216322    params.alignment = m_unpackAlignment;
    63226323    return params;
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h

    r268234 r268578  
    852852    void texSubImage2DBase(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum internalformat, GCGLenum format, GCGLenum type, GCGLsizei byteLength, const void* pixels);
    853853    static const char* getTexImageFunctionName(TexImageFunctionID);
    854 
    855     virtual GraphicsContextGLOpenGL::PixelStoreParams getPackPixelStoreParams() const;
    856     virtual GraphicsContextGLOpenGL::PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const;
     854    using PixelStoreParams = GraphicsContextGL::PixelStoreParams;
     855    virtual PixelStoreParams getPackPixelStoreParams() const;
     856    virtual PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const;
    857857
    858858#if !USE(ANGLE)
  • trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp

    r268198 r268578  
    3232
    3333#include "ExtensionsGL.h"
     34#include "FormatConverter.h"
     35#include "Image.h"
     36#include "ImageData.h"
     37#include "ImageObserver.h"
    3438
    3539namespace WebCore {
     40
     41static GraphicsContextGL::DataFormat getDataFormat(GCGLenum destinationFormat, GCGLenum destinationType)
     42{
     43    GraphicsContextGL::DataFormat dstFormat = GraphicsContextGL::DataFormat::RGBA8;
     44    switch (destinationType) {
     45    case GraphicsContextGL::BYTE:
     46        switch (destinationFormat) {
     47        case GraphicsContextGL::RED:
     48        case GraphicsContextGL::RED_INTEGER:
     49            dstFormat = GraphicsContextGL::DataFormat::R8_S;
     50            break;
     51        case GraphicsContextGL::RG:
     52        case GraphicsContextGL::RG_INTEGER:
     53            dstFormat = GraphicsContextGL::DataFormat::RG8_S;
     54            break;
     55        case GraphicsContextGL::RGB:
     56        case GraphicsContextGL::RGB_INTEGER:
     57            dstFormat = GraphicsContextGL::DataFormat::RGB8_S;
     58            break;
     59        case GraphicsContextGL::RGBA:
     60        case GraphicsContextGL::RGBA_INTEGER:
     61            dstFormat = GraphicsContextGL::DataFormat::RGBA8_S;
     62            break;
     63        default:
     64            ASSERT_NOT_REACHED();
     65        }
     66        break;
     67    case GraphicsContextGL::UNSIGNED_BYTE:
     68        switch (destinationFormat) {
     69        case GraphicsContextGL::RGB:
     70        case GraphicsContextGL::RGB_INTEGER:
     71        case GraphicsContextGL::SRGB:
     72            dstFormat = GraphicsContextGL::GraphicsContextGL::DataFormat::RGB8;
     73            break;
     74        case GraphicsContextGL::RGBA:
     75        case GraphicsContextGL::RGBA_INTEGER:
     76        case GraphicsContextGL::SRGB_ALPHA:
     77            dstFormat = GraphicsContextGL::DataFormat::RGBA8;
     78            break;
     79        case GraphicsContextGL::ALPHA:
     80            dstFormat = GraphicsContextGL::DataFormat::A8;
     81            break;
     82        case GraphicsContextGL::LUMINANCE:
     83        case GraphicsContextGL::RED:
     84        case GraphicsContextGL::RED_INTEGER:
     85            dstFormat = GraphicsContextGL::DataFormat::R8;
     86            break;
     87        case GraphicsContextGL::RG:
     88        case GraphicsContextGL::RG_INTEGER:
     89            dstFormat = GraphicsContextGL::DataFormat::RG8;
     90            break;
     91        case GraphicsContextGL::LUMINANCE_ALPHA:
     92            dstFormat = GraphicsContextGL::DataFormat::RA8;
     93            break;
     94        default:
     95            ASSERT_NOT_REACHED();
     96        }
     97        break;
     98    case GraphicsContextGL::SHORT:
     99        switch (destinationFormat) {
     100        case GraphicsContextGL::RED_INTEGER:
     101            dstFormat = GraphicsContextGL::DataFormat::R16_S;
     102            break;
     103        case GraphicsContextGL::RG_INTEGER:
     104            dstFormat = GraphicsContextGL::DataFormat::RG16_S;
     105            break;
     106        case GraphicsContextGL::RGB_INTEGER:
     107            dstFormat = GraphicsContextGL::DataFormat::RGB16_S;
     108            break;
     109        case GraphicsContextGL::RGBA_INTEGER:
     110            dstFormat = GraphicsContextGL::DataFormat::RGBA16_S;
     111            break;
     112        default:
     113            ASSERT_NOT_REACHED();
     114        }
     115        break;
     116    case GraphicsContextGL::UNSIGNED_SHORT:
     117        switch (destinationFormat) {
     118        case GraphicsContextGL::RED_INTEGER:
     119            dstFormat = GraphicsContextGL::DataFormat::R16;
     120            break;
     121        case GraphicsContextGL::DEPTH_COMPONENT:
     122            dstFormat = GraphicsContextGL::DataFormat::D16;
     123            break;
     124        case GraphicsContextGL::RG_INTEGER:
     125            dstFormat = GraphicsContextGL::DataFormat::RG16;
     126            break;
     127        case GraphicsContextGL::RGB_INTEGER:
     128            dstFormat = GraphicsContextGL::DataFormat::RGB16;
     129            break;
     130        case GraphicsContextGL::RGBA_INTEGER:
     131            dstFormat = GraphicsContextGL::DataFormat::RGBA16;
     132            break;
     133        default:
     134            ASSERT_NOT_REACHED();
     135        }
     136        break;
     137    case GraphicsContextGL::INT:
     138        switch (destinationFormat) {
     139        case GraphicsContextGL::RED_INTEGER:
     140            dstFormat = GraphicsContextGL::DataFormat::R32_S;
     141            break;
     142        case GraphicsContextGL::RG_INTEGER:
     143            dstFormat = GraphicsContextGL::DataFormat::RG32_S;
     144            break;
     145        case GraphicsContextGL::RGB_INTEGER:
     146            dstFormat = GraphicsContextGL::DataFormat::RGB32_S;
     147            break;
     148        case GraphicsContextGL::RGBA_INTEGER:
     149            dstFormat = GraphicsContextGL::DataFormat::RGBA32_S;
     150            break;
     151        default:
     152            ASSERT_NOT_REACHED();
     153        }
     154        break;
     155    case GraphicsContextGL::UNSIGNED_INT:
     156        switch (destinationFormat) {
     157        case GraphicsContextGL::RED_INTEGER:
     158            dstFormat = GraphicsContextGL::DataFormat::R32;
     159            break;
     160        case GraphicsContextGL::DEPTH_COMPONENT:
     161            dstFormat = GraphicsContextGL::DataFormat::D32;
     162            break;
     163        case GraphicsContextGL::RG_INTEGER:
     164            dstFormat = GraphicsContextGL::DataFormat::RG32;
     165            break;
     166        case GraphicsContextGL::RGB_INTEGER:
     167            dstFormat = GraphicsContextGL::DataFormat::RGB32;
     168            break;
     169        case GraphicsContextGL::RGBA_INTEGER:
     170            dstFormat = GraphicsContextGL::DataFormat::RGBA32;
     171            break;
     172        default:
     173            ASSERT_NOT_REACHED();
     174        }
     175        break;
     176    case GraphicsContextGL::HALF_FLOAT_OES: // OES_texture_half_float
     177    case GraphicsContextGL::HALF_FLOAT:
     178        switch (destinationFormat) {
     179        case GraphicsContextGL::RGBA:
     180            dstFormat = GraphicsContextGL::DataFormat::RGBA16F;
     181            break;
     182        case GraphicsContextGL::RGB:
     183            dstFormat = GraphicsContextGL::DataFormat::RGB16F;
     184            break;
     185        case GraphicsContextGL::RG:
     186            dstFormat = GraphicsContextGL::DataFormat::RG16F;
     187            break;
     188        case GraphicsContextGL::ALPHA:
     189            dstFormat = GraphicsContextGL::DataFormat::A16F;
     190            break;
     191        case GraphicsContextGL::LUMINANCE:
     192        case GraphicsContextGL::RED:
     193            dstFormat = GraphicsContextGL::DataFormat::R16F;
     194            break;
     195        case GraphicsContextGL::LUMINANCE_ALPHA:
     196            dstFormat = GraphicsContextGL::DataFormat::RA16F;
     197            break;
     198        case GraphicsContextGL::SRGB:
     199            dstFormat = GraphicsContextGL::DataFormat::RGB16F;
     200            break;
     201        case GraphicsContextGL::SRGB_ALPHA:
     202            dstFormat = GraphicsContextGL::DataFormat::RGBA16F;
     203            break;
     204        default:
     205            ASSERT_NOT_REACHED();
     206        }
     207        break;
     208    case GraphicsContextGL::FLOAT: // OES_texture_float
     209        switch (destinationFormat) {
     210        case GraphicsContextGL::RGBA:
     211            dstFormat = GraphicsContextGL::DataFormat::RGBA32F;
     212            break;
     213        case GraphicsContextGL::RGB:
     214            dstFormat = GraphicsContextGL::DataFormat::RGB32F;
     215            break;
     216        case GraphicsContextGL::RG:
     217            dstFormat = GraphicsContextGL::DataFormat::RG32F;
     218            break;
     219        case GraphicsContextGL::ALPHA:
     220            dstFormat = GraphicsContextGL::DataFormat::A32F;
     221            break;
     222        case GraphicsContextGL::LUMINANCE:
     223        case GraphicsContextGL::RED:
     224            dstFormat = GraphicsContextGL::DataFormat::R32F;
     225            break;
     226        case GraphicsContextGL::DEPTH_COMPONENT:
     227            dstFormat = GraphicsContextGL::DataFormat::D32F;
     228            break;
     229        case GraphicsContextGL::LUMINANCE_ALPHA:
     230            dstFormat = GraphicsContextGL::DataFormat::RA32F;
     231            break;
     232        case GraphicsContextGL::SRGB:
     233            dstFormat = GraphicsContextGL::DataFormat::RGB32F;
     234            break;
     235        case GraphicsContextGL::SRGB_ALPHA:
     236            dstFormat = GraphicsContextGL::DataFormat::RGBA32F;
     237            break;
     238        default:
     239            ASSERT_NOT_REACHED();
     240        }
     241        break;
     242    case GraphicsContextGL::UNSIGNED_SHORT_4_4_4_4:
     243        dstFormat = GraphicsContextGL::DataFormat::RGBA4444;
     244        break;
     245    case GraphicsContextGL::UNSIGNED_SHORT_5_5_5_1:
     246        dstFormat = GraphicsContextGL::DataFormat::RGBA5551;
     247        break;
     248    case GraphicsContextGL::UNSIGNED_SHORT_5_6_5:
     249        dstFormat = GraphicsContextGL::DataFormat::RGB565;
     250        break;
     251    case GraphicsContextGL::UNSIGNED_INT_5_9_9_9_REV:
     252        dstFormat = GraphicsContextGL::DataFormat::RGB5999;
     253        break;
     254    case GraphicsContextGL::UNSIGNED_INT_24_8:
     255        dstFormat = GraphicsContextGL::DataFormat::DS24_8;
     256        break;
     257    case GraphicsContextGL::UNSIGNED_INT_10F_11F_11F_REV:
     258        dstFormat = GraphicsContextGL::DataFormat::RGB10F11F11F;
     259        break;
     260    case GraphicsContextGL::UNSIGNED_INT_2_10_10_10_REV:
     261        dstFormat = GraphicsContextGL::DataFormat::RGBA2_10_10_10;
     262        break;
     263    default:
     264        ASSERT_NOT_REACHED();
     265    }
     266    return dstFormat;
     267}
     268
     269ALWAYS_INLINE static unsigned texelBytesForFormat(GraphicsContextGL::DataFormat format)
     270{
     271    switch (format) {
     272    case GraphicsContextGL::DataFormat::R8:
     273    case GraphicsContextGL::DataFormat::R8_S:
     274    case GraphicsContextGL::DataFormat::A8:
     275        return 1;
     276    case GraphicsContextGL::DataFormat::RG8:
     277    case GraphicsContextGL::DataFormat::RG8_S:
     278    case GraphicsContextGL::DataFormat::RA8:
     279    case GraphicsContextGL::DataFormat::AR8:
     280    case GraphicsContextGL::DataFormat::RGBA5551:
     281    case GraphicsContextGL::DataFormat::RGBA4444:
     282    case GraphicsContextGL::DataFormat::RGB565:
     283    case GraphicsContextGL::DataFormat::A16F:
     284    case GraphicsContextGL::DataFormat::R16:
     285    case GraphicsContextGL::DataFormat::R16_S:
     286    case GraphicsContextGL::DataFormat::R16F:
     287    case GraphicsContextGL::DataFormat::D16:
     288        return 2;
     289    case GraphicsContextGL::DataFormat::RGB8:
     290    case GraphicsContextGL::DataFormat::RGB8_S:
     291    case GraphicsContextGL::DataFormat::BGR8:
     292        return 3;
     293    case GraphicsContextGL::DataFormat::RGBA8:
     294    case GraphicsContextGL::DataFormat::RGBA8_S:
     295    case GraphicsContextGL::DataFormat::ARGB8:
     296    case GraphicsContextGL::DataFormat::ABGR8:
     297    case GraphicsContextGL::DataFormat::BGRA8:
     298    case GraphicsContextGL::DataFormat::R32:
     299    case GraphicsContextGL::DataFormat::R32_S:
     300    case GraphicsContextGL::DataFormat::R32F:
     301    case GraphicsContextGL::DataFormat::A32F:
     302    case GraphicsContextGL::DataFormat::RA16F:
     303    case GraphicsContextGL::DataFormat::RGBA2_10_10_10:
     304    case GraphicsContextGL::DataFormat::RGB10F11F11F:
     305    case GraphicsContextGL::DataFormat::RGB5999:
     306    case GraphicsContextGL::DataFormat::RG16:
     307    case GraphicsContextGL::DataFormat::RG16_S:
     308    case GraphicsContextGL::DataFormat::RG16F:
     309    case GraphicsContextGL::DataFormat::D32:
     310    case GraphicsContextGL::DataFormat::D32F:
     311    case GraphicsContextGL::DataFormat::DS24_8:
     312        return 4;
     313    case GraphicsContextGL::DataFormat::RGB16:
     314    case GraphicsContextGL::DataFormat::RGB16_S:
     315    case GraphicsContextGL::DataFormat::RGB16F:
     316        return 6;
     317    case GraphicsContextGL::DataFormat::RGBA16:
     318    case GraphicsContextGL::DataFormat::RGBA16_S:
     319    case GraphicsContextGL::DataFormat::RA32F:
     320    case GraphicsContextGL::DataFormat::RGBA16F:
     321    case GraphicsContextGL::DataFormat::RG32:
     322    case GraphicsContextGL::DataFormat::RG32_S:
     323    case GraphicsContextGL::DataFormat::RG32F:
     324        return 8;
     325    case GraphicsContextGL::DataFormat::RGB32:
     326    case GraphicsContextGL::DataFormat::RGB32_S:
     327    case GraphicsContextGL::DataFormat::RGB32F:
     328        return 12;
     329    case GraphicsContextGL::DataFormat::RGBA32:
     330    case GraphicsContextGL::DataFormat::RGBA32_S:
     331    case GraphicsContextGL::DataFormat::RGBA32F:
     332        return 16;
     333    default:
     334        return 0;
     335    }
     336}
     337
     338
     339// Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
     340// data into the specified OpenGL destination format and type.
     341// A sourceUnpackAlignment of zero indicates that the source
     342// data is tightly packed. Non-zero values may take a slow path.
     343// Destination data will have no gaps between rows.
     344static bool packPixels(const uint8_t* sourceData, GraphicsContextGL::DataFormat sourceDataFormat, unsigned sourceDataWidth, unsigned sourceDataHeight, const IntRect& sourceDataSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, unsigned destinationFormat, unsigned destinationType, GraphicsContextGL::AlphaOp alphaOp, void* destinationData, bool flipY)
     345{
     346    ASSERT(depth >= 1);
     347    UNUSED_PARAM(sourceDataHeight); // Derived from sourceDataSubRectangle.height().
     348    if (!unpackImageHeight)
     349        unpackImageHeight = sourceDataSubRectangle.height();
     350    int validSrc = sourceDataWidth * texelBytesForFormat(sourceDataFormat);
     351    int remainder = sourceUnpackAlignment ? (validSrc % sourceUnpackAlignment) : 0;
     352    int srcStride = remainder ? (validSrc + sourceUnpackAlignment - remainder) : validSrc;
     353    int srcRowOffset = sourceDataSubRectangle.x() * texelBytesForFormat(sourceDataFormat);
     354
     355    GraphicsContextGL::DataFormat dstDataFormat = getDataFormat(destinationFormat, destinationType);
     356    int dstStride = sourceDataSubRectangle.width() * texelBytesForFormat(dstDataFormat);
     357    if (flipY) {
     358        destinationData = static_cast<uint8_t*>(destinationData) + dstStride * ((depth * sourceDataSubRectangle.height()) - 1);
     359        dstStride = -dstStride;
     360    }
     361    if (!GraphicsContextGL::hasAlpha(sourceDataFormat) || !GraphicsContextGL::hasColor(sourceDataFormat) || !GraphicsContextGL::hasColor(dstDataFormat))
     362        alphaOp = GraphicsContextGL::AlphaOp::DoNothing;
     363
     364    if (sourceDataFormat == dstDataFormat && alphaOp == GraphicsContextGL::AlphaOp::DoNothing) {
     365        const uint8_t* basePtr = sourceData + srcStride * sourceDataSubRectangle.y();
     366        const uint8_t* baseEnd = sourceData + srcStride * sourceDataSubRectangle.maxY();
     367
     368        // If packing multiple images into a 3D texture, and flipY is true,
     369        // then the sub-rectangle is pointing at the start of the
     370        // "bottommost" of those images. Since the source pointer strides in
     371        // the positive direction, we need to back it up to point at the
     372        // last, or "topmost", of these images.
     373        if (flipY && depth > 1) {
     374            const ptrdiff_t distanceToTopImage = (depth - 1) * srcStride * unpackImageHeight;
     375            basePtr -= distanceToTopImage;
     376            baseEnd -= distanceToTopImage;
     377        }
     378
     379        unsigned rowSize = (dstStride > 0) ? dstStride: -dstStride;
     380        uint8_t* dst = static_cast<uint8_t*>(destinationData);
     381
     382        for (int i = 0; i < depth; ++i) {
     383            const uint8_t* ptr = basePtr;
     384            const uint8_t* ptrEnd = baseEnd;
     385            while (ptr < ptrEnd) {
     386                memcpy(dst, ptr + srcRowOffset, rowSize);
     387                ptr += srcStride;
     388                dst += dstStride;
     389            }
     390            basePtr += unpackImageHeight * srcStride;
     391            baseEnd += unpackImageHeight * srcStride;
     392        }
     393        return true;
     394    }
     395
     396    FormatConverter converter(
     397        sourceDataSubRectangle, depth,
     398        unpackImageHeight, sourceData, destinationData,
     399        srcStride, srcRowOffset, dstStride);
     400    converter.convert(sourceDataFormat, dstDataFormat, alphaOp);
     401    if (!converter.success())
     402        return false;
     403    return true;
     404}
     405
    36406
    37407GraphicsContextGL::GraphicsContextGL(GraphicsContextGLAttributes attrs, Destination destination, GraphicsContextGL*)
     
    185555}
    186556
     557bool GraphicsContextGL::computeFormatAndTypeParameters(GCGLenum format, GCGLenum type, unsigned* componentsPerPixel, unsigned* bytesPerComponent)
     558{
     559    switch (format) {
     560    case GraphicsContextGL::ALPHA:
     561    case GraphicsContextGL::LUMINANCE:
     562    case GraphicsContextGL::RED:
     563    case GraphicsContextGL::RED_INTEGER:
     564    case GraphicsContextGL::DEPTH_COMPONENT:
     565    case GraphicsContextGL::DEPTH_STENCIL: // Treat it as one component.
     566        *componentsPerPixel = 1;
     567        break;
     568    case GraphicsContextGL::LUMINANCE_ALPHA:
     569    case GraphicsContextGL::RG:
     570    case GraphicsContextGL::RG_INTEGER:
     571        *componentsPerPixel = 2;
     572        break;
     573    case GraphicsContextGL::RGB:
     574    case GraphicsContextGL::RGB_INTEGER:
     575    case ExtensionsGL::SRGB_EXT:
     576        *componentsPerPixel = 3;
     577        break;
     578    case GraphicsContextGL::RGBA:
     579    case GraphicsContextGL::RGBA_INTEGER:
     580    case ExtensionsGL::BGRA_EXT: // GL_EXT_texture_format_BGRA8888
     581    case ExtensionsGL::SRGB_ALPHA_EXT:
     582        *componentsPerPixel = 4;
     583        break;
     584    default:
     585        return false;
     586    }
     587
     588    switch (type) {
     589    case GraphicsContextGL::BYTE:
     590        *bytesPerComponent = sizeof(GCGLbyte);
     591        break;
     592    case GraphicsContextGL::UNSIGNED_BYTE:
     593        *bytesPerComponent = sizeof(GCGLubyte);
     594        break;
     595    case GraphicsContextGL::SHORT:
     596        *bytesPerComponent = sizeof(GCGLshort);
     597        break;
     598    case GraphicsContextGL::UNSIGNED_SHORT:
     599        *bytesPerComponent = sizeof(GCGLushort);
     600        break;
     601    case GraphicsContextGL::UNSIGNED_SHORT_5_6_5:
     602    case GraphicsContextGL::UNSIGNED_SHORT_4_4_4_4:
     603    case GraphicsContextGL::UNSIGNED_SHORT_5_5_5_1:
     604        *componentsPerPixel = 1;
     605        *bytesPerComponent = sizeof(GCGLushort);
     606        break;
     607    case GraphicsContextGL::INT:
     608        *bytesPerComponent = sizeof(GCGLint);
     609        break;
     610    case GraphicsContextGL::UNSIGNED_INT:
     611        *bytesPerComponent = sizeof(GCGLuint);
     612        break;
     613    case GraphicsContextGL::UNSIGNED_INT_24_8:
     614    case GraphicsContextGL::UNSIGNED_INT_10F_11F_11F_REV:
     615    case GraphicsContextGL::UNSIGNED_INT_5_9_9_9_REV:
     616    case GraphicsContextGL::UNSIGNED_INT_2_10_10_10_REV:
     617        *componentsPerPixel = 1;
     618        *bytesPerComponent = sizeof(GCGLuint);
     619        break;
     620    case GraphicsContextGL::FLOAT: // OES_texture_float
     621        *bytesPerComponent = sizeof(GCGLfloat);
     622        break;
     623    case GraphicsContextGL::HALF_FLOAT:
     624    case GraphicsContextGL::HALF_FLOAT_OES: // OES_texture_half_float
     625        *bytesPerComponent = sizeof(GCGLhalffloat);
     626        break;
     627    case GraphicsContextGL::FLOAT_32_UNSIGNED_INT_24_8_REV:
     628        *bytesPerComponent = sizeof(GCGLfloat) + sizeof(GCGLuint);
     629        break;
     630    default:
     631        return false;
     632    }
     633    return true;
     634}
     635
     636GCGLenum GraphicsContextGL::computeImageSizeInBytes(GCGLenum format, GCGLenum type, GCGLsizei width, GCGLsizei height, GCGLsizei depth, const PixelStoreParams& params, unsigned* imageSizeInBytes, unsigned* paddingInBytes, unsigned* skipSizeInBytes)
     637{
     638    ASSERT(imageSizeInBytes);
     639    ASSERT(params.alignment == 1 || params.alignment == 2 || params.alignment == 4 || params.alignment == 8);
     640    ASSERT(params.rowLength >= 0);
     641    ASSERT(params.imageHeight >= 0);
     642    ASSERT(params.skipPixels >= 0);
     643    ASSERT(params.skipRows >= 0);
     644    ASSERT(params.skipImages >= 0);
     645    if (width < 0 || height < 0 || depth < 0)
     646        return GraphicsContextGL::INVALID_VALUE;
     647    if (!width || !height || !depth) {
     648        *imageSizeInBytes = 0;
     649        if (paddingInBytes)
     650            *paddingInBytes = 0;
     651        if (skipSizeInBytes)
     652            *skipSizeInBytes = 0;
     653        return GraphicsContextGL::NO_ERROR;
     654    }
     655
     656    int rowLength = params.rowLength > 0 ? params.rowLength : width;
     657    int imageHeight = params.imageHeight > 0 ? params.imageHeight : height;
     658
     659    unsigned bytesPerComponent, componentsPerPixel;
     660    if (!computeFormatAndTypeParameters(format, type, &componentsPerPixel, &bytesPerComponent))
     661        return GraphicsContextGL::INVALID_ENUM;
     662    unsigned bytesPerGroup = bytesPerComponent * componentsPerPixel;
     663    Checked<uint32_t, RecordOverflow> checkedValue = static_cast<uint32_t>(rowLength);
     664    checkedValue *= bytesPerGroup;
     665    if (checkedValue.hasOverflowed())
     666        return GraphicsContextGL::INVALID_VALUE;
     667
     668    unsigned lastRowSize;
     669    if (params.rowLength > 0 && params.rowLength != width) {
     670        Checked<uint32_t, RecordOverflow> tmp = width;
     671        tmp *= bytesPerGroup;
     672        if (tmp.hasOverflowed())
     673            return GraphicsContextGL::INVALID_VALUE;
     674        lastRowSize = tmp.unsafeGet();
     675    } else
     676        lastRowSize = checkedValue.unsafeGet();
     677
     678    unsigned padding = 0;
     679    unsigned residual = checkedValue.unsafeGet() % params.alignment;
     680    if (residual) {
     681        padding = params.alignment - residual;
     682        checkedValue += padding;
     683    }
     684    if (checkedValue.hasOverflowed())
     685        return GraphicsContextGL::INVALID_VALUE;
     686    unsigned paddedRowSize = checkedValue.unsafeGet();
     687
     688    Checked<uint32_t, RecordOverflow> rows = imageHeight;
     689    rows *= (depth - 1);
     690    // Last image is not affected by IMAGE_HEIGHT parameter.
     691    rows += height;
     692    if (rows.hasOverflowed())
     693        return GraphicsContextGL::INVALID_VALUE;
     694    checkedValue *= (rows - 1);
     695    // Last row is not affected by ROW_LENGTH parameter.
     696    checkedValue += lastRowSize;
     697    if (checkedValue.hasOverflowed())
     698        return GraphicsContextGL::INVALID_VALUE;
     699    *imageSizeInBytes = checkedValue.unsafeGet();
     700    if (paddingInBytes)
     701        *paddingInBytes = padding;
     702
     703    Checked<uint32_t, RecordOverflow> skipSize = 0;
     704    if (params.skipImages > 0) {
     705        Checked<uint32_t, RecordOverflow> tmp = paddedRowSize;
     706        tmp *= imageHeight;
     707        tmp *= params.skipImages;
     708        if (tmp.hasOverflowed())
     709            return GraphicsContextGL::INVALID_VALUE;
     710        skipSize += tmp.unsafeGet();
     711    }
     712    if (params.skipRows > 0) {
     713        Checked<uint32_t, RecordOverflow> tmp = paddedRowSize;
     714        tmp *= params.skipRows;
     715        if (tmp.hasOverflowed())
     716            return GraphicsContextGL::INVALID_VALUE;
     717        skipSize += tmp.unsafeGet();
     718    }
     719    if (params.skipPixels > 0) {
     720        Checked<uint32_t, RecordOverflow> tmp = bytesPerGroup;
     721        tmp *= params.skipPixels;
     722        if (tmp.hasOverflowed())
     723            return GraphicsContextGL::INVALID_VALUE;
     724        skipSize += tmp.unsafeGet();
     725    }
     726    if (skipSize.hasOverflowed())
     727        return GraphicsContextGL::INVALID_VALUE;
     728    if (skipSizeInBytes)
     729        *skipSizeInBytes = skipSize.unsafeGet();
     730
     731    checkedValue += skipSize.unsafeGet();
     732    if (checkedValue.hasOverflowed())
     733        return GraphicsContextGL::INVALID_VALUE;
     734    return GraphicsContextGL::NO_ERROR;
     735}
     736
     737#if !USE(ANGLE)
     738bool GraphicsContextGL::possibleFormatAndTypeForInternalFormat(GCGLenum internalFormat, GCGLenum& format, GCGLenum& type)
     739{
     740#define POSSIBLE_FORMAT_TYPE_CASE(internalFormatMacro, formatMacro, typeMacro) case internalFormatMacro: \
     741        format = formatMacro; \
     742        type = typeMacro; \
     743        break;
     744
     745    switch (internalFormat) {
     746        POSSIBLE_FORMAT_TYPE_CASE(RGB, RGB, UNSIGNED_BYTE);
     747        POSSIBLE_FORMAT_TYPE_CASE(RGBA, RGBA, UNSIGNED_BYTE);
     748        POSSIBLE_FORMAT_TYPE_CASE(LUMINANCE_ALPHA, LUMINANCE_ALPHA, UNSIGNED_BYTE);
     749        POSSIBLE_FORMAT_TYPE_CASE(LUMINANCE, LUMINANCE, UNSIGNED_BYTE);
     750        POSSIBLE_FORMAT_TYPE_CASE(ALPHA, ALPHA, UNSIGNED_BYTE);
     751        POSSIBLE_FORMAT_TYPE_CASE(R8, RED, UNSIGNED_BYTE);
     752        POSSIBLE_FORMAT_TYPE_CASE(R8_SNORM, RED, BYTE);
     753        POSSIBLE_FORMAT_TYPE_CASE(R16F, RED, HALF_FLOAT);
     754        POSSIBLE_FORMAT_TYPE_CASE(R32F, RED, FLOAT);
     755        POSSIBLE_FORMAT_TYPE_CASE(R8UI, RED_INTEGER, UNSIGNED_BYTE);
     756        POSSIBLE_FORMAT_TYPE_CASE(R8I, RED_INTEGER, BYTE);
     757        POSSIBLE_FORMAT_TYPE_CASE(R16UI, RED_INTEGER, UNSIGNED_SHORT);
     758        POSSIBLE_FORMAT_TYPE_CASE(R16I, RED_INTEGER, SHORT);
     759        POSSIBLE_FORMAT_TYPE_CASE(R32UI, RED_INTEGER, UNSIGNED_INT);
     760        POSSIBLE_FORMAT_TYPE_CASE(R32I, RED_INTEGER, INT);
     761        POSSIBLE_FORMAT_TYPE_CASE(RG8, RG, UNSIGNED_BYTE);
     762        POSSIBLE_FORMAT_TYPE_CASE(RG8_SNORM, RG, BYTE);
     763        POSSIBLE_FORMAT_TYPE_CASE(RG16F, RG, HALF_FLOAT);
     764        POSSIBLE_FORMAT_TYPE_CASE(RG32F, RG, FLOAT);
     765        POSSIBLE_FORMAT_TYPE_CASE(RG8UI, RG_INTEGER, UNSIGNED_BYTE);
     766        POSSIBLE_FORMAT_TYPE_CASE(RG8I, RG_INTEGER, BYTE);
     767        POSSIBLE_FORMAT_TYPE_CASE(RG16UI, RG_INTEGER, UNSIGNED_SHORT);
     768        POSSIBLE_FORMAT_TYPE_CASE(RG16I, RG_INTEGER, SHORT);
     769        POSSIBLE_FORMAT_TYPE_CASE(RG32UI, RG_INTEGER, UNSIGNED_INT);
     770        POSSIBLE_FORMAT_TYPE_CASE(RG32I, RG_INTEGER, INT);
     771        POSSIBLE_FORMAT_TYPE_CASE(RGB8, RGB, UNSIGNED_BYTE);
     772        POSSIBLE_FORMAT_TYPE_CASE(SRGB8, RGB, UNSIGNED_BYTE);
     773        POSSIBLE_FORMAT_TYPE_CASE(RGB565, RGB, UNSIGNED_SHORT_5_6_5);
     774        POSSIBLE_FORMAT_TYPE_CASE(RGB8_SNORM, RGB, BYTE);
     775        POSSIBLE_FORMAT_TYPE_CASE(R11F_G11F_B10F, RGB, UNSIGNED_INT_10F_11F_11F_REV);
     776        POSSIBLE_FORMAT_TYPE_CASE(RGB9_E5, RGB, UNSIGNED_INT_5_9_9_9_REV);
     777        POSSIBLE_FORMAT_TYPE_CASE(RGB16F, RGB, HALF_FLOAT);
     778        POSSIBLE_FORMAT_TYPE_CASE(RGB32F, RGB, FLOAT);
     779        POSSIBLE_FORMAT_TYPE_CASE(RGB8UI, RGB_INTEGER, UNSIGNED_BYTE);
     780        POSSIBLE_FORMAT_TYPE_CASE(RGB8I, RGB_INTEGER, BYTE);
     781        POSSIBLE_FORMAT_TYPE_CASE(RGB16UI, RGB_INTEGER, UNSIGNED_SHORT);
     782        POSSIBLE_FORMAT_TYPE_CASE(RGB16I, RGB_INTEGER, SHORT);
     783        POSSIBLE_FORMAT_TYPE_CASE(RGB32UI, RGB_INTEGER, UNSIGNED_INT);
     784        POSSIBLE_FORMAT_TYPE_CASE(RGB32I, RGB_INTEGER, INT);
     785        POSSIBLE_FORMAT_TYPE_CASE(RGBA8, RGBA, UNSIGNED_BYTE);
     786        POSSIBLE_FORMAT_TYPE_CASE(SRGB8_ALPHA8, RGBA, UNSIGNED_BYTE);
     787        POSSIBLE_FORMAT_TYPE_CASE(RGBA8_SNORM, RGBA, BYTE);
     788        POSSIBLE_FORMAT_TYPE_CASE(RGB5_A1, RGBA, UNSIGNED_SHORT_5_5_5_1);
     789        POSSIBLE_FORMAT_TYPE_CASE(RGBA4, RGBA, UNSIGNED_SHORT_4_4_4_4);
     790        POSSIBLE_FORMAT_TYPE_CASE(RGB10_A2, RGBA, UNSIGNED_INT_2_10_10_10_REV);
     791        POSSIBLE_FORMAT_TYPE_CASE(RGBA16F, RGBA, HALF_FLOAT);
     792        POSSIBLE_FORMAT_TYPE_CASE(RGBA32F, RGBA, FLOAT);
     793        POSSIBLE_FORMAT_TYPE_CASE(RGBA8UI, RGBA_INTEGER, UNSIGNED_BYTE);
     794        POSSIBLE_FORMAT_TYPE_CASE(RGBA8I, RGBA_INTEGER, BYTE);
     795        POSSIBLE_FORMAT_TYPE_CASE(RGB10_A2UI, RGBA_INTEGER, UNSIGNED_INT_2_10_10_10_REV);
     796        POSSIBLE_FORMAT_TYPE_CASE(RGBA16UI, RGBA_INTEGER, UNSIGNED_SHORT);
     797        POSSIBLE_FORMAT_TYPE_CASE(RGBA16I, RGBA_INTEGER, SHORT);
     798        POSSIBLE_FORMAT_TYPE_CASE(RGBA32I, RGBA_INTEGER, INT);
     799        POSSIBLE_FORMAT_TYPE_CASE(RGBA32UI, RGBA_INTEGER, UNSIGNED_INT);
     800        POSSIBLE_FORMAT_TYPE_CASE(DEPTH_COMPONENT16, DEPTH_COMPONENT, UNSIGNED_SHORT);
     801        POSSIBLE_FORMAT_TYPE_CASE(DEPTH_COMPONENT, DEPTH_COMPONENT, UNSIGNED_SHORT);
     802        POSSIBLE_FORMAT_TYPE_CASE(DEPTH_COMPONENT24, DEPTH_COMPONENT, UNSIGNED_INT);
     803        POSSIBLE_FORMAT_TYPE_CASE(DEPTH_COMPONENT32F, DEPTH_COMPONENT, FLOAT);
     804        POSSIBLE_FORMAT_TYPE_CASE(DEPTH_STENCIL, DEPTH_STENCIL, UNSIGNED_INT_24_8);
     805        POSSIBLE_FORMAT_TYPE_CASE(DEPTH24_STENCIL8, DEPTH_STENCIL, UNSIGNED_INT_24_8);
     806        POSSIBLE_FORMAT_TYPE_CASE(DEPTH32F_STENCIL8, DEPTH_STENCIL, FLOAT_32_UNSIGNED_INT_24_8_REV);
     807        POSSIBLE_FORMAT_TYPE_CASE(ExtensionsGL::SRGB_EXT, ExtensionsGL::SRGB_EXT, UNSIGNED_BYTE);
     808        POSSIBLE_FORMAT_TYPE_CASE(ExtensionsGL::SRGB_ALPHA_EXT, ExtensionsGL::SRGB_ALPHA_EXT, UNSIGNED_BYTE);
     809    default:
     810        return false;
     811    }
     812#undef POSSIBLE_FORMAT_TYPE_CASE
     813
     814    return true;
     815}
     816#endif // !USE(ANGLE)
     817
     818bool GraphicsContextGL::packImageData(Image* image, const void* pixels, GCGLenum format, GCGLenum type, bool flipY, AlphaOp alphaOp, DataFormat sourceFormat, unsigned sourceImageWidth, unsigned sourceImageHeight, const IntRect& sourceImageSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, Vector<uint8_t>& data)
     819{
     820    if (!image || !pixels)
     821        return false;
     822
     823    unsigned packedSize;
     824    // Output data is tightly packed (alignment == 1).
     825    PixelStoreParams params;
     826    params.alignment = 1;
     827    if (computeImageSizeInBytes(format, type, sourceImageSubRectangle.width(), sourceImageSubRectangle.height(), depth, params, &packedSize, nullptr, nullptr) != GraphicsContextGL::NO_ERROR)
     828        return false;
     829    data.resize(packedSize);
     830
     831    if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, sourceImageWidth, sourceImageHeight, sourceImageSubRectangle, depth, sourceUnpackAlignment, unpackImageHeight, format, type, alphaOp, data.data(), flipY))
     832        return false;
     833    if (ImageObserver* observer = image->imageObserver())
     834        observer->didDraw(*image);
     835    return true;
     836}
     837
     838bool GraphicsContextGL::extractImageData(ImageData* imageData, DataFormat sourceDataFormat, const IntRect& sourceImageSubRectangle, int depth, int unpackImageHeight, GCGLenum format, GCGLenum type, bool flipY, bool premultiplyAlpha, Vector<uint8_t>& data)
     839{
     840    if (!imageData)
     841        return false;
     842    int width = imageData->width();
     843    int height = imageData->height();
     844
     845    unsigned packedSize;
     846    // Output data is tightly packed (alignment == 1).
     847    PixelStoreParams params;
     848    params.alignment = 1;
     849    if (computeImageSizeInBytes(format, type, sourceImageSubRectangle.width(), sourceImageSubRectangle.height(), depth, params, &packedSize, nullptr, nullptr) != GraphicsContextGL::NO_ERROR)
     850        return false;
     851    data.resize(packedSize);
     852
     853    if (!packPixels(imageData->data()->data(), sourceDataFormat, width, height, sourceImageSubRectangle, depth, 0, unpackImageHeight, format, type, premultiplyAlpha ? AlphaOp::DoPremultiply : AlphaOp::DoNothing, data.data(), flipY))
     854        return false;
     855
     856    return true;
     857}
     858
     859bool GraphicsContextGL::extractTextureData(unsigned width, unsigned height, GCGLenum format, GCGLenum type, const PixelStoreParams& unpackParams, bool flipY, bool premultiplyAlpha, const void* pixels, Vector<uint8_t>& data)
     860{
     861    // Assumes format, type, etc. have already been validated.
     862    DataFormat sourceDataFormat = getDataFormat(format, type);
     863
     864    // Resize the output buffer.
     865    unsigned componentsPerPixel, bytesPerComponent;
     866    if (!computeFormatAndTypeParameters(format, type, &componentsPerPixel, &bytesPerComponent))
     867        return false;
     868    unsigned bytesPerPixel = componentsPerPixel * bytesPerComponent;
     869    data.resize(width * height * bytesPerPixel);
     870
     871    unsigned imageSizeInBytes, skipSizeInBytes;
     872    computeImageSizeInBytes(format, type, width, height, 1, unpackParams, &imageSizeInBytes, nullptr, &skipSizeInBytes);
     873    const uint8_t* srcData = static_cast<const uint8_t*>(pixels);
     874    if (skipSizeInBytes)
     875        srcData += skipSizeInBytes;
     876
     877    if (!packPixels(srcData, sourceDataFormat, unpackParams.rowLength ? unpackParams.rowLength : width, height, IntRect(0, 0, width, height), 1, unpackParams.alignment, 0, format, type, (premultiplyAlpha ? AlphaOp::DoPremultiply : AlphaOp::DoNothing), data.data(), flipY))
     878        return false;
     879
     880    return true;
     881}
     882
    187883} // namespace WebCore
    188884
  • trunk/Source/WebCore/platform/graphics/GraphicsContextGL.h

    r268198 r268578  
    3434#include "IntSize.h"
    3535#include "PlatformLayer.h"
     36#include <wtf/HashSet.h>
    3637#include <wtf/RefCounted.h>
    3738#include <wtf/text/WTFString.h>
     
    889890    }
    890891
     892    class Client {
     893    public:
     894        virtual ~Client() { }
     895        virtual void didComposite() = 0;
     896        virtual void forceContextLost() = 0;
     897        virtual void recycleContext() = 0;
     898        virtual void dispatchContextChangedNotification() = 0;
     899    };
     900
    891901    struct ActiveInfo {
    892902        String name;
     
    897907    GraphicsContextGL(GraphicsContextGLAttributes, Destination = Destination::Offscreen, GraphicsContextGL* sharedContext = nullptr);
    898908    virtual ~GraphicsContextGL() = default;
     909
     910    void addClient(Client& client) { m_clients.add(&client); }
     911    void removeClient(Client& client) { m_clients.remove(&client); }
    899912
    900913    // ========== WebGL 1 entry points.
     
    12541267    // ========== Non-WebGL based entry points.
    12551268
     1269    virtual void setContextVisibility(bool) = 0;
     1270
     1271    virtual GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const = 0;
     1272
     1273    virtual bool isGLES2Compliant() const = 0;
     1274
     1275    // Synthesizes an OpenGL error which will be returned from a
     1276    // later call to getError. This is used to emulate OpenGL ES
     1277    // 2.0 behavior on the desktop and to enforce additional error
     1278    // checking mandated by WebGL.
     1279    //
     1280    // Per the behavior of glGetError, this stores at most one
     1281    // instance of any given error, and returns them from calls to
     1282    // getError in the order they were added.
     1283    virtual void synthesizeGLError(GCGLenum error) = 0;
     1284
     1285    virtual void setFailNextGPUStatusCheck() = 0;
     1286
     1287    virtual void prepareForDisplay() = 0;
     1288
     1289#if !USE(ANGLE)
     1290    // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
     1291    // Return true if no GL error is synthesized.
     1292    // By default, alignment is 4, the OpenGL default setting.
     1293    virtual bool texImage2DResourceSafe(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLint alignment = 4) =  0;
     1294#endif
     1295
     1296    IntSize getInternalFramebufferSize() const { return IntSize(m_currentWidth, m_currentHeight); }
     1297
    12561298    static unsigned getClearBitsByAttachmentType(GCGLenum);
    12571299    static unsigned getClearBitsByFormat(GCGLenum);
     
    12591301    static uint8_t getChannelBitsByFormat(GCGLenum);
    12601302
     1303    struct PixelStoreParams final {
     1304        GCGLint alignment { 4 };
     1305        GCGLint rowLength { 0 };
     1306        GCGLint imageHeight { 0 };
     1307        GCGLint skipPixels { 0 };
     1308        GCGLint skipRows { 0 };
     1309        GCGLint skipImages { 0 };
     1310    };
     1311
     1312    // Computes the components per pixel and bytes per component
     1313    // for the given format and type combination. Returns false if
     1314    // either was an invalid enum.
     1315    static bool computeFormatAndTypeParameters(GCGLenum format, GCGLenum type, unsigned* componentsPerPixel, unsigned* bytesPerComponent);
     1316
     1317    // Computes the image size in bytes. If paddingInBytes is not null, padding
     1318    // is also calculated in return. Returns NO_ERROR if succeed, otherwise
     1319    // return the suggested GL error indicating the cause of the failure:
     1320    //   INVALID_VALUE if width/height is negative or overflow happens.
     1321    //   INVALID_ENUM if format/type is illegal.
     1322    static GCGLenum computeImageSizeInBytes(GCGLenum format, GCGLenum type, GCGLsizei width, GCGLsizei height, GCGLsizei depth, const PixelStoreParams&, unsigned* imageSizeInBytes, unsigned* paddingInBytes, unsigned* skipSizeInBytes);
     1323
     1324#if !USE(ANGLE)
     1325    static bool possibleFormatAndTypeForInternalFormat(GCGLenum internalFormat, GCGLenum& format, GCGLenum& type);
     1326#endif // !USE(ANGLE)
     1327
     1328    // Extracts the contents of the given ImageData into the passed Vector,
     1329    // packing the pixel data according to the given format and type,
     1330    // and obeying the flipY and premultiplyAlpha flags. Returns true
     1331    // upon success.
     1332    static bool extractImageData(ImageData*, DataFormat, const IntRect& sourceImageSubRectangle, int depth, int unpackImageHeight, GCGLenum format, GCGLenum type, bool flipY, bool premultiplyAlpha, Vector<uint8_t>& data);
     1333
     1334    // Helper function which extracts the user-supplied texture
     1335    // data, applying the flipY and premultiplyAlpha parameters.
     1336    // If the data is not tightly packed according to the passed
     1337    // unpackParams, the output data will be tightly packed.
     1338    // Returns true if successful, false if any error occurred.
     1339    static bool extractTextureData(unsigned width, unsigned height, GCGLenum format, GCGLenum type, const PixelStoreParams& unpackParams, bool flipY, bool premultiplyAlpha, const void* pixels, Vector<uint8_t>& data);
     1340
     1341    // Packs the contents of the given Image which is passed in |pixels| into the passed Vector
     1342    // according to the given format and type, and obeying the flipY and AlphaOp flags.
     1343    // Returns true upon success.
     1344    static bool packImageData(Image*, const void* pixels, GCGLenum format, GCGLenum type, bool flipY, AlphaOp, DataFormat sourceFormat, unsigned sourceImageWidth, unsigned sourceImageHeight, const IntRect& sourceImageSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, Vector<uint8_t>& data);
     1345
    12611346    Destination destination() const { return m_destination; }
     1347
     1348protected:
     1349    int m_currentWidth { 0 };
     1350    int m_currentHeight { 0 };
     1351    HashSet<Client*> m_clients;
    12621352
    12631353private:
  • trunk/Source/WebCore/platform/graphics/GraphicsContextGLImageExtractor.cpp

    r268577 r268578  
    11/*
    2  * Copyright (C) 2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    2626#include "config.h"
    27 #include "GraphicsContextGLOpenGL.h"
     27#include "GraphicsContextGLImageExtractor.h"
    2828
    29 #if ENABLE(GRAPHICS_CONTEXT_GL) && USE(DIRECT2D)
    30 
    31 #include "COMPtr.h"
    32 #include "NotImplemented.h"
    33 #include <d2d1.h>
    34 #include <d2d1effects.h>
     29#if ENABLE(GRAPHICS_CONTEXT_GL)
    3530
    3631namespace WebCore {
    3732
    38 GraphicsContextGLOpenGL::ImageExtractor::~ImageExtractor() = default;
    39 
    40 bool GraphicsContextGLOpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)
     33GraphicsContextGLImageExtractor::GraphicsContextGLImageExtractor(Image* image, DOMSource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)
    4134{
    42     if (!m_image)
    43         return false;
    44 
    45     notImplemented();
    46 
    47     return true;
     35    m_image = image;
     36    m_imageHtmlDomSource = imageHtmlDomSource;
     37    m_extractSucceeded = extractImage(premultiplyAlpha, ignoreGammaAndColorProfile, ignoreNativeImageAlphaPremultiplication);
    4838}
    4939
    50 void GraphicsContextGLOpenGL::paintToCanvas(const unsigned char* imagePixels, const IntSize& imageSize, const IntSize& canvasSize, GraphicsContext& context)
    51 {
    52     if (!imagePixels || imageSize.isEmpty() || canvasSize.isEmpty())
    53         return;
    54 
    55     notImplemented();
    5640}
    5741
    58 } // namespace WebCore
    59 
    60 #endif // ENABLE(GRAPHICS_CONTEXT_GL) && USE(DIRECT2D)
     42#endif
  • trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp

    r268386 r268578  
    708708}
    709709
    710 IntSize GraphicsContextGLOpenGL::getInternalFramebufferSize() const
    711 {
    712     return IntSize(m_currentWidth, m_currentHeight);
    713 }
    714 
    715710void GraphicsContextGLOpenGL::activeTexture(GCGLenum texture)
    716711{
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextGLCairo.cpp

    r265360 r268578  
    3232
    3333#include "CairoUtilities.h"
     34#include "GraphicsContextGLImageExtractor.h"
    3435#include "Image.h"
    3536#include "ImageSource.h"
     
    4041namespace WebCore {
    4142
    42 GraphicsContextGLOpenGL::ImageExtractor::~ImageExtractor() = default;
     43GraphicsContextGLImageExtractor::~GraphicsContextGLImageExtractor() = default;
    4344
    44 bool GraphicsContextGLOpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool)
     45bool GraphicsContextGLImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool)
    4546{
    4647    if (!m_image)
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp

    r265360 r268578  
    3131#include "BitmapImage.h"
    3232#include "GraphicsContextCG.h"
     33#include "GraphicsContextGLImageExtractor.h"
    3334#include "GraphicsContextGLOpenGL.h"
    3435#include "Image.h"
     
    318319}
    319320
    320 GraphicsContextGLOpenGL::ImageExtractor::~ImageExtractor() = default;
    321 
    322 bool GraphicsContextGLOpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)
     321GraphicsContextGLImageExtractor::~GraphicsContextGLImageExtractor() = default;
     322
     323bool GraphicsContextGLImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)
    323324{
    324325    if (!m_image)
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp

    r268198 r268578  
    3232
    3333#include "ExtensionsGL.h"
    34 #include "FormatConverter.h"
    35 #include "Image.h"
    36 #include "ImageData.h"
    37 #include "ImageObserver.h"
    3834#include <wtf/UniqueArray.h>
    3935
    4036namespace WebCore {
    41 
    42 namespace {
    43 
    44 GraphicsContextGL::DataFormat getDataFormat(GCGLenum destinationFormat, GCGLenum destinationType)
    45 {
    46     GraphicsContextGL::DataFormat dstFormat = GraphicsContextGL::DataFormat::RGBA8;
    47     switch (destinationType) {
    48     case GraphicsContextGL::BYTE:
    49         switch (destinationFormat) {
    50         case GraphicsContextGL::RED:
    51         case GraphicsContextGL::RED_INTEGER:
    52             dstFormat = GraphicsContextGL::DataFormat::R8_S;
    53             break;
    54         case GraphicsContextGL::RG:
    55         case GraphicsContextGL::RG_INTEGER:
    56             dstFormat = GraphicsContextGL::DataFormat::RG8_S;
    57             break;
    58         case GraphicsContextGL::RGB:
    59         case GraphicsContextGL::RGB_INTEGER:
    60             dstFormat = GraphicsContextGL::DataFormat::RGB8_S;
    61             break;
    62         case GraphicsContextGL::RGBA:
    63         case GraphicsContextGL::RGBA_INTEGER:
    64             dstFormat = GraphicsContextGL::DataFormat::RGBA8_S;
    65             break;
    66         default:
    67             ASSERT_NOT_REACHED();
    68         }
    69         break;
    70     case GraphicsContextGL::UNSIGNED_BYTE:
    71         switch (destinationFormat) {
    72         case GraphicsContextGL::RGB:
    73         case GraphicsContextGL::RGB_INTEGER:
    74         case GraphicsContextGL::SRGB:
    75             dstFormat = GraphicsContextGL::GraphicsContextGL::DataFormat::RGB8;
    76             break;
    77         case GraphicsContextGL::RGBA:
    78         case GraphicsContextGL::RGBA_INTEGER:
    79         case GraphicsContextGL::SRGB_ALPHA:
    80             dstFormat = GraphicsContextGL::DataFormat::RGBA8;
    81             break;
    82         case GraphicsContextGL::ALPHA:
    83             dstFormat = GraphicsContextGL::DataFormat::A8;
    84             break;
    85         case GraphicsContextGL::LUMINANCE:
    86         case GraphicsContextGL::RED:
    87         case GraphicsContextGL::RED_INTEGER:
    88             dstFormat = GraphicsContextGL::DataFormat::R8;
    89             break;
    90         case GraphicsContextGL::RG:
    91         case GraphicsContextGL::RG_INTEGER:
    92             dstFormat = GraphicsContextGL::DataFormat::RG8;
    93             break;
    94         case GraphicsContextGL::LUMINANCE_ALPHA:
    95             dstFormat = GraphicsContextGL::DataFormat::RA8;
    96             break;
    97         default:
    98             ASSERT_NOT_REACHED();
    99         }
    100         break;
    101     case GraphicsContextGL::SHORT:
    102         switch (destinationFormat) {
    103         case GraphicsContextGL::RED_INTEGER:
    104             dstFormat = GraphicsContextGL::DataFormat::R16_S;
    105             break;
    106         case GraphicsContextGL::RG_INTEGER:
    107             dstFormat = GraphicsContextGL::DataFormat::RG16_S;
    108             break;
    109         case GraphicsContextGL::RGB_INTEGER:
    110             dstFormat = GraphicsContextGL::DataFormat::RGB16_S;
    111             break;
    112         case GraphicsContextGL::RGBA_INTEGER:
    113             dstFormat = GraphicsContextGL::DataFormat::RGBA16_S;
    114             break;
    115         default:
    116             ASSERT_NOT_REACHED();
    117         }
    118         break;
    119     case GraphicsContextGL::UNSIGNED_SHORT:
    120         switch (destinationFormat) {
    121         case GraphicsContextGL::RED_INTEGER:
    122             dstFormat = GraphicsContextGL::DataFormat::R16;
    123             break;
    124         case GraphicsContextGL::DEPTH_COMPONENT:
    125             dstFormat = GraphicsContextGL::DataFormat::D16;
    126             break;
    127         case GraphicsContextGL::RG_INTEGER:
    128             dstFormat = GraphicsContextGL::DataFormat::RG16;
    129             break;
    130         case GraphicsContextGL::RGB_INTEGER:
    131             dstFormat = GraphicsContextGL::DataFormat::RGB16;
    132             break;
    133         case GraphicsContextGL::RGBA_INTEGER:
    134             dstFormat = GraphicsContextGL::DataFormat::RGBA16;
    135             break;
    136         default:
    137             ASSERT_NOT_REACHED();
    138         }
    139         break;
    140     case GraphicsContextGL::INT:
    141         switch (destinationFormat) {
    142         case GraphicsContextGL::RED_INTEGER:
    143             dstFormat = GraphicsContextGL::DataFormat::R32_S;
    144             break;
    145         case GraphicsContextGL::RG_INTEGER:
    146             dstFormat = GraphicsContextGL::DataFormat::RG32_S;
    147             break;
    148         case GraphicsContextGL::RGB_INTEGER:
    149             dstFormat = GraphicsContextGL::DataFormat::RGB32_S;
    150             break;
    151         case GraphicsContextGL::RGBA_INTEGER:
    152             dstFormat = GraphicsContextGL::DataFormat::RGBA32_S;
    153             break;
    154         default:
    155             ASSERT_NOT_REACHED();
    156         }
    157         break;
    158     case GraphicsContextGL::UNSIGNED_INT:
    159         switch (destinationFormat) {
    160         case GraphicsContextGL::RED_INTEGER:
    161             dstFormat = GraphicsContextGL::DataFormat::R32;
    162             break;
    163         case GraphicsContextGL::DEPTH_COMPONENT:
    164             dstFormat = GraphicsContextGL::DataFormat::D32;
    165             break;
    166         case GraphicsContextGL::RG_INTEGER:
    167             dstFormat = GraphicsContextGL::DataFormat::RG32;
    168             break;
    169         case GraphicsContextGL::RGB_INTEGER:
    170             dstFormat = GraphicsContextGL::DataFormat::RGB32;
    171             break;
    172         case GraphicsContextGL::RGBA_INTEGER:
    173             dstFormat = GraphicsContextGL::DataFormat::RGBA32;
    174             break;
    175         default:
    176             ASSERT_NOT_REACHED();
    177         }
    178         break;
    179     case GraphicsContextGL::HALF_FLOAT_OES: // OES_texture_half_float
    180     case GraphicsContextGL::HALF_FLOAT:
    181         switch (destinationFormat) {
    182         case GraphicsContextGL::RGBA:
    183             dstFormat = GraphicsContextGL::DataFormat::RGBA16F;
    184             break;
    185         case GraphicsContextGL::RGB:
    186             dstFormat = GraphicsContextGL::DataFormat::RGB16F;
    187             break;
    188         case GraphicsContextGL::RG:
    189             dstFormat = GraphicsContextGL::DataFormat::RG16F;
    190             break;
    191         case GraphicsContextGL::ALPHA:
    192             dstFormat = GraphicsContextGL::DataFormat::A16F;
    193             break;
    194         case GraphicsContextGL::LUMINANCE:
    195         case GraphicsContextGL::RED:
    196             dstFormat = GraphicsContextGL::DataFormat::R16F;
    197             break;
    198         case GraphicsContextGL::LUMINANCE_ALPHA:
    199             dstFormat = GraphicsContextGL::DataFormat::RA16F;
    200             break;
    201         case GraphicsContextGL::SRGB:
    202             dstFormat = GraphicsContextGL::DataFormat::RGB16F;
    203             break;
    204         case GraphicsContextGL::SRGB_ALPHA:
    205             dstFormat = GraphicsContextGL::DataFormat::RGBA16F;
    206             break;
    207         default:
    208             ASSERT_NOT_REACHED();
    209         }
    210         break;
    211     case GraphicsContextGL::FLOAT: // OES_texture_float
    212         switch (destinationFormat) {
    213         case GraphicsContextGL::RGBA:
    214             dstFormat = GraphicsContextGL::DataFormat::RGBA32F;
    215             break;
    216         case GraphicsContextGL::RGB:
    217             dstFormat = GraphicsContextGL::DataFormat::RGB32F;
    218             break;
    219         case GraphicsContextGL::RG:
    220             dstFormat = GraphicsContextGL::DataFormat::RG32F;
    221             break;
    222         case GraphicsContextGL::ALPHA:
    223             dstFormat = GraphicsContextGL::DataFormat::A32F;
    224             break;
    225         case GraphicsContextGL::LUMINANCE:
    226         case GraphicsContextGL::RED:
    227             dstFormat = GraphicsContextGL::DataFormat::R32F;
    228             break;
    229         case GraphicsContextGL::DEPTH_COMPONENT:
    230             dstFormat = GraphicsContextGL::DataFormat::D32F;
    231             break;
    232         case GraphicsContextGL::LUMINANCE_ALPHA:
    233             dstFormat = GraphicsContextGL::DataFormat::RA32F;
    234             break;
    235         case GraphicsContextGL::SRGB:
    236             dstFormat = GraphicsContextGL::DataFormat::RGB32F;
    237             break;
    238         case GraphicsContextGL::SRGB_ALPHA:
    239             dstFormat = GraphicsContextGL::DataFormat::RGBA32F;
    240             break;
    241         default:
    242             ASSERT_NOT_REACHED();
    243         }
    244         break;
    245     case GraphicsContextGL::UNSIGNED_SHORT_4_4_4_4:
    246         dstFormat = GraphicsContextGL::DataFormat::RGBA4444;
    247         break;
    248     case GraphicsContextGL::UNSIGNED_SHORT_5_5_5_1:
    249         dstFormat = GraphicsContextGL::DataFormat::RGBA5551;
    250         break;
    251     case GraphicsContextGL::UNSIGNED_SHORT_5_6_5:
    252         dstFormat = GraphicsContextGL::DataFormat::RGB565;
    253         break;
    254     case GraphicsContextGL::UNSIGNED_INT_5_9_9_9_REV:
    255         dstFormat = GraphicsContextGL::DataFormat::RGB5999;
    256         break;
    257     case GraphicsContextGL::UNSIGNED_INT_24_8:
    258         dstFormat = GraphicsContextGL::DataFormat::DS24_8;
    259         break;
    260     case GraphicsContextGL::UNSIGNED_INT_10F_11F_11F_REV:
    261         dstFormat = GraphicsContextGL::DataFormat::RGB10F11F11F;
    262         break;
    263     case GraphicsContextGL::UNSIGNED_INT_2_10_10_10_REV:
    264         dstFormat = GraphicsContextGL::DataFormat::RGBA2_10_10_10;
    265         break;
    266     default:
    267         ASSERT_NOT_REACHED();
    268     }
    269     return dstFormat;
    270 }
    271 
    272 } // anonymous namespace
    27337
    27438void GraphicsContextGLOpenGL::resetBuffersToAutoClear()
     
    30872}
    30973
     74#if !USE(ANGLE)
    31075bool GraphicsContextGLOpenGL::texImage2DResourceSafe(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLint unpackAlignment)
    31176{
     
    31479    if (width > 0 && height > 0) {
    31580        unsigned size;
    316         GraphicsContextGLOpenGL::PixelStoreParams params;
     81        PixelStoreParams params;
    31782        params.alignment = unpackAlignment;
    31883        GCGLenum error = computeImageSizeInBytes(format, type, width, height, 1, params, &size, nullptr, nullptr);
     
    33095    return texImage2D(target, level, internalformat, width, height, border, format, type, zero.get());
    33196}
     97#endif
    33298
    333 bool GraphicsContextGLOpenGL::computeFormatAndTypeParameters(GCGLenum format, GCGLenum type, unsigned* componentsPerPixel, unsigned* bytesPerComponent)
    334 {
    335     switch (format) {
    336     case GraphicsContextGL::ALPHA:
    337     case GraphicsContextGL::LUMINANCE:
    338     case GraphicsContextGL::RED:
    339     case GraphicsContextGL::RED_INTEGER:
    340     case GraphicsContextGL::DEPTH_COMPONENT:
    341     case GraphicsContextGL::DEPTH_STENCIL: // Treat it as one component.
    342         *componentsPerPixel = 1;
    343         break;
    344     case GraphicsContextGL::LUMINANCE_ALPHA:
    345     case GraphicsContextGL::RG:
    346     case GraphicsContextGL::RG_INTEGER:
    347         *componentsPerPixel = 2;
    348         break;
    349     case GraphicsContextGL::RGB:
    350     case GraphicsContextGL::RGB_INTEGER:
    351     case ExtensionsGL::SRGB_EXT:
    352         *componentsPerPixel = 3;
    353         break;
    354     case GraphicsContextGL::RGBA:
    355     case GraphicsContextGL::RGBA_INTEGER:
    356     case ExtensionsGL::BGRA_EXT: // GL_EXT_texture_format_BGRA8888
    357     case ExtensionsGL::SRGB_ALPHA_EXT:
    358         *componentsPerPixel = 4;
    359         break;
    360     default:
    361         return false;
    362     }
    363 
    364     switch (type) {
    365     case GraphicsContextGL::BYTE:
    366         *bytesPerComponent = sizeof(GCGLbyte);
    367         break;
    368     case GraphicsContextGL::UNSIGNED_BYTE:
    369         *bytesPerComponent = sizeof(GCGLubyte);
    370         break;
    371     case GraphicsContextGL::SHORT:
    372         *bytesPerComponent = sizeof(GCGLshort);
    373         break;
    374     case GraphicsContextGL::UNSIGNED_SHORT:
    375         *bytesPerComponent = sizeof(GCGLushort);
    376         break;
    377     case GraphicsContextGL::UNSIGNED_SHORT_5_6_5:
    378     case GraphicsContextGL::UNSIGNED_SHORT_4_4_4_4:
    379     case GraphicsContextGL::UNSIGNED_SHORT_5_5_5_1:
    380         *componentsPerPixel = 1;
    381         *bytesPerComponent = sizeof(GCGLushort);
    382         break;
    383     case GraphicsContextGL::INT:
    384         *bytesPerComponent = sizeof(GCGLint);
    385         break;
    386     case GraphicsContextGL::UNSIGNED_INT:
    387         *bytesPerComponent = sizeof(GCGLuint);
    388         break;
    389     case GraphicsContextGL::UNSIGNED_INT_24_8:
    390     case GraphicsContextGL::UNSIGNED_INT_10F_11F_11F_REV:
    391     case GraphicsContextGL::UNSIGNED_INT_5_9_9_9_REV:
    392     case GraphicsContextGL::UNSIGNED_INT_2_10_10_10_REV:
    393         *componentsPerPixel = 1;
    394         *bytesPerComponent = sizeof(GCGLuint);
    395         break;
    396     case GraphicsContextGL::FLOAT: // OES_texture_float
    397         *bytesPerComponent = sizeof(GCGLfloat);
    398         break;
    399     case GraphicsContextGL::HALF_FLOAT:
    400     case GraphicsContextGL::HALF_FLOAT_OES: // OES_texture_half_float
    401         *bytesPerComponent = sizeof(GCGLhalffloat);
    402         break;
    403     case GraphicsContextGL::FLOAT_32_UNSIGNED_INT_24_8_REV:
    404         *bytesPerComponent = sizeof(GCGLfloat) + sizeof(GCGLuint);
    405         break;
    406     default:
    407         return false;
    408     }
    409     return true;
    410 }
    411 
    412 #if !USE(ANGLE)
    413 bool GraphicsContextGLOpenGL::possibleFormatAndTypeForInternalFormat(GCGLenum internalFormat, GCGLenum& format, GCGLenum& type)
    414 {
    415 #define POSSIBLE_FORMAT_TYPE_CASE(internalFormatMacro, formatMacro, typeMacro) case internalFormatMacro: \
    416         format = formatMacro; \
    417         type = GraphicsContextGLOpenGL::typeMacro; \
    418         break;
    419 
    420     switch (internalFormat) {
    421     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB               , GraphicsContextGL::RGB            , UNSIGNED_BYTE                 );
    422     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA              , GraphicsContextGL::RGBA           , UNSIGNED_BYTE                 );
    423     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::LUMINANCE_ALPHA   , GraphicsContextGL::LUMINANCE_ALPHA, UNSIGNED_BYTE                 );
    424     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::LUMINANCE         , GraphicsContextGL::LUMINANCE      , UNSIGNED_BYTE                 );
    425     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::ALPHA             , GraphicsContextGL::ALPHA          , UNSIGNED_BYTE                 );
    426     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R8                , GraphicsContextGL::RED            , UNSIGNED_BYTE                 );
    427     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R8_SNORM          , GraphicsContextGL::RED            , BYTE                          );
    428     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R16F              , GraphicsContextGL::RED            , HALF_FLOAT                    );
    429     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R32F              , GraphicsContextGL::RED            , FLOAT                         );
    430     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R8UI              , GraphicsContextGL::RED_INTEGER    , UNSIGNED_BYTE                 );
    431     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R8I               , GraphicsContextGL::RED_INTEGER    , BYTE                          );
    432     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R16UI             , GraphicsContextGL::RED_INTEGER    , UNSIGNED_SHORT                );
    433     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R16I              , GraphicsContextGL::RED_INTEGER    , SHORT                         );
    434     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R32UI             , GraphicsContextGL::RED_INTEGER    , UNSIGNED_INT                  );
    435     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R32I              , GraphicsContextGL::RED_INTEGER    , INT                           );
    436     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG8               , GraphicsContextGL::RG             , UNSIGNED_BYTE                 );
    437     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG8_SNORM         , GraphicsContextGL::RG             , BYTE                          );
    438     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG16F             , GraphicsContextGL::RG             , HALF_FLOAT                    );
    439     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG32F             , GraphicsContextGL::RG             , FLOAT                         );
    440     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG8UI             , GraphicsContextGL::RG_INTEGER     , UNSIGNED_BYTE                 );
    441     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG8I              , GraphicsContextGL::RG_INTEGER     , BYTE                          );
    442     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG16UI            , GraphicsContextGL::RG_INTEGER     , UNSIGNED_SHORT                );
    443     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG16I             , GraphicsContextGL::RG_INTEGER     , SHORT                         );
    444     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG32UI            , GraphicsContextGL::RG_INTEGER     , UNSIGNED_INT                  );
    445     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG32I             , GraphicsContextGL::RG_INTEGER     , INT                           );
    446     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB8              , GraphicsContextGL::RGB            , UNSIGNED_BYTE                 );
    447     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::SRGB8             , GraphicsContextGL::RGB            , UNSIGNED_BYTE                 );
    448     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB565            , GraphicsContextGL::RGB            , UNSIGNED_SHORT_5_6_5          );
    449     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB8_SNORM        , GraphicsContextGL::RGB            , BYTE                          );
    450     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R11F_G11F_B10F    , GraphicsContextGL::RGB            , UNSIGNED_INT_10F_11F_11F_REV  );
    451     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB9_E5           , GraphicsContextGL::RGB            , UNSIGNED_INT_5_9_9_9_REV      );
    452     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB16F            , GraphicsContextGL::RGB            , HALF_FLOAT                    );
    453     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB32F            , GraphicsContextGL::RGB            , FLOAT                         );
    454     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB8UI            , GraphicsContextGL::RGB_INTEGER    , UNSIGNED_BYTE                 );
    455     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB8I             , GraphicsContextGL::RGB_INTEGER    , BYTE                          );
    456     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB16UI           , GraphicsContextGL::RGB_INTEGER    , UNSIGNED_SHORT                );
    457     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB16I            , GraphicsContextGL::RGB_INTEGER    , SHORT                         );
    458     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB32UI           , GraphicsContextGL::RGB_INTEGER    , UNSIGNED_INT                  );
    459     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB32I            , GraphicsContextGL::RGB_INTEGER    , INT                           );
    460     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA8             , GraphicsContextGL::RGBA           , UNSIGNED_BYTE                 );
    461     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::SRGB8_ALPHA8      , GraphicsContextGL::RGBA           , UNSIGNED_BYTE                 );
    462     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA8_SNORM       , GraphicsContextGL::RGBA           , BYTE                          );
    463     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB5_A1           , GraphicsContextGL::RGBA           , UNSIGNED_SHORT_5_5_5_1        );
    464     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA4             , GraphicsContextGL::RGBA           , UNSIGNED_SHORT_4_4_4_4        );
    465     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB10_A2          , GraphicsContextGL::RGBA           , UNSIGNED_INT_2_10_10_10_REV   );
    466     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA16F           , GraphicsContextGL::RGBA           , HALF_FLOAT                    );
    467     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA32F           , GraphicsContextGL::RGBA           , FLOAT                         );
    468     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA8UI           , GraphicsContextGL::RGBA_INTEGER   , UNSIGNED_BYTE                 );
    469     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA8I            , GraphicsContextGL::RGBA_INTEGER   , BYTE                          );
    470     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB10_A2UI        , GraphicsContextGL::RGBA_INTEGER   , UNSIGNED_INT_2_10_10_10_REV   );
    471     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA16UI          , GraphicsContextGL::RGBA_INTEGER   , UNSIGNED_SHORT                );
    472     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA16I           , GraphicsContextGL::RGBA_INTEGER   , SHORT                         );
    473     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA32I           , GraphicsContextGL::RGBA_INTEGER   , INT                           );
    474     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA32UI          , GraphicsContextGL::RGBA_INTEGER   , UNSIGNED_INT                  );
    475     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_COMPONENT16 , GraphicsContextGL::DEPTH_COMPONENT, UNSIGNED_SHORT                );
    476     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_COMPONENT   , GraphicsContextGL::DEPTH_COMPONENT, UNSIGNED_SHORT                );
    477     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_COMPONENT24 , GraphicsContextGL::DEPTH_COMPONENT, UNSIGNED_INT                  );
    478     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_COMPONENT32F, GraphicsContextGL::DEPTH_COMPONENT, FLOAT                         );
    479     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_STENCIL     , GraphicsContextGL::DEPTH_STENCIL  , UNSIGNED_INT_24_8             );
    480     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH24_STENCIL8  , GraphicsContextGL::DEPTH_STENCIL  , UNSIGNED_INT_24_8             );
    481     POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH32F_STENCIL8 , GraphicsContextGL::DEPTH_STENCIL  , FLOAT_32_UNSIGNED_INT_24_8_REV);
    482     POSSIBLE_FORMAT_TYPE_CASE(ExtensionsGL::SRGB_EXT               , ExtensionsGL::SRGB_EXT            , UNSIGNED_BYTE                 );
    483     POSSIBLE_FORMAT_TYPE_CASE(ExtensionsGL::SRGB_ALPHA_EXT         , ExtensionsGL::SRGB_ALPHA_EXT      , UNSIGNED_BYTE                 );
    484     default:
    485         return false;
    486     }
    487 #undef POSSIBLE_FORMAT_TYPE_CASE
    488 
    489     return true;
    490 }
    491 #endif // !USE(ANGLE)
    492 
    493 GCGLenum GraphicsContextGLOpenGL::computeImageSizeInBytes(
    494     GCGLenum format, GCGLenum type, GCGLsizei width, GCGLsizei height, GCGLsizei depth, const GraphicsContextGLOpenGL::PixelStoreParams& params,
    495     unsigned* imageSizeInBytes, unsigned* paddingInBytes, unsigned* skipSizeInBytes)
    496 {
    497     ASSERT(imageSizeInBytes);
    498     ASSERT(params.alignment == 1 || params.alignment == 2 || params.alignment == 4 || params.alignment == 8);
    499     ASSERT(params.rowLength >= 0);
    500     ASSERT(params.imageHeight >= 0);
    501     ASSERT(params.skipPixels >= 0);
    502     ASSERT(params.skipRows >= 0);
    503     ASSERT(params.skipImages >= 0);
    504     if (width < 0 || height < 0 || depth < 0)
    505         return GraphicsContextGL::INVALID_VALUE;
    506     if (!width || !height || !depth) {
    507         *imageSizeInBytes = 0;
    508         if (paddingInBytes)
    509             *paddingInBytes = 0;
    510         if (skipSizeInBytes)
    511             *skipSizeInBytes = 0;
    512         return GraphicsContextGL::NO_ERROR;
    513     }
    514 
    515     int rowLength = params.rowLength > 0 ? params.rowLength : width;
    516     int imageHeight = params.imageHeight > 0 ? params.imageHeight : height;
    517 
    518     unsigned bytesPerComponent, componentsPerPixel;
    519     if (!computeFormatAndTypeParameters(format, type, &componentsPerPixel, &bytesPerComponent))
    520         return GraphicsContextGL::INVALID_ENUM;
    521     unsigned bytesPerGroup = bytesPerComponent * componentsPerPixel;
    522     Checked<uint32_t, RecordOverflow> checkedValue = static_cast<uint32_t>(rowLength);
    523     checkedValue *= bytesPerGroup;
    524     if (checkedValue.hasOverflowed())
    525         return GraphicsContextGL::INVALID_VALUE;
    526 
    527     unsigned lastRowSize;
    528     if (params.rowLength > 0 && params.rowLength != width) {
    529         Checked<uint32_t, RecordOverflow> tmp = width;
    530         tmp *= bytesPerGroup;
    531         if (tmp.hasOverflowed())
    532             return GraphicsContextGL::INVALID_VALUE;
    533         lastRowSize = tmp.unsafeGet();
    534     } else
    535         lastRowSize = checkedValue.unsafeGet();
    536 
    537     unsigned padding = 0;
    538     unsigned residual = checkedValue.unsafeGet() % params.alignment;
    539     if (residual) {
    540         padding = params.alignment - residual;
    541         checkedValue += padding;
    542     }
    543     if (checkedValue.hasOverflowed())
    544         return GraphicsContextGL::INVALID_VALUE;
    545     unsigned paddedRowSize = checkedValue.unsafeGet();
    546 
    547     Checked<uint32_t, RecordOverflow> rows = imageHeight;
    548     rows *= (depth - 1);
    549     // Last image is not affected by IMAGE_HEIGHT parameter.
    550     rows += height;
    551     if (rows.hasOverflowed())
    552         return GraphicsContextGL::INVALID_VALUE;
    553     checkedValue *= (rows - 1);
    554     // Last row is not affected by ROW_LENGTH parameter.
    555     checkedValue += lastRowSize;
    556     if (checkedValue.hasOverflowed())
    557         return GraphicsContextGL::INVALID_VALUE;
    558     *imageSizeInBytes = checkedValue.unsafeGet();
    559     if (paddingInBytes)
    560         *paddingInBytes = padding;
    561 
    562     Checked<uint32_t, RecordOverflow> skipSize = 0;
    563     if (params.skipImages > 0) {
    564         Checked<uint32_t, RecordOverflow> tmp = paddedRowSize;
    565         tmp *= imageHeight;
    566         tmp *= params.skipImages;
    567         if (tmp.hasOverflowed())
    568             return GraphicsContextGL::INVALID_VALUE;
    569         skipSize += tmp.unsafeGet();
    570     }
    571     if (params.skipRows > 0) {
    572         Checked<uint32_t, RecordOverflow> tmp = paddedRowSize;
    573         tmp *= params.skipRows;
    574         if (tmp.hasOverflowed())
    575             return GraphicsContextGL::INVALID_VALUE;
    576         skipSize += tmp.unsafeGet();
    577     }
    578     if (params.skipPixels > 0) {
    579         Checked<uint32_t, RecordOverflow> tmp = bytesPerGroup;
    580         tmp *= params.skipPixels;
    581         if (tmp.hasOverflowed())
    582             return GraphicsContextGL::INVALID_VALUE;
    583         skipSize += tmp.unsafeGet();
    584     }
    585     if (skipSize.hasOverflowed())
    586         return GraphicsContextGL::INVALID_VALUE;
    587     if (skipSizeInBytes)
    588         *skipSizeInBytes = skipSize.unsafeGet();
    589 
    590     checkedValue += skipSize.unsafeGet();
    591     if (checkedValue.hasOverflowed())
    592         return GraphicsContextGL::INVALID_VALUE;
    593     return GraphicsContextGL::NO_ERROR;
    594 }
    595 
    596 GraphicsContextGLOpenGL::PixelStoreParams::PixelStoreParams()
    597     : alignment(4)
    598     , rowLength(0)
    599     , imageHeight(0)
    600     , skipPixels(0)
    601     , skipRows(0)
    602     , skipImages(0)
    603 {
    604 }
    605 
    606 GraphicsContextGLOpenGL::ImageExtractor::ImageExtractor(Image* image, DOMSource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)
    607 {
    608     m_image = image;
    609     m_imageHtmlDomSource = imageHtmlDomSource;
    610     m_extractSucceeded = extractImage(premultiplyAlpha, ignoreGammaAndColorProfile, ignoreNativeImageAlphaPremultiplication);
    611 }
    612 
    613 bool GraphicsContextGLOpenGL::packImageData(Image* image, const void* pixels, GCGLenum format, GCGLenum type, bool flipY, AlphaOp alphaOp, DataFormat sourceFormat, unsigned sourceImageWidth, unsigned sourceImageHeight, const IntRect& sourceImageSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, Vector<uint8_t>& data)
    614 {
    615     if (!image || !pixels)
    616         return false;
    617 
    618     unsigned packedSize;
    619     // Output data is tightly packed (alignment == 1).
    620     PixelStoreParams params;
    621     params.alignment = 1;
    622     if (computeImageSizeInBytes(format, type, sourceImageSubRectangle.width(), sourceImageSubRectangle.height(), depth, params, &packedSize, nullptr, nullptr) != GraphicsContextGL::NO_ERROR)
    623         return false;
    624     data.resize(packedSize);
    625 
    626     if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, sourceImageWidth, sourceImageHeight, sourceImageSubRectangle, depth, sourceUnpackAlignment, unpackImageHeight, format, type, alphaOp, data.data(), flipY))
    627         return false;
    628     if (ImageObserver* observer = image->imageObserver())
    629         observer->didDraw(*image);
    630     return true;
    631 }
    632 
    633 bool GraphicsContextGLOpenGL::extractImageData(
    634     ImageData* imageData, DataFormat sourceDataFormat, const IntRect& sourceImageSubRectangle,
    635     int depth, int unpackImageHeight, GCGLenum format, GCGLenum type, bool flipY, bool premultiplyAlpha, Vector<uint8_t>& data)
    636 {
    637     if (!imageData)
    638         return false;
    639     int width = imageData->width();
    640     int height = imageData->height();
    641 
    642     unsigned packedSize;
    643     // Output data is tightly packed (alignment == 1).
    644     PixelStoreParams params;
    645     params.alignment = 1;
    646     if (computeImageSizeInBytes(format, type, sourceImageSubRectangle.width(), sourceImageSubRectangle.height(), depth, params, &packedSize, nullptr, nullptr) != GraphicsContextGL::NO_ERROR)
    647         return false;
    648     data.resize(packedSize);
    649 
    650     if (!packPixels(imageData->data()->data(), sourceDataFormat, width, height, sourceImageSubRectangle, depth, 0, unpackImageHeight, format, type, premultiplyAlpha ? AlphaOp::DoPremultiply : AlphaOp::DoNothing, data.data(), flipY))
    651         return false;
    652 
    653     return true;
    654 }
    655 
    656 bool GraphicsContextGLOpenGL::extractTextureData(unsigned width, unsigned height, GCGLenum format, GCGLenum type, const PixelStoreParams& unpackParams, bool flipY, bool premultiplyAlpha, const void* pixels, Vector<uint8_t>& data)
    657 {
    658     // Assumes format, type, etc. have already been validated.
    659     DataFormat sourceDataFormat = getDataFormat(format, type);
    660 
    661     // Resize the output buffer.
    662     unsigned componentsPerPixel, bytesPerComponent;
    663     if (!computeFormatAndTypeParameters(format, type, &componentsPerPixel, &bytesPerComponent))
    664         return false;
    665     unsigned bytesPerPixel = componentsPerPixel * bytesPerComponent;
    666     data.resize(width * height * bytesPerPixel);
    667 
    668     unsigned imageSizeInBytes, skipSizeInBytes;
    669     computeImageSizeInBytes(format, type, width, height, 1, unpackParams, &imageSizeInBytes, nullptr, &skipSizeInBytes);
    670     const uint8_t* srcData = static_cast<const uint8_t*>(pixels);
    671     if (skipSizeInBytes)
    672         srcData += skipSizeInBytes;
    673 
    674     if (!packPixels(srcData, sourceDataFormat, unpackParams.rowLength ? unpackParams.rowLength : width, height, IntRect(0, 0, width, height), 1, unpackParams.alignment, 0, format, type, (premultiplyAlpha ? AlphaOp::DoPremultiply : AlphaOp::DoNothing), data.data(), flipY))
    675         return false;
    676 
    677     return true;
    678 }
    679 
    680 ALWAYS_INLINE unsigned TexelBytesForFormat(GraphicsContextGL::DataFormat format)
    681 {
    682     switch (format) {
    683     case GraphicsContextGL::DataFormat::R8:
    684     case GraphicsContextGL::DataFormat::R8_S:
    685     case GraphicsContextGL::DataFormat::A8:
    686         return 1;
    687     case GraphicsContextGL::DataFormat::RG8:
    688     case GraphicsContextGL::DataFormat::RG8_S:
    689     case GraphicsContextGL::DataFormat::RA8:
    690     case GraphicsContextGL::DataFormat::AR8:
    691     case GraphicsContextGL::DataFormat::RGBA5551:
    692     case GraphicsContextGL::DataFormat::RGBA4444:
    693     case GraphicsContextGL::DataFormat::RGB565:
    694     case GraphicsContextGL::DataFormat::A16F:
    695     case GraphicsContextGL::DataFormat::R16:
    696     case GraphicsContextGL::DataFormat::R16_S:
    697     case GraphicsContextGL::DataFormat::R16F:
    698     case GraphicsContextGL::DataFormat::D16:
    699         return 2;
    700     case GraphicsContextGL::DataFormat::RGB8:
    701     case GraphicsContextGL::DataFormat::RGB8_S:
    702     case GraphicsContextGL::DataFormat::BGR8:
    703         return 3;
    704     case GraphicsContextGL::DataFormat::RGBA8:
    705     case GraphicsContextGL::DataFormat::RGBA8_S:
    706     case GraphicsContextGL::DataFormat::ARGB8:
    707     case GraphicsContextGL::DataFormat::ABGR8:
    708     case GraphicsContextGL::DataFormat::BGRA8:
    709     case GraphicsContextGL::DataFormat::R32:
    710     case GraphicsContextGL::DataFormat::R32_S:
    711     case GraphicsContextGL::DataFormat::R32F:
    712     case GraphicsContextGL::DataFormat::A32F:
    713     case GraphicsContextGL::DataFormat::RA16F:
    714     case GraphicsContextGL::DataFormat::RGBA2_10_10_10:
    715     case GraphicsContextGL::DataFormat::RGB10F11F11F:
    716     case GraphicsContextGL::DataFormat::RGB5999:
    717     case GraphicsContextGL::DataFormat::RG16:
    718     case GraphicsContextGL::DataFormat::RG16_S:
    719     case GraphicsContextGL::DataFormat::RG16F:
    720     case GraphicsContextGL::DataFormat::D32:
    721     case GraphicsContextGL::DataFormat::D32F:
    722     case GraphicsContextGL::DataFormat::DS24_8:
    723         return 4;
    724     case GraphicsContextGL::DataFormat::RGB16:
    725     case GraphicsContextGL::DataFormat::RGB16_S:
    726     case GraphicsContextGL::DataFormat::RGB16F:
    727         return 6;
    728     case GraphicsContextGL::DataFormat::RGBA16:
    729     case GraphicsContextGL::DataFormat::RGBA16_S:
    730     case GraphicsContextGL::DataFormat::RA32F:
    731     case GraphicsContextGL::DataFormat::RGBA16F:
    732     case GraphicsContextGL::DataFormat::RG32:
    733     case GraphicsContextGL::DataFormat::RG32_S:
    734     case GraphicsContextGL::DataFormat::RG32F:
    735         return 8;
    736     case GraphicsContextGL::DataFormat::RGB32:
    737     case GraphicsContextGL::DataFormat::RGB32_S:
    738     case GraphicsContextGL::DataFormat::RGB32F:
    739         return 12;
    740     case GraphicsContextGL::DataFormat::RGBA32:
    741     case GraphicsContextGL::DataFormat::RGBA32_S:
    742     case GraphicsContextGL::DataFormat::RGBA32F:
    743         return 16;
    744     default:
    745         return 0;
    746     }
    747 }
    748 
    749 bool GraphicsContextGLOpenGL::packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned sourceDataWidth, unsigned sourceDataHeight, const IntRect& sourceDataSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, unsigned destinationFormat, unsigned destinationType, AlphaOp alphaOp, void* destinationData, bool flipY)
    750 {
    751     ASSERT(depth >= 1);
    752     UNUSED_PARAM(sourceDataHeight); // Derived from sourceDataSubRectangle.height().
    753     if (!unpackImageHeight)
    754         unpackImageHeight = sourceDataSubRectangle.height();
    755     int validSrc = sourceDataWidth * TexelBytesForFormat(sourceDataFormat);
    756     int remainder = sourceUnpackAlignment ? (validSrc % sourceUnpackAlignment) : 0;
    757     int srcStride = remainder ? (validSrc + sourceUnpackAlignment - remainder) : validSrc;
    758     int srcRowOffset = sourceDataSubRectangle.x() * TexelBytesForFormat(sourceDataFormat);
    759 
    760     DataFormat dstDataFormat = getDataFormat(destinationFormat, destinationType);
    761     int dstStride = sourceDataSubRectangle.width() * TexelBytesForFormat(dstDataFormat);
    762     if (flipY) {
    763         destinationData = static_cast<uint8_t*>(destinationData) + dstStride * ((depth * sourceDataSubRectangle.height()) - 1);
    764         dstStride = -dstStride;
    765     }
    766     if (!hasAlpha(sourceDataFormat) || !hasColor(sourceDataFormat) || !hasColor(dstDataFormat))
    767         alphaOp = AlphaOp::DoNothing;
    768 
    769     if (sourceDataFormat == dstDataFormat && alphaOp == AlphaOp::DoNothing) {
    770         const uint8_t* basePtr = sourceData + srcStride * sourceDataSubRectangle.y();
    771         const uint8_t* baseEnd = sourceData + srcStride * sourceDataSubRectangle.maxY();
    772 
    773         // If packing multiple images into a 3D texture, and flipY is true,
    774         // then the sub-rectangle is pointing at the start of the
    775         // "bottommost" of those images. Since the source pointer strides in
    776         // the positive direction, we need to back it up to point at the
    777         // last, or "topmost", of these images.
    778         if (flipY && depth > 1) {
    779             const ptrdiff_t distanceToTopImage = (depth - 1) * srcStride * unpackImageHeight;
    780             basePtr -= distanceToTopImage;
    781             baseEnd -= distanceToTopImage;
    782         }
    783 
    784         unsigned rowSize = (dstStride > 0) ? dstStride: -dstStride;
    785         uint8_t* dst = static_cast<uint8_t*>(destinationData);
    786 
    787         for (int i = 0; i < depth; ++i) {
    788             const uint8_t* ptr = basePtr;
    789             const uint8_t* ptrEnd = baseEnd;
    790             while (ptr < ptrEnd) {
    791                 memcpy(dst, ptr + srcRowOffset, rowSize);
    792                 ptr += srcStride;
    793                 dst += dstStride;
    794             }
    795             basePtr += unpackImageHeight * srcStride;
    796             baseEnd += unpackImageHeight * srcStride;
    797         }
    798         return true;
    799     }
    800 
    801     FormatConverter converter(
    802         sourceDataSubRectangle, depth,
    803         unpackImageHeight, sourceData, destinationData,
    804         srcStride, srcRowOffset, dstStride);
    805     converter.convert(sourceDataFormat, dstDataFormat, alphaOp);
    806     if (!converter.success())
    807         return false;
    808     return true;
    809 }
    81099
    811100#if !PLATFORM(COCOA)
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h

    r268386 r268578  
    8888class GraphicsContextGLOpenGLPrivate;
    8989
    90 class GraphicsContextGLOpenGL : public GraphicsContextGL
     90class GraphicsContextGLOpenGL final : public GraphicsContextGL
    9191#if PLATFORM(COCOA)
    9292    , private WebGLLayerClient
     
    9494{
    9595public:
    96     class Client {
    97     public:
    98         virtual ~Client() { }
    99         virtual void didComposite() = 0;
    100         virtual void forceContextLost() = 0;
    101         virtual void recycleContext() = 0;
    102         virtual void dispatchContextChangedNotification() = 0;
    103     };
    104 
    10596    static RefPtr<GraphicsContextGLOpenGL> create(GraphicsContextGLAttributes, HostWindow*, Destination = Destination::Offscreen);
    10697    virtual ~GraphicsContextGLOpenGL();
     
    10899#if PLATFORM(COCOA)
    109100    static Ref<GraphicsContextGLOpenGL> createShared(GraphicsContextGLOpenGL& sharedContext);
    110     PlatformGraphicsContextGL platformGraphicsContextGL() const override { return m_contextObj; }
    111     PlatformGLObject platformTexture() const override { return m_texture; }
    112     CALayer* platformLayer() const override { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
     101    PlatformGraphicsContextGL platformGraphicsContextGL() const final { return m_contextObj; }
     102    PlatformGLObject platformTexture() const final { return m_texture; }
     103    CALayer* platformLayer() const final { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
    113104    PlatformGraphicsContextGLDisplay platformDisplay() const { return m_displayObj; }
    114105    PlatformGraphicsContextGLConfig platformConfig() const { return m_configObj; }
     
    131122#endif
    132123
    133     void addClient(Client& client) { m_clients.add(&client); }
    134     void removeClient(Client& client) { m_clients.remove(&client); }
    135 
    136124    // With multisampling on, blit from multisampleFBO to regular FBO.
    137125    void prepareTexture();
     
    146134    void compileShaderDirect(PlatformGLObject);
    147135
    148     // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
    149     // Return true if no GL error is synthesized.
    150     // By default, alignment is 4, the OpenGL default setting.
    151     bool texImage2DResourceSafe(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLint alignment = 4);
    152 
    153     bool isGLES2Compliant() const;
    154 
    155     //----------------------------------------------------------------------
    156     // Helpers for texture uploading and pixel readback.
    157     //
    158 
    159     struct PixelStoreParams final {
    160         PixelStoreParams();
    161 
    162         GCGLint alignment;
    163         GCGLint rowLength;
    164         GCGLint imageHeight;
    165         GCGLint skipPixels;
    166         GCGLint skipRows;
    167         GCGLint skipImages;
    168     };
    169 
    170     // Computes the components per pixel and bytes per component
    171     // for the given format and type combination. Returns false if
    172     // either was an invalid enum.
    173     static bool computeFormatAndTypeParameters(GCGLenum format,
    174         GCGLenum type,
    175         unsigned* componentsPerPixel,
    176         unsigned* bytesPerComponent);
    177 
    178     // Computes the image size in bytes. If paddingInBytes is not null, padding
    179     // is also calculated in return. Returns NO_ERROR if succeed, otherwise
    180     // return the suggested GL error indicating the cause of the failure:
    181     //   INVALID_VALUE if width/height is negative or overflow happens.
    182     //   INVALID_ENUM if format/type is illegal.
    183     static GCGLenum computeImageSizeInBytes(GCGLenum format,
    184         GCGLenum type,
    185         GCGLsizei width,
    186         GCGLsizei height,
    187         GCGLsizei depth,
    188         const PixelStoreParams&,
    189         unsigned* imageSizeInBytes,
    190         unsigned* paddingInBytes,
    191         unsigned* skipSizeInBytes);
    192 
    193136#if !USE(ANGLE)
    194     static bool possibleFormatAndTypeForInternalFormat(GCGLenum internalFormat, GCGLenum& format, GCGLenum& type);
    195 #endif // !USE(ANGLE)
    196 
    197     // Extracts the contents of the given ImageData into the passed Vector,
    198     // packing the pixel data according to the given format and type,
    199     // and obeying the flipY and premultiplyAlpha flags. Returns true
    200     // upon success.
    201     static bool extractImageData(ImageData*,
    202         DataFormat,
    203         const IntRect& sourceImageSubRectangle,
    204         int depth,
    205         int unpackImageHeight,
    206         GCGLenum format,
    207         GCGLenum type,
    208         bool flipY,
    209         bool premultiplyAlpha,
    210         Vector<uint8_t>& data);
    211 
    212     // Helper function which extracts the user-supplied texture
    213     // data, applying the flipY and premultiplyAlpha parameters.
    214     // If the data is not tightly packed according to the passed
    215     // unpackParams, the output data will be tightly packed.
    216     // Returns true if successful, false if any error occurred.
    217     static bool extractTextureData(unsigned width, unsigned height,
    218         GCGLenum format, GCGLenum type,
    219         const PixelStoreParams& unpackParams,
    220         bool flipY, bool premultiplyAlpha,
    221         const void* pixels,
    222         Vector<uint8_t>& data);
     137    bool texImage2DResourceSafe(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLint alignment = 4) final;
     138#endif
     139
     140    bool isGLES2Compliant() const final;
    223141
    224142    //----------------------------------------------------------------------
     
    538456    void setBuffersToAutoClear(GCGLbitfield);
    539457    GCGLbitfield getBuffersToAutoClear() const;
    540     void enablePreserveDrawingBuffer() override;
     458    void enablePreserveDrawingBuffer() final;
    541459
    542460    void dispatchContextChangedNotification();
     
    551469#endif
    552470
    553 #if PLATFORM(COCOA)
    554     bool reshapeDisplayBufferBacking();
    555     bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer);
    556 #if PLATFORM(MAC)
     471#if PLATFORM(COCOA) && PLATFORM(MAC)
    557472    void updateCGLContext();
    558473#endif
    559 #endif // PLATFORM(COCOA)
    560 
    561     void setContextVisibility(bool);
    562 
    563     GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const { return m_powerPreferenceUsedForCreation; }
     474
     475    void setContextVisibility(bool) final;
     476
     477    GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const final { return m_powerPreferenceUsedForCreation; }
    564478
    565479    // Support for buffer creation and deletion
     
    578492    void deleteTexture(PlatformGLObject) final;
    579493
    580     // Synthesizes an OpenGL error which will be returned from a
    581     // later call to getError. This is used to emulate OpenGL ES
    582     // 2.0 behavior on the desktop and to enforce additional error
    583     // checking mandated by WebGL.
    584     //
    585     // Per the behavior of glGetError, this stores at most one
    586     // instance of any given error, and returns them from calls to
    587     // getError in the order they were added.
    588     void synthesizeGLError(GCGLenum error);
     494    void synthesizeGLError(GCGLenum error) final;
    589495
    590496    // Read real OpenGL errors, and move them to the synthetic
     
    598504    ExtensionsGL& getExtensions() final;
    599505
    600     IntSize getInternalFramebufferSize() const;
    601 
    602     // Packs the contents of the given Image which is passed in |pixels| into the passed Vector
    603     // according to the given format and type, and obeying the flipY and AlphaOp flags.
    604     // Returns true upon success.
    605     static bool packImageData(Image*, const void* pixels, GCGLenum format, GCGLenum type, bool flipY, AlphaOp, DataFormat sourceFormat, unsigned sourceImageWidth, unsigned sourceImageHeight, const IntRect& sourceImageSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, Vector<uint8_t>& data);
    606 
    607     class ImageExtractor {
    608     public:
    609         ImageExtractor(Image*, DOMSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication);
    610 
    611         // Each platform must provide an implementation of this method to deallocate or release resources
    612         // associated with the image if needed.
    613         ~ImageExtractor();
    614 
    615         bool extractSucceeded() { return m_extractSucceeded; }
    616         const void* imagePixelData() { return m_imagePixelData; }
    617         unsigned imageWidth() { return m_imageWidth; }
    618         unsigned imageHeight() { return m_imageHeight; }
    619         DataFormat imageSourceFormat() { return m_imageSourceFormat; }
    620         AlphaOp imageAlphaOp() { return m_alphaOp; }
    621         unsigned imageSourceUnpackAlignment() { return m_imageSourceUnpackAlignment; }
    622         DOMSource imageHtmlDomSource() { return m_imageHtmlDomSource; }
    623     private:
    624         // Each platform must provide an implementation of this method.
    625         // Extracts the image and keeps track of its status, such as width, height, Source Alignment, format and AlphaOp etc,
    626         // needs to lock the resources or relevant data if needed and returns true upon success
    627         bool extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication);
    628 
    629 #if USE(CAIRO)
    630         RefPtr<cairo_surface_t> m_imageSurface;
    631 #elif USE(CG)
    632         RetainPtr<CGImageRef> m_cgImage;
    633         RetainPtr<CGImageRef> m_decodedImage;
    634         RetainPtr<CFDataRef> m_pixelData;
    635         UniqueArray<uint8_t> m_formalizedRGBA8Data;
    636 #endif
    637         Image* m_image;
    638         DOMSource m_imageHtmlDomSource;
    639         bool m_extractSucceeded;
    640         const void* m_imagePixelData;
    641         unsigned m_imageWidth;
    642         unsigned m_imageHeight;
    643         DataFormat m_imageSourceFormat;
    644         AlphaOp m_alphaOp;
    645         unsigned m_imageSourceUnpackAlignment;
    646     };
    647 
    648     void setFailNextGPUStatusCheck() { m_failNextStatusCheck = true; }
    649 
    650     GCGLenum activeTextureUnit() const { return m_state.activeTextureUnit; }
    651     GCGLenum currentBoundTexture() const { return m_state.currentBoundTexture(); }
    652     GCGLenum currentBoundTarget() const { return m_state.currentBoundTarget(); }
     506    void setFailNextGPUStatusCheck() final { m_failNextStatusCheck = true; }
     507
    653508    unsigned textureSeed(GCGLuint texture) { return m_state.textureSeedCount.count(texture); }
    654509
     
    658513#endif
    659514
    660     void prepareForDisplay();
     515    void prepareForDisplay() final;
    661516
    662517private:
    663518    GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, Destination = Destination::Offscreen, GraphicsContextGLOpenGL* sharedContext = nullptr);
    664519
    665     // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
    666     // data into the specified OpenGL destination format and type.
    667     // A sourceUnpackAlignment of zero indicates that the source
    668     // data is tightly packed. Non-zero values may take a slow path.
    669     // Destination data will have no gaps between rows.
    670     static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned sourceDataWidth, unsigned sourceDataHeight, const IntRect& sourceDataSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, unsigned destinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool flipY);
    671520
    672521    // Take into account the user's requested context creation attributes,
     
    696545#if PLATFORM(COCOA)
    697546    bool allowOfflineRenderers() const;
     547    bool reshapeDisplayBufferBacking();
     548    bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer);
    698549    // WebGLLayerClient overrides.
    699     void didDisplay() override;
    700 #endif
    701 
    702     int m_currentWidth { 0 };
    703     int m_currentHeight { 0 };
     550    void didDisplay() final;
     551#endif
    704552
    705553#if PLATFORM(COCOA)
     
    889737#endif
    890738
    891     HashSet<Client*> m_clients;
    892 
    893739    bool m_isForWebGL2 { false };
    894740    bool m_usingCoreProfile { false };
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLCommon.cpp

    r268198 r268578  
    426426}
    427427
    428 IntSize GraphicsContextGLOpenGL::getInternalFramebufferSize() const
    429 {
    430     return IntSize(m_currentWidth, m_currentHeight);
    431 }
    432 
    433428void GraphicsContextGLOpenGL::activeTexture(GCGLenum texture)
    434429{
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextGLDirect2D.cpp

    r265360 r268578  
    3030
    3131#include "COMPtr.h"
     32#include "GraphicsContextGLImageExtractor.h"
    3233#include "NotImplemented.h"
    3334#include <d2d1.h>
     
    3637namespace WebCore {
    3738
    38 GraphicsContextGLOpenGL::ImageExtractor::~ImageExtractor() = default;
     39GraphicsContextGLImageExtractor::~GraphicsContextGLImageExtractor() = default;
    3940
    40 bool GraphicsContextGLOpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)
     41bool GraphicsContextGLImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)
    4142{
    4243    if (!m_image)
Note: See TracChangeset for help on using the changeset viewer.