Changeset 268578 in webkit
- Timestamp:
- Oct 16, 2020, 3:55:59 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 16 edited
- 1 copied
-
ChangeLog (modified) (1 diff)
-
Sources.txt (modified) (1 diff)
-
WebCore.xcodeproj/project.pbxproj (modified) (4 diffs)
-
html/canvas/WebGL2RenderingContext.cpp (modified) (2 diffs)
-
html/canvas/WebGL2RenderingContext.h (modified) (1 diff)
-
html/canvas/WebGLRenderingContextBase.cpp (modified) (4 diffs)
-
html/canvas/WebGLRenderingContextBase.h (modified) (1 diff)
-
platform/graphics/GraphicsContextGL.cpp (modified) (2 diffs)
-
platform/graphics/GraphicsContextGL.h (modified) (5 diffs)
-
platform/graphics/GraphicsContextGLImageExtractor.cpp (copied) (copied from trunk/Source/WebCore/platform/graphics/win/GraphicsContextGLDirect2D.cpp ) (2 diffs)
-
platform/graphics/GraphicsContextGLImageExtractor.h (added)
-
platform/graphics/angle/GraphicsContextGLANGLE.cpp (modified) (1 diff)
-
platform/graphics/cairo/GraphicsContextGLCairo.cpp (modified) (2 diffs)
-
platform/graphics/cg/GraphicsContextGLCG.cpp (modified) (2 diffs)
-
platform/graphics/opengl/GraphicsContextGLOpenGL.cpp (modified) (4 diffs)
-
platform/graphics/opengl/GraphicsContextGLOpenGL.h (modified) (12 diffs)
-
platform/graphics/opengl/GraphicsContextGLOpenGLCommon.cpp (modified) (1 diff)
-
platform/graphics/win/GraphicsContextGLDirect2D.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r268577 r268578 1 2020-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 1 78 2020-10-16 Youenn Fablet <youenn@apple.com> 2 79 -
trunk/Source/WebCore/Sources.txt
r268560 r268578 1896 1896 platform/graphics/GraphicsContext.cpp 1897 1897 platform/graphics/GraphicsContextGL.cpp 1898 platform/graphics/GraphicsContextGLImageExtractor.cpp 1898 1899 platform/graphics/GraphicsContextImpl.cpp 1899 1900 platform/graphics/GraphicsLayer.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r268577 r268578 2219 2219 7BB34A152534579100029D08 /* WebGLLayerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A132534579100029D08 /* WebGLLayerClient.h */; }; 2220 2220 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, ); }; }; 2221 2222 7BE7427381FA906FBB4F0F2C /* JSSVGGraphicsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 950C4C02BED8936F818E2F99 /* JSSVGGraphicsElement.h */; }; 2222 2223 7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C029C6D2493C8F800268204 /* ColorTypes.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 10071 10072 7BB34A132534579100029D08 /* WebGLLayerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLLayerClient.h; sourceTree = "<group>"; }; 10072 10073 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>"; }; 10073 10076 7C011F3D24FAD360005BEF10 /* Settings.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Settings.cpp.erb; sourceTree = "<group>"; }; 10074 10077 7C011F3E24FAD360005BEF10 /* InternalSettingsGenerated.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = InternalSettingsGenerated.cpp.erb; sourceTree = "<group>"; }; … … 26147 26150 313DE86F23A96967008FC47B /* GraphicsContextGL.h */, 26148 26151 7C330A011DF8FAC600D3395C /* GraphicsContextGLAttributes.h */, 26152 7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */, 26153 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */, 26149 26154 0F0012401FAD881000531D76 /* GraphicsContextImpl.cpp */, 26150 26155 0F00123F1FAD87D600531D76 /* GraphicsContextImpl.h */, … … 31623 31628 7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */, 31624 31629 7C330A021DF8FAC600D3395C /* GraphicsContextGLAttributes.h in Headers */, 31630 7BB34A48253776CA00029D08 /* GraphicsContextGLImageExtractor.h in Headers */, 31625 31631 49C7B9FC1042D3650009D447 /* GraphicsContextGLOpenGL.h in Headers */, 31626 31632 319A728823C267FE0085353C /* GraphicsContextGLOpenGLManager.h in Headers */, -
trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
r268502 r268578 3003 3003 } 3004 3004 3005 GraphicsContextGLOpenGL::PixelStoreParams WebGL2RenderingContext::getPackPixelStoreParams() const3006 { 3007 GraphicsContextGLOpenGL::PixelStoreParams params;3005 WebGLRenderingContextBase::PixelStoreParams WebGL2RenderingContext::getPackPixelStoreParams() const 3006 { 3007 PixelStoreParams params; 3008 3008 params.alignment = m_packAlignment; 3009 3009 params.rowLength = m_packRowLength; … … 3013 3013 } 3014 3014 3015 GraphicsContextGLOpenGL::PixelStoreParams WebGL2RenderingContext::getUnpackPixelStoreParams(TexImageDimension dimension) const3016 { 3017 GraphicsContextGLOpenGL::PixelStoreParams params;3015 WebGLRenderingContextBase::PixelStoreParams WebGL2RenderingContext::getUnpackPixelStoreParams(TexImageDimension dimension) const 3016 { 3017 PixelStoreParams params; 3018 3018 params.alignment = m_unpackAlignment; 3019 3019 params.rowLength = m_unpackRowLength; -
trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.h
r268198 r268578 257 257 GCGLuint maxTransformFeedbackSeparateAttribs() const; 258 258 259 GraphicsContextGLOpenGL::PixelStoreParams getPackPixelStoreParams() const override;260 GraphicsContextGLOpenGL::PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const override;259 PixelStoreParams getPackPixelStoreParams() const override; 260 PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const override; 261 261 262 262 bool checkAndTranslateAttachments(const char* functionName, GCGLenum, Vector<GCGLenum>&); -
trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
r268255 r268578 51 51 #include "FrameView.h" 52 52 #include "GraphicsContext.h" 53 #include "GraphicsContextGLImageExtractor.h" 53 54 #include "HTMLCanvasElement.h" 54 55 #include "HTMLImageElement.h" … … 4889 4890 // Only enter here if width or height is non-zero. Otherwise, call to the 4890 4891 // underlying driver to generate appropriate GL errors if needed. 4891 GraphicsContextGLOpenGL::PixelStoreParams unpackParams = getUnpackPixelStoreParams(TexImageDimension::Tex2D);4892 PixelStoreParams unpackParams = getUnpackPixelStoreParams(TexImageDimension::Tex2D); 4892 4893 GCGLint dataStoreWidth = unpackParams.rowLength ? unpackParams.rowLength : width; 4893 4894 if (unpackParams.skipPixels + width > dataStoreWidth) { … … 4946 4947 adjustedSourceImageRect.setY(image->height() - adjustedSourceImageRect.maxY()); 4947 4948 4948 GraphicsContextGL OpenGL::ImageExtractor imageExtractor(image, domSource, premultiplyAlpha, m_unpackColorspaceConversion == GraphicsContextGL::NONE, ignoreNativeImageAlphaPremultiplication);4949 GraphicsContextGLImageExtractor imageExtractor(image, domSource, premultiplyAlpha, m_unpackColorspaceConversion == GraphicsContextGL::NONE, ignoreNativeImageAlphaPremultiplication); 4949 4950 if (!imageExtractor.extractSucceeded()) { 4950 4951 synthesizeGLError(GraphicsContextGL::INVALID_VALUE, functionName, "bad image data"); … … 6308 6309 } 6309 6310 6310 GraphicsContextGLOpenGL::PixelStoreParams WebGLRenderingContextBase::getPackPixelStoreParams() const6311 { 6312 GraphicsContextGLOpenGL::PixelStoreParams params;6311 WebGLRenderingContextBase::PixelStoreParams WebGLRenderingContextBase::getPackPixelStoreParams() const 6312 { 6313 PixelStoreParams params; 6313 6314 params.alignment = m_packAlignment; 6314 6315 return params; 6315 6316 } 6316 6317 6317 GraphicsContextGLOpenGL::PixelStoreParams WebGLRenderingContextBase::getUnpackPixelStoreParams(TexImageDimension dimension) const6318 WebGLRenderingContextBase::PixelStoreParams WebGLRenderingContextBase::getUnpackPixelStoreParams(TexImageDimension dimension) const 6318 6319 { 6319 6320 UNUSED_PARAM(dimension); 6320 GraphicsContextGLOpenGL::PixelStoreParams params;6321 PixelStoreParams params; 6321 6322 params.alignment = m_unpackAlignment; 6322 6323 return params; -
trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h
r268234 r268578 852 852 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); 853 853 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; 857 857 858 858 #if !USE(ANGLE) -
trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp
r268198 r268578 32 32 33 33 #include "ExtensionsGL.h" 34 #include "FormatConverter.h" 35 #include "Image.h" 36 #include "ImageData.h" 37 #include "ImageObserver.h" 34 38 35 39 namespace WebCore { 40 41 static 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 269 ALWAYS_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. 344 static 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 36 406 37 407 GraphicsContextGL::GraphicsContextGL(GraphicsContextGLAttributes attrs, Destination destination, GraphicsContextGL*) … … 185 555 } 186 556 557 bool 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 636 GCGLenum 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) 738 bool 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 818 bool 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 838 bool 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 859 bool 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 187 883 } // namespace WebCore 188 884 -
trunk/Source/WebCore/platform/graphics/GraphicsContextGL.h
r268198 r268578 34 34 #include "IntSize.h" 35 35 #include "PlatformLayer.h" 36 #include <wtf/HashSet.h> 36 37 #include <wtf/RefCounted.h> 37 38 #include <wtf/text/WTFString.h> … … 889 890 } 890 891 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 891 901 struct ActiveInfo { 892 902 String name; … … 897 907 GraphicsContextGL(GraphicsContextGLAttributes, Destination = Destination::Offscreen, GraphicsContextGL* sharedContext = nullptr); 898 908 virtual ~GraphicsContextGL() = default; 909 910 void addClient(Client& client) { m_clients.add(&client); } 911 void removeClient(Client& client) { m_clients.remove(&client); } 899 912 900 913 // ========== WebGL 1 entry points. … … 1254 1267 // ========== Non-WebGL based entry points. 1255 1268 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 1256 1298 static unsigned getClearBitsByAttachmentType(GCGLenum); 1257 1299 static unsigned getClearBitsByFormat(GCGLenum); … … 1259 1301 static uint8_t getChannelBitsByFormat(GCGLenum); 1260 1302 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 1261 1346 Destination destination() const { return m_destination; } 1347 1348 protected: 1349 int m_currentWidth { 0 }; 1350 int m_currentHeight { 0 }; 1351 HashSet<Client*> m_clients; 1262 1352 1263 1353 private: -
trunk/Source/WebCore/platform/graphics/GraphicsContextGLImageExtractor.cpp
r268577 r268578 1 1 /* 2 * Copyright (C) 20 19Apple Inc. All rights reserved.2 * Copyright (C) 2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (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. 24 24 */ 25 25 26 26 #include "config.h" 27 #include "GraphicsContextGL OpenGL.h"27 #include "GraphicsContextGLImageExtractor.h" 28 28 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) 35 30 36 31 namespace WebCore { 37 32 38 GraphicsContextGLOpenGL::ImageExtractor::~ImageExtractor() = default; 39 40 bool GraphicsContextGLOpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication) 33 GraphicsContextGLImageExtractor::GraphicsContextGLImageExtractor(Image* image, DOMSource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication) 41 34 { 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); 48 38 } 49 39 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();56 40 } 57 41 58 } // namespace WebCore 59 60 #endif // ENABLE(GRAPHICS_CONTEXT_GL) && USE(DIRECT2D) 42 #endif -
trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp
r268386 r268578 708 708 } 709 709 710 IntSize GraphicsContextGLOpenGL::getInternalFramebufferSize() const711 {712 return IntSize(m_currentWidth, m_currentHeight);713 }714 715 710 void GraphicsContextGLOpenGL::activeTexture(GCGLenum texture) 716 711 { -
trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextGLCairo.cpp
r265360 r268578 32 32 33 33 #include "CairoUtilities.h" 34 #include "GraphicsContextGLImageExtractor.h" 34 35 #include "Image.h" 35 36 #include "ImageSource.h" … … 40 41 namespace WebCore { 41 42 42 GraphicsContextGL OpenGL::ImageExtractor::~ImageExtractor() = default;43 GraphicsContextGLImageExtractor::~GraphicsContextGLImageExtractor() = default; 43 44 44 bool GraphicsContextGL OpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool)45 bool GraphicsContextGLImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool) 45 46 { 46 47 if (!m_image) -
trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp
r265360 r268578 31 31 #include "BitmapImage.h" 32 32 #include "GraphicsContextCG.h" 33 #include "GraphicsContextGLImageExtractor.h" 33 34 #include "GraphicsContextGLOpenGL.h" 34 35 #include "Image.h" … … 318 319 } 319 320 320 GraphicsContextGL OpenGL::ImageExtractor::~ImageExtractor() = default;321 322 bool GraphicsContextGL OpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)321 GraphicsContextGLImageExtractor::~GraphicsContextGLImageExtractor() = default; 322 323 bool GraphicsContextGLImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication) 323 324 { 324 325 if (!m_image) -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp
r268198 r268578 32 32 33 33 #include "ExtensionsGL.h" 34 #include "FormatConverter.h"35 #include "Image.h"36 #include "ImageData.h"37 #include "ImageObserver.h"38 34 #include <wtf/UniqueArray.h> 39 35 40 36 namespace 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_float180 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_float212 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 namespace273 37 274 38 void GraphicsContextGLOpenGL::resetBuffersToAutoClear() … … 308 72 } 309 73 74 #if !USE(ANGLE) 310 75 bool GraphicsContextGLOpenGL::texImage2DResourceSafe(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLint unpackAlignment) 311 76 { … … 314 79 if (width > 0 && height > 0) { 315 80 unsigned size; 316 GraphicsContextGLOpenGL::PixelStoreParams params;81 PixelStoreParams params; 317 82 params.alignment = unpackAlignment; 318 83 GCGLenum error = computeImageSizeInBytes(format, type, width, height, 1, params, &size, nullptr, nullptr); … … 330 95 return texImage2D(target, level, internalformat, width, height, border, format, type, zero.get()); 331 96 } 97 #endif 332 98 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_BGRA8888357 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_float397 *bytesPerComponent = sizeof(GCGLfloat);398 break;399 case GraphicsContextGL::HALF_FLOAT:400 case GraphicsContextGL::HALF_FLOAT_OES: // OES_texture_half_float401 *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_CASE488 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 } else535 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 the775 // "bottommost" of those images. Since the source pointer strides in776 // the positive direction, we need to back it up to point at the777 // 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 }810 99 811 100 #if !PLATFORM(COCOA) -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h
r268386 r268578 88 88 class GraphicsContextGLOpenGLPrivate; 89 89 90 class GraphicsContextGLOpenGL : public GraphicsContextGL90 class GraphicsContextGLOpenGL final : public GraphicsContextGL 91 91 #if PLATFORM(COCOA) 92 92 , private WebGLLayerClient … … 94 94 { 95 95 public: 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 105 96 static RefPtr<GraphicsContextGLOpenGL> create(GraphicsContextGLAttributes, HostWindow*, Destination = Destination::Offscreen); 106 97 virtual ~GraphicsContextGLOpenGL(); … … 108 99 #if PLATFORM(COCOA) 109 100 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()); } 113 104 PlatformGraphicsContextGLDisplay platformDisplay() const { return m_displayObj; } 114 105 PlatformGraphicsContextGLConfig platformConfig() const { return m_configObj; } … … 131 122 #endif 132 123 133 void addClient(Client& client) { m_clients.add(&client); }134 void removeClient(Client& client) { m_clients.remove(&client); }135 136 124 // With multisampling on, blit from multisampleFBO to regular FBO. 137 125 void prepareTexture(); … … 146 134 void compileShaderDirect(PlatformGLObject); 147 135 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 component171 // for the given format and type combination. Returns false if172 // 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, padding179 // is also calculated in return. Returns NO_ERROR if succeed, otherwise180 // 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 193 136 #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; 223 141 224 142 //---------------------------------------------------------------------- … … 538 456 void setBuffersToAutoClear(GCGLbitfield); 539 457 GCGLbitfield getBuffersToAutoClear() const; 540 void enablePreserveDrawingBuffer() override;458 void enablePreserveDrawingBuffer() final; 541 459 542 460 void dispatchContextChangedNotification(); … … 551 469 #endif 552 470 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) 557 472 void updateCGLContext(); 558 473 #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; } 564 478 565 479 // Support for buffer creation and deletion … … 578 492 void deleteTexture(PlatformGLObject) final; 579 493 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; 589 495 590 496 // Read real OpenGL errors, and move them to the synthetic … … 598 504 ExtensionsGL& getExtensions() final; 599 505 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 653 508 unsigned textureSeed(GCGLuint texture) { return m_state.textureSeedCount.count(texture); } 654 509 … … 658 513 #endif 659 514 660 void prepareForDisplay() ;515 void prepareForDisplay() final; 661 516 662 517 private: 663 518 GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, Destination = Destination::Offscreen, GraphicsContextGLOpenGL* sharedContext = nullptr); 664 519 665 // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel666 // data into the specified OpenGL destination format and type.667 // A sourceUnpackAlignment of zero indicates that the source668 // 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);671 520 672 521 // Take into account the user's requested context creation attributes, … … 696 545 #if PLATFORM(COCOA) 697 546 bool allowOfflineRenderers() const; 547 bool reshapeDisplayBufferBacking(); 548 bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer); 698 549 // 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 704 552 705 553 #if PLATFORM(COCOA) … … 889 737 #endif 890 738 891 HashSet<Client*> m_clients;892 893 739 bool m_isForWebGL2 { false }; 894 740 bool m_usingCoreProfile { false }; -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLCommon.cpp
r268198 r268578 426 426 } 427 427 428 IntSize GraphicsContextGLOpenGL::getInternalFramebufferSize() const429 {430 return IntSize(m_currentWidth, m_currentHeight);431 }432 433 428 void GraphicsContextGLOpenGL::activeTexture(GCGLenum texture) 434 429 { -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextGLDirect2D.cpp
r265360 r268578 30 30 31 31 #include "COMPtr.h" 32 #include "GraphicsContextGLImageExtractor.h" 32 33 #include "NotImplemented.h" 33 34 #include <d2d1.h> … … 36 37 namespace WebCore { 37 38 38 GraphicsContextGL OpenGL::ImageExtractor::~ImageExtractor() = default;39 GraphicsContextGLImageExtractor::~GraphicsContextGLImageExtractor() = default; 39 40 40 bool GraphicsContextGL OpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)41 bool GraphicsContextGLImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication) 41 42 { 42 43 if (!m_image)
Note:
See TracChangeset
for help on using the changeset viewer.