Changeset 268755 in webkit
- Timestamp:
- Oct 20, 2020, 1:10:22 PM (6 years ago)
- Location:
- branches/safari-611.1.4-branch/Source/WebCore
- Files:
-
- 2 deleted
- 16 edited
-
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 (deleted)
-
platform/graphics/GraphicsContextGLImageExtractor.h (deleted)
-
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
-
branches/safari-611.1.4-branch/Source/WebCore/ChangeLog
r268754 r268755 1 2020-10-20 Alan Coon <alancoon@apple.com> 2 3 Revert r268578. rdar://problem/70497386 4 1 5 2020-10-20 Alan Coon <alancoon@apple.com> 2 6 -
branches/safari-611.1.4-branch/Source/WebCore/Sources.txt
r268648 r268755 1898 1898 platform/graphics/GraphicsContext.cpp 1899 1899 platform/graphics/GraphicsContextGL.cpp 1900 platform/graphics/GraphicsContextGLImageExtractor.cpp1901 1900 platform/graphics/GraphicsContextImpl.cpp 1902 1901 platform/graphics/GraphicsLayer.cpp -
branches/safari-611.1.4-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r268648 r268755 2221 2221 7BB34A152534579100029D08 /* WebGLLayerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A132534579100029D08 /* WebGLLayerClient.h */; }; 2222 2222 7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */; }; 2223 7BB34A48253776CA00029D08 /* GraphicsContextGLImageExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */; settings = {ATTRIBUTES = (Private, ); }; };2224 2223 7BE7427381FA906FBB4F0F2C /* JSSVGGraphicsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 950C4C02BED8936F818E2F99 /* JSSVGGraphicsElement.h */; }; 2225 2224 7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C029C6D2493C8F800268204 /* ColorTypes.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 10077 10076 7BB34A132534579100029D08 /* WebGLLayerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLLayerClient.h; sourceTree = "<group>"; }; 10078 10077 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLANGLEUtilities.h; sourceTree = "<group>"; }; 10079 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLImageExtractor.h; sourceTree = "<group>"; };10080 7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextGLImageExtractor.cpp; sourceTree = "<group>"; };10081 10078 7C011F3D24FAD360005BEF10 /* Settings.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Settings.cpp.erb; sourceTree = "<group>"; }; 10082 10079 7C011F3E24FAD360005BEF10 /* InternalSettingsGenerated.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = InternalSettingsGenerated.cpp.erb; sourceTree = "<group>"; }; … … 26160 26157 313DE86F23A96967008FC47B /* GraphicsContextGL.h */, 26161 26158 7C330A011DF8FAC600D3395C /* GraphicsContextGLAttributes.h */, 26162 7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */,26163 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */,26164 26159 0F0012401FAD881000531D76 /* GraphicsContextImpl.cpp */, 26165 26160 0F00123F1FAD87D600531D76 /* GraphicsContextImpl.h */, … … 31648 31643 7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */, 31649 31644 7C330A021DF8FAC600D3395C /* GraphicsContextGLAttributes.h in Headers */, 31650 7BB34A48253776CA00029D08 /* GraphicsContextGLImageExtractor.h in Headers */,31651 31645 49C7B9FC1042D3650009D447 /* GraphicsContextGLOpenGL.h in Headers */, 31652 31646 319A728823C267FE0085353C /* GraphicsContextGLOpenGLManager.h in Headers */, -
branches/safari-611.1.4-branch/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
r268578 r268755 3003 3003 } 3004 3004 3005 WebGLRenderingContextBase::PixelStoreParams WebGL2RenderingContext::getPackPixelStoreParams() const3006 { 3007 PixelStoreParams params;3005 GraphicsContextGLOpenGL::PixelStoreParams WebGL2RenderingContext::getPackPixelStoreParams() const 3006 { 3007 GraphicsContextGLOpenGL::PixelStoreParams params; 3008 3008 params.alignment = m_packAlignment; 3009 3009 params.rowLength = m_packRowLength; … … 3013 3013 } 3014 3014 3015 WebGLRenderingContextBase::PixelStoreParams WebGL2RenderingContext::getUnpackPixelStoreParams(TexImageDimension dimension) const3016 { 3017 PixelStoreParams params;3015 GraphicsContextGLOpenGL::PixelStoreParams WebGL2RenderingContext::getUnpackPixelStoreParams(TexImageDimension dimension) const 3016 { 3017 GraphicsContextGLOpenGL::PixelStoreParams params; 3018 3018 params.alignment = m_unpackAlignment; 3019 3019 params.rowLength = m_unpackRowLength; -
branches/safari-611.1.4-branch/Source/WebCore/html/canvas/WebGL2RenderingContext.h
r268578 r268755 257 257 GCGLuint maxTransformFeedbackSeparateAttribs() const; 258 258 259 PixelStoreParams getPackPixelStoreParams() const override;260 PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const override;259 GraphicsContextGLOpenGL::PixelStoreParams getPackPixelStoreParams() const override; 260 GraphicsContextGLOpenGL::PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const override; 261 261 262 262 bool checkAndTranslateAttachments(const char* functionName, GCGLenum, Vector<GCGLenum>&); -
branches/safari-611.1.4-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
r268578 r268755 51 51 #include "FrameView.h" 52 52 #include "GraphicsContext.h" 53 #include "GraphicsContextGLImageExtractor.h"54 53 #include "HTMLCanvasElement.h" 55 54 #include "HTMLImageElement.h" … … 4890 4889 // Only enter here if width or height is non-zero. Otherwise, call to the 4891 4890 // underlying driver to generate appropriate GL errors if needed. 4892 PixelStoreParams unpackParams = getUnpackPixelStoreParams(TexImageDimension::Tex2D);4891 GraphicsContextGLOpenGL::PixelStoreParams unpackParams = getUnpackPixelStoreParams(TexImageDimension::Tex2D); 4893 4892 GCGLint dataStoreWidth = unpackParams.rowLength ? unpackParams.rowLength : width; 4894 4893 if (unpackParams.skipPixels + width > dataStoreWidth) { … … 4947 4946 adjustedSourceImageRect.setY(image->height() - adjustedSourceImageRect.maxY()); 4948 4947 4949 GraphicsContextGL ImageExtractor imageExtractor(image, domSource, premultiplyAlpha, m_unpackColorspaceConversion == GraphicsContextGL::NONE, ignoreNativeImageAlphaPremultiplication);4948 GraphicsContextGLOpenGL::ImageExtractor imageExtractor(image, domSource, premultiplyAlpha, m_unpackColorspaceConversion == GraphicsContextGL::NONE, ignoreNativeImageAlphaPremultiplication); 4950 4949 if (!imageExtractor.extractSucceeded()) { 4951 4950 synthesizeGLError(GraphicsContextGL::INVALID_VALUE, functionName, "bad image data"); … … 6309 6308 } 6310 6309 6311 WebGLRenderingContextBase::PixelStoreParams WebGLRenderingContextBase::getPackPixelStoreParams() const6312 { 6313 PixelStoreParams params;6310 GraphicsContextGLOpenGL::PixelStoreParams WebGLRenderingContextBase::getPackPixelStoreParams() const 6311 { 6312 GraphicsContextGLOpenGL::PixelStoreParams params; 6314 6313 params.alignment = m_packAlignment; 6315 6314 return params; 6316 6315 } 6317 6316 6318 WebGLRenderingContextBase::PixelStoreParams WebGLRenderingContextBase::getUnpackPixelStoreParams(TexImageDimension dimension) const6317 GraphicsContextGLOpenGL::PixelStoreParams WebGLRenderingContextBase::getUnpackPixelStoreParams(TexImageDimension dimension) const 6319 6318 { 6320 6319 UNUSED_PARAM(dimension); 6321 PixelStoreParams params;6320 GraphicsContextGLOpenGL::PixelStoreParams params; 6322 6321 params.alignment = m_unpackAlignment; 6323 6322 return params; -
branches/safari-611.1.4-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.h
r268578 r268755 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 using PixelStoreParams = GraphicsContextGL::PixelStoreParams; 855 virtual PixelStoreParams getPackPixelStoreParams() const;856 virtual PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const;854 855 virtual GraphicsContextGLOpenGL::PixelStoreParams getPackPixelStoreParams() const; 856 virtual GraphicsContextGLOpenGL::PixelStoreParams getUnpackPixelStoreParams(TexImageDimension) const; 857 857 858 858 #if !USE(ANGLE) -
branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/GraphicsContextGL.cpp
r268578 r268755 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 39 35 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_float177 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_float209 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 pixel340 // data into the specified OpenGL destination format and type.341 // A sourceUnpackAlignment of zero indicates that the source342 // 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 the370 // "bottommost" of those images. Since the source pointer strides in371 // the positive direction, we need to back it up to point at the372 // 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 406 36 407 37 GraphicsContextGL::GraphicsContextGL(GraphicsContextGLAttributes attrs, Destination destination, GraphicsContextGL*) … … 555 185 } 556 186 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_BGRA8888581 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_float621 *bytesPerComponent = sizeof(GCGLfloat);622 break;623 case GraphicsContextGL::HALF_FLOAT:624 case GraphicsContextGL::HALF_FLOAT_OES: // OES_texture_half_float625 *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 } else676 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_CASE813 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 883 187 } // namespace WebCore 884 188 -
branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h
r268578 r268755 34 34 #include "IntSize.h" 35 35 #include "PlatformLayer.h" 36 #include <wtf/HashSet.h>37 36 #include <wtf/RefCounted.h> 38 37 #include <wtf/text/WTFString.h> … … 890 889 } 891 890 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 901 891 struct ActiveInfo { 902 892 String name; … … 907 897 GraphicsContextGL(GraphicsContextGLAttributes, Destination = Destination::Offscreen, GraphicsContextGL* sharedContext = nullptr); 908 898 virtual ~GraphicsContextGL() = default; 909 910 void addClient(Client& client) { m_clients.add(&client); }911 void removeClient(Client& client) { m_clients.remove(&client); }912 899 913 900 // ========== WebGL 1 entry points. … … 1267 1254 // ========== Non-WebGL based entry points. 1268 1255 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 a1276 // later call to getError. This is used to emulate OpenGL ES1277 // 2.0 behavior on the desktop and to enforce additional error1278 // checking mandated by WebGL.1279 //1280 // Per the behavior of glGetError, this stores at most one1281 // instance of any given error, and returns them from calls to1282 // 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 #endif1295 1296 IntSize getInternalFramebufferSize() const { return IntSize(m_currentWidth, m_currentHeight); }1297 1298 1256 static unsigned getClearBitsByAttachmentType(GCGLenum); 1299 1257 static unsigned getClearBitsByFormat(GCGLenum); … … 1301 1259 static uint8_t getChannelBitsByFormat(GCGLenum); 1302 1260 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 component1313 // for the given format and type combination. Returns false if1314 // 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, padding1318 // is also calculated in return. Returns NO_ERROR if succeed, otherwise1319 // 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 true1331 // 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 texture1335 // data, applying the flipY and premultiplyAlpha parameters.1336 // If the data is not tightly packed according to the passed1337 // 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 Vector1342 // 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 1346 1261 Destination destination() const { return m_destination; } 1347 1348 protected:1349 int m_currentWidth { 0 };1350 int m_currentHeight { 0 };1351 HashSet<Client*> m_clients;1352 1262 1353 1263 private: -
branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp
r268578 r268755 708 708 } 709 709 710 IntSize GraphicsContextGLOpenGL::getInternalFramebufferSize() const 711 { 712 return IntSize(m_currentWidth, m_currentHeight); 713 } 714 710 715 void GraphicsContextGLOpenGL::activeTexture(GCGLenum texture) 711 716 { -
branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cairo/GraphicsContextGLCairo.cpp
r268578 r268755 32 32 33 33 #include "CairoUtilities.h" 34 #include "GraphicsContextGLImageExtractor.h"35 34 #include "Image.h" 36 35 #include "ImageSource.h" … … 41 40 namespace WebCore { 42 41 43 GraphicsContextGL ImageExtractor::~GraphicsContextGLImageExtractor() = default;42 GraphicsContextGLOpenGL::ImageExtractor::~ImageExtractor() = default; 44 43 45 bool GraphicsContextGL ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool)44 bool GraphicsContextGLOpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool) 46 45 { 47 46 if (!m_image) -
branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp
r268578 r268755 31 31 #include "BitmapImage.h" 32 32 #include "GraphicsContextCG.h" 33 #include "GraphicsContextGLImageExtractor.h"34 33 #include "GraphicsContextGLOpenGL.h" 35 34 #include "Image.h" … … 319 318 } 320 319 321 GraphicsContextGL ImageExtractor::~GraphicsContextGLImageExtractor() = default;322 323 bool GraphicsContextGL ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)320 GraphicsContextGLOpenGL::ImageExtractor::~ImageExtractor() = default; 321 322 bool GraphicsContextGLOpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication) 324 323 { 325 324 if (!m_image) -
branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp
r268578 r268755 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 #include <wtf/UniqueArray.h> 35 39 36 40 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_float 180 case GraphicsContextGL::HALF_FLOAT: 181 switch (destinationFormat) { 182 case GraphicsContextGL::RGBA: 183 dstFormat = GraphicsContextGL::DataFormat::RGBA16F; 184 break; 185 case GraphicsContextGL::RGB: 186 dstFormat = GraphicsContextGL::DataFormat::RGB16F; 187 break; 188 case GraphicsContextGL::RG: 189 dstFormat = GraphicsContextGL::DataFormat::RG16F; 190 break; 191 case GraphicsContextGL::ALPHA: 192 dstFormat = GraphicsContextGL::DataFormat::A16F; 193 break; 194 case GraphicsContextGL::LUMINANCE: 195 case GraphicsContextGL::RED: 196 dstFormat = GraphicsContextGL::DataFormat::R16F; 197 break; 198 case GraphicsContextGL::LUMINANCE_ALPHA: 199 dstFormat = GraphicsContextGL::DataFormat::RA16F; 200 break; 201 case GraphicsContextGL::SRGB: 202 dstFormat = GraphicsContextGL::DataFormat::RGB16F; 203 break; 204 case GraphicsContextGL::SRGB_ALPHA: 205 dstFormat = GraphicsContextGL::DataFormat::RGBA16F; 206 break; 207 default: 208 ASSERT_NOT_REACHED(); 209 } 210 break; 211 case GraphicsContextGL::FLOAT: // OES_texture_float 212 switch (destinationFormat) { 213 case GraphicsContextGL::RGBA: 214 dstFormat = GraphicsContextGL::DataFormat::RGBA32F; 215 break; 216 case GraphicsContextGL::RGB: 217 dstFormat = GraphicsContextGL::DataFormat::RGB32F; 218 break; 219 case GraphicsContextGL::RG: 220 dstFormat = GraphicsContextGL::DataFormat::RG32F; 221 break; 222 case GraphicsContextGL::ALPHA: 223 dstFormat = GraphicsContextGL::DataFormat::A32F; 224 break; 225 case GraphicsContextGL::LUMINANCE: 226 case GraphicsContextGL::RED: 227 dstFormat = GraphicsContextGL::DataFormat::R32F; 228 break; 229 case GraphicsContextGL::DEPTH_COMPONENT: 230 dstFormat = GraphicsContextGL::DataFormat::D32F; 231 break; 232 case GraphicsContextGL::LUMINANCE_ALPHA: 233 dstFormat = GraphicsContextGL::DataFormat::RA32F; 234 break; 235 case GraphicsContextGL::SRGB: 236 dstFormat = GraphicsContextGL::DataFormat::RGB32F; 237 break; 238 case GraphicsContextGL::SRGB_ALPHA: 239 dstFormat = GraphicsContextGL::DataFormat::RGBA32F; 240 break; 241 default: 242 ASSERT_NOT_REACHED(); 243 } 244 break; 245 case GraphicsContextGL::UNSIGNED_SHORT_4_4_4_4: 246 dstFormat = GraphicsContextGL::DataFormat::RGBA4444; 247 break; 248 case GraphicsContextGL::UNSIGNED_SHORT_5_5_5_1: 249 dstFormat = GraphicsContextGL::DataFormat::RGBA5551; 250 break; 251 case GraphicsContextGL::UNSIGNED_SHORT_5_6_5: 252 dstFormat = GraphicsContextGL::DataFormat::RGB565; 253 break; 254 case GraphicsContextGL::UNSIGNED_INT_5_9_9_9_REV: 255 dstFormat = GraphicsContextGL::DataFormat::RGB5999; 256 break; 257 case GraphicsContextGL::UNSIGNED_INT_24_8: 258 dstFormat = GraphicsContextGL::DataFormat::DS24_8; 259 break; 260 case GraphicsContextGL::UNSIGNED_INT_10F_11F_11F_REV: 261 dstFormat = GraphicsContextGL::DataFormat::RGB10F11F11F; 262 break; 263 case GraphicsContextGL::UNSIGNED_INT_2_10_10_10_REV: 264 dstFormat = GraphicsContextGL::DataFormat::RGBA2_10_10_10; 265 break; 266 default: 267 ASSERT_NOT_REACHED(); 268 } 269 return dstFormat; 270 } 271 272 } // anonymous namespace 37 273 38 274 void GraphicsContextGLOpenGL::resetBuffersToAutoClear() … … 72 308 } 73 309 74 #if !USE(ANGLE)75 310 bool GraphicsContextGLOpenGL::texImage2DResourceSafe(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLint unpackAlignment) 76 311 { … … 79 314 if (width > 0 && height > 0) { 80 315 unsigned size; 81 PixelStoreParams params;316 GraphicsContextGLOpenGL::PixelStoreParams params; 82 317 params.alignment = unpackAlignment; 83 318 GCGLenum error = computeImageSizeInBytes(format, type, width, height, 1, params, &size, nullptr, nullptr); … … 95 330 return texImage2D(target, level, internalformat, width, height, border, format, type, zero.get()); 96 331 } 97 #endif 98 332 333 bool GraphicsContextGLOpenGL::computeFormatAndTypeParameters(GCGLenum format, GCGLenum type, unsigned* componentsPerPixel, unsigned* bytesPerComponent) 334 { 335 switch (format) { 336 case GraphicsContextGL::ALPHA: 337 case GraphicsContextGL::LUMINANCE: 338 case GraphicsContextGL::RED: 339 case GraphicsContextGL::RED_INTEGER: 340 case GraphicsContextGL::DEPTH_COMPONENT: 341 case GraphicsContextGL::DEPTH_STENCIL: // Treat it as one component. 342 *componentsPerPixel = 1; 343 break; 344 case GraphicsContextGL::LUMINANCE_ALPHA: 345 case GraphicsContextGL::RG: 346 case GraphicsContextGL::RG_INTEGER: 347 *componentsPerPixel = 2; 348 break; 349 case GraphicsContextGL::RGB: 350 case GraphicsContextGL::RGB_INTEGER: 351 case ExtensionsGL::SRGB_EXT: 352 *componentsPerPixel = 3; 353 break; 354 case GraphicsContextGL::RGBA: 355 case GraphicsContextGL::RGBA_INTEGER: 356 case ExtensionsGL::BGRA_EXT: // GL_EXT_texture_format_BGRA8888 357 case ExtensionsGL::SRGB_ALPHA_EXT: 358 *componentsPerPixel = 4; 359 break; 360 default: 361 return false; 362 } 363 364 switch (type) { 365 case GraphicsContextGL::BYTE: 366 *bytesPerComponent = sizeof(GCGLbyte); 367 break; 368 case GraphicsContextGL::UNSIGNED_BYTE: 369 *bytesPerComponent = sizeof(GCGLubyte); 370 break; 371 case GraphicsContextGL::SHORT: 372 *bytesPerComponent = sizeof(GCGLshort); 373 break; 374 case GraphicsContextGL::UNSIGNED_SHORT: 375 *bytesPerComponent = sizeof(GCGLushort); 376 break; 377 case GraphicsContextGL::UNSIGNED_SHORT_5_6_5: 378 case GraphicsContextGL::UNSIGNED_SHORT_4_4_4_4: 379 case GraphicsContextGL::UNSIGNED_SHORT_5_5_5_1: 380 *componentsPerPixel = 1; 381 *bytesPerComponent = sizeof(GCGLushort); 382 break; 383 case GraphicsContextGL::INT: 384 *bytesPerComponent = sizeof(GCGLint); 385 break; 386 case GraphicsContextGL::UNSIGNED_INT: 387 *bytesPerComponent = sizeof(GCGLuint); 388 break; 389 case GraphicsContextGL::UNSIGNED_INT_24_8: 390 case GraphicsContextGL::UNSIGNED_INT_10F_11F_11F_REV: 391 case GraphicsContextGL::UNSIGNED_INT_5_9_9_9_REV: 392 case GraphicsContextGL::UNSIGNED_INT_2_10_10_10_REV: 393 *componentsPerPixel = 1; 394 *bytesPerComponent = sizeof(GCGLuint); 395 break; 396 case GraphicsContextGL::FLOAT: // OES_texture_float 397 *bytesPerComponent = sizeof(GCGLfloat); 398 break; 399 case GraphicsContextGL::HALF_FLOAT: 400 case GraphicsContextGL::HALF_FLOAT_OES: // OES_texture_half_float 401 *bytesPerComponent = sizeof(GCGLhalffloat); 402 break; 403 case GraphicsContextGL::FLOAT_32_UNSIGNED_INT_24_8_REV: 404 *bytesPerComponent = sizeof(GCGLfloat) + sizeof(GCGLuint); 405 break; 406 default: 407 return false; 408 } 409 return true; 410 } 411 412 #if !USE(ANGLE) 413 bool GraphicsContextGLOpenGL::possibleFormatAndTypeForInternalFormat(GCGLenum internalFormat, GCGLenum& format, GCGLenum& type) 414 { 415 #define POSSIBLE_FORMAT_TYPE_CASE(internalFormatMacro, formatMacro, typeMacro) case internalFormatMacro: \ 416 format = formatMacro; \ 417 type = GraphicsContextGLOpenGL::typeMacro; \ 418 break; 419 420 switch (internalFormat) { 421 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB , GraphicsContextGL::RGB , UNSIGNED_BYTE ); 422 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA , GraphicsContextGL::RGBA , UNSIGNED_BYTE ); 423 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::LUMINANCE_ALPHA , GraphicsContextGL::LUMINANCE_ALPHA, UNSIGNED_BYTE ); 424 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::LUMINANCE , GraphicsContextGL::LUMINANCE , UNSIGNED_BYTE ); 425 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::ALPHA , GraphicsContextGL::ALPHA , UNSIGNED_BYTE ); 426 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R8 , GraphicsContextGL::RED , UNSIGNED_BYTE ); 427 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R8_SNORM , GraphicsContextGL::RED , BYTE ); 428 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R16F , GraphicsContextGL::RED , HALF_FLOAT ); 429 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R32F , GraphicsContextGL::RED , FLOAT ); 430 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R8UI , GraphicsContextGL::RED_INTEGER , UNSIGNED_BYTE ); 431 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R8I , GraphicsContextGL::RED_INTEGER , BYTE ); 432 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R16UI , GraphicsContextGL::RED_INTEGER , UNSIGNED_SHORT ); 433 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R16I , GraphicsContextGL::RED_INTEGER , SHORT ); 434 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R32UI , GraphicsContextGL::RED_INTEGER , UNSIGNED_INT ); 435 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R32I , GraphicsContextGL::RED_INTEGER , INT ); 436 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG8 , GraphicsContextGL::RG , UNSIGNED_BYTE ); 437 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG8_SNORM , GraphicsContextGL::RG , BYTE ); 438 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG16F , GraphicsContextGL::RG , HALF_FLOAT ); 439 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG32F , GraphicsContextGL::RG , FLOAT ); 440 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG8UI , GraphicsContextGL::RG_INTEGER , UNSIGNED_BYTE ); 441 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG8I , GraphicsContextGL::RG_INTEGER , BYTE ); 442 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG16UI , GraphicsContextGL::RG_INTEGER , UNSIGNED_SHORT ); 443 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG16I , GraphicsContextGL::RG_INTEGER , SHORT ); 444 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG32UI , GraphicsContextGL::RG_INTEGER , UNSIGNED_INT ); 445 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RG32I , GraphicsContextGL::RG_INTEGER , INT ); 446 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB8 , GraphicsContextGL::RGB , UNSIGNED_BYTE ); 447 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::SRGB8 , GraphicsContextGL::RGB , UNSIGNED_BYTE ); 448 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB565 , GraphicsContextGL::RGB , UNSIGNED_SHORT_5_6_5 ); 449 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB8_SNORM , GraphicsContextGL::RGB , BYTE ); 450 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::R11F_G11F_B10F , GraphicsContextGL::RGB , UNSIGNED_INT_10F_11F_11F_REV ); 451 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB9_E5 , GraphicsContextGL::RGB , UNSIGNED_INT_5_9_9_9_REV ); 452 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB16F , GraphicsContextGL::RGB , HALF_FLOAT ); 453 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB32F , GraphicsContextGL::RGB , FLOAT ); 454 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB8UI , GraphicsContextGL::RGB_INTEGER , UNSIGNED_BYTE ); 455 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB8I , GraphicsContextGL::RGB_INTEGER , BYTE ); 456 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB16UI , GraphicsContextGL::RGB_INTEGER , UNSIGNED_SHORT ); 457 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB16I , GraphicsContextGL::RGB_INTEGER , SHORT ); 458 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB32UI , GraphicsContextGL::RGB_INTEGER , UNSIGNED_INT ); 459 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB32I , GraphicsContextGL::RGB_INTEGER , INT ); 460 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA8 , GraphicsContextGL::RGBA , UNSIGNED_BYTE ); 461 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::SRGB8_ALPHA8 , GraphicsContextGL::RGBA , UNSIGNED_BYTE ); 462 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA8_SNORM , GraphicsContextGL::RGBA , BYTE ); 463 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB5_A1 , GraphicsContextGL::RGBA , UNSIGNED_SHORT_5_5_5_1 ); 464 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA4 , GraphicsContextGL::RGBA , UNSIGNED_SHORT_4_4_4_4 ); 465 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB10_A2 , GraphicsContextGL::RGBA , UNSIGNED_INT_2_10_10_10_REV ); 466 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA16F , GraphicsContextGL::RGBA , HALF_FLOAT ); 467 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA32F , GraphicsContextGL::RGBA , FLOAT ); 468 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA8UI , GraphicsContextGL::RGBA_INTEGER , UNSIGNED_BYTE ); 469 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA8I , GraphicsContextGL::RGBA_INTEGER , BYTE ); 470 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGB10_A2UI , GraphicsContextGL::RGBA_INTEGER , UNSIGNED_INT_2_10_10_10_REV ); 471 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA16UI , GraphicsContextGL::RGBA_INTEGER , UNSIGNED_SHORT ); 472 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA16I , GraphicsContextGL::RGBA_INTEGER , SHORT ); 473 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA32I , GraphicsContextGL::RGBA_INTEGER , INT ); 474 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::RGBA32UI , GraphicsContextGL::RGBA_INTEGER , UNSIGNED_INT ); 475 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_COMPONENT16 , GraphicsContextGL::DEPTH_COMPONENT, UNSIGNED_SHORT ); 476 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_COMPONENT , GraphicsContextGL::DEPTH_COMPONENT, UNSIGNED_SHORT ); 477 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_COMPONENT24 , GraphicsContextGL::DEPTH_COMPONENT, UNSIGNED_INT ); 478 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_COMPONENT32F, GraphicsContextGL::DEPTH_COMPONENT, FLOAT ); 479 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH_STENCIL , GraphicsContextGL::DEPTH_STENCIL , UNSIGNED_INT_24_8 ); 480 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH24_STENCIL8 , GraphicsContextGL::DEPTH_STENCIL , UNSIGNED_INT_24_8 ); 481 POSSIBLE_FORMAT_TYPE_CASE(GraphicsContextGL::DEPTH32F_STENCIL8 , GraphicsContextGL::DEPTH_STENCIL , FLOAT_32_UNSIGNED_INT_24_8_REV); 482 POSSIBLE_FORMAT_TYPE_CASE(ExtensionsGL::SRGB_EXT , ExtensionsGL::SRGB_EXT , UNSIGNED_BYTE ); 483 POSSIBLE_FORMAT_TYPE_CASE(ExtensionsGL::SRGB_ALPHA_EXT , ExtensionsGL::SRGB_ALPHA_EXT , UNSIGNED_BYTE ); 484 default: 485 return false; 486 } 487 #undef POSSIBLE_FORMAT_TYPE_CASE 488 489 return true; 490 } 491 #endif // !USE(ANGLE) 492 493 GCGLenum GraphicsContextGLOpenGL::computeImageSizeInBytes( 494 GCGLenum format, GCGLenum type, GCGLsizei width, GCGLsizei height, GCGLsizei depth, const GraphicsContextGLOpenGL::PixelStoreParams& params, 495 unsigned* imageSizeInBytes, unsigned* paddingInBytes, unsigned* skipSizeInBytes) 496 { 497 ASSERT(imageSizeInBytes); 498 ASSERT(params.alignment == 1 || params.alignment == 2 || params.alignment == 4 || params.alignment == 8); 499 ASSERT(params.rowLength >= 0); 500 ASSERT(params.imageHeight >= 0); 501 ASSERT(params.skipPixels >= 0); 502 ASSERT(params.skipRows >= 0); 503 ASSERT(params.skipImages >= 0); 504 if (width < 0 || height < 0 || depth < 0) 505 return GraphicsContextGL::INVALID_VALUE; 506 if (!width || !height || !depth) { 507 *imageSizeInBytes = 0; 508 if (paddingInBytes) 509 *paddingInBytes = 0; 510 if (skipSizeInBytes) 511 *skipSizeInBytes = 0; 512 return GraphicsContextGL::NO_ERROR; 513 } 514 515 int rowLength = params.rowLength > 0 ? params.rowLength : width; 516 int imageHeight = params.imageHeight > 0 ? params.imageHeight : height; 517 518 unsigned bytesPerComponent, componentsPerPixel; 519 if (!computeFormatAndTypeParameters(format, type, &componentsPerPixel, &bytesPerComponent)) 520 return GraphicsContextGL::INVALID_ENUM; 521 unsigned bytesPerGroup = bytesPerComponent * componentsPerPixel; 522 Checked<uint32_t, RecordOverflow> checkedValue = static_cast<uint32_t>(rowLength); 523 checkedValue *= bytesPerGroup; 524 if (checkedValue.hasOverflowed()) 525 return GraphicsContextGL::INVALID_VALUE; 526 527 unsigned lastRowSize; 528 if (params.rowLength > 0 && params.rowLength != width) { 529 Checked<uint32_t, RecordOverflow> tmp = width; 530 tmp *= bytesPerGroup; 531 if (tmp.hasOverflowed()) 532 return GraphicsContextGL::INVALID_VALUE; 533 lastRowSize = tmp.unsafeGet(); 534 } else 535 lastRowSize = checkedValue.unsafeGet(); 536 537 unsigned padding = 0; 538 unsigned residual = checkedValue.unsafeGet() % params.alignment; 539 if (residual) { 540 padding = params.alignment - residual; 541 checkedValue += padding; 542 } 543 if (checkedValue.hasOverflowed()) 544 return GraphicsContextGL::INVALID_VALUE; 545 unsigned paddedRowSize = checkedValue.unsafeGet(); 546 547 Checked<uint32_t, RecordOverflow> rows = imageHeight; 548 rows *= (depth - 1); 549 // Last image is not affected by IMAGE_HEIGHT parameter. 550 rows += height; 551 if (rows.hasOverflowed()) 552 return GraphicsContextGL::INVALID_VALUE; 553 checkedValue *= (rows - 1); 554 // Last row is not affected by ROW_LENGTH parameter. 555 checkedValue += lastRowSize; 556 if (checkedValue.hasOverflowed()) 557 return GraphicsContextGL::INVALID_VALUE; 558 *imageSizeInBytes = checkedValue.unsafeGet(); 559 if (paddingInBytes) 560 *paddingInBytes = padding; 561 562 Checked<uint32_t, RecordOverflow> skipSize = 0; 563 if (params.skipImages > 0) { 564 Checked<uint32_t, RecordOverflow> tmp = paddedRowSize; 565 tmp *= imageHeight; 566 tmp *= params.skipImages; 567 if (tmp.hasOverflowed()) 568 return GraphicsContextGL::INVALID_VALUE; 569 skipSize += tmp.unsafeGet(); 570 } 571 if (params.skipRows > 0) { 572 Checked<uint32_t, RecordOverflow> tmp = paddedRowSize; 573 tmp *= params.skipRows; 574 if (tmp.hasOverflowed()) 575 return GraphicsContextGL::INVALID_VALUE; 576 skipSize += tmp.unsafeGet(); 577 } 578 if (params.skipPixels > 0) { 579 Checked<uint32_t, RecordOverflow> tmp = bytesPerGroup; 580 tmp *= params.skipPixels; 581 if (tmp.hasOverflowed()) 582 return GraphicsContextGL::INVALID_VALUE; 583 skipSize += tmp.unsafeGet(); 584 } 585 if (skipSize.hasOverflowed()) 586 return GraphicsContextGL::INVALID_VALUE; 587 if (skipSizeInBytes) 588 *skipSizeInBytes = skipSize.unsafeGet(); 589 590 checkedValue += skipSize.unsafeGet(); 591 if (checkedValue.hasOverflowed()) 592 return GraphicsContextGL::INVALID_VALUE; 593 return GraphicsContextGL::NO_ERROR; 594 } 595 596 GraphicsContextGLOpenGL::PixelStoreParams::PixelStoreParams() 597 : alignment(4) 598 , rowLength(0) 599 , imageHeight(0) 600 , skipPixels(0) 601 , skipRows(0) 602 , skipImages(0) 603 { 604 } 605 606 GraphicsContextGLOpenGL::ImageExtractor::ImageExtractor(Image* image, DOMSource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication) 607 { 608 m_image = image; 609 m_imageHtmlDomSource = imageHtmlDomSource; 610 m_extractSucceeded = extractImage(premultiplyAlpha, ignoreGammaAndColorProfile, ignoreNativeImageAlphaPremultiplication); 611 } 612 613 bool GraphicsContextGLOpenGL::packImageData(Image* image, const void* pixels, GCGLenum format, GCGLenum type, bool flipY, AlphaOp alphaOp, DataFormat sourceFormat, unsigned sourceImageWidth, unsigned sourceImageHeight, const IntRect& sourceImageSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, Vector<uint8_t>& data) 614 { 615 if (!image || !pixels) 616 return false; 617 618 unsigned packedSize; 619 // Output data is tightly packed (alignment == 1). 620 PixelStoreParams params; 621 params.alignment = 1; 622 if (computeImageSizeInBytes(format, type, sourceImageSubRectangle.width(), sourceImageSubRectangle.height(), depth, params, &packedSize, nullptr, nullptr) != GraphicsContextGL::NO_ERROR) 623 return false; 624 data.resize(packedSize); 625 626 if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, sourceImageWidth, sourceImageHeight, sourceImageSubRectangle, depth, sourceUnpackAlignment, unpackImageHeight, format, type, alphaOp, data.data(), flipY)) 627 return false; 628 if (ImageObserver* observer = image->imageObserver()) 629 observer->didDraw(*image); 630 return true; 631 } 632 633 bool GraphicsContextGLOpenGL::extractImageData( 634 ImageData* imageData, DataFormat sourceDataFormat, const IntRect& sourceImageSubRectangle, 635 int depth, int unpackImageHeight, GCGLenum format, GCGLenum type, bool flipY, bool premultiplyAlpha, Vector<uint8_t>& data) 636 { 637 if (!imageData) 638 return false; 639 int width = imageData->width(); 640 int height = imageData->height(); 641 642 unsigned packedSize; 643 // Output data is tightly packed (alignment == 1). 644 PixelStoreParams params; 645 params.alignment = 1; 646 if (computeImageSizeInBytes(format, type, sourceImageSubRectangle.width(), sourceImageSubRectangle.height(), depth, params, &packedSize, nullptr, nullptr) != GraphicsContextGL::NO_ERROR) 647 return false; 648 data.resize(packedSize); 649 650 if (!packPixels(imageData->data()->data(), sourceDataFormat, width, height, sourceImageSubRectangle, depth, 0, unpackImageHeight, format, type, premultiplyAlpha ? AlphaOp::DoPremultiply : AlphaOp::DoNothing, data.data(), flipY)) 651 return false; 652 653 return true; 654 } 655 656 bool GraphicsContextGLOpenGL::extractTextureData(unsigned width, unsigned height, GCGLenum format, GCGLenum type, const PixelStoreParams& unpackParams, bool flipY, bool premultiplyAlpha, const void* pixels, Vector<uint8_t>& data) 657 { 658 // Assumes format, type, etc. have already been validated. 659 DataFormat sourceDataFormat = getDataFormat(format, type); 660 661 // Resize the output buffer. 662 unsigned componentsPerPixel, bytesPerComponent; 663 if (!computeFormatAndTypeParameters(format, type, &componentsPerPixel, &bytesPerComponent)) 664 return false; 665 unsigned bytesPerPixel = componentsPerPixel * bytesPerComponent; 666 data.resize(width * height * bytesPerPixel); 667 668 unsigned imageSizeInBytes, skipSizeInBytes; 669 computeImageSizeInBytes(format, type, width, height, 1, unpackParams, &imageSizeInBytes, nullptr, &skipSizeInBytes); 670 const uint8_t* srcData = static_cast<const uint8_t*>(pixels); 671 if (skipSizeInBytes) 672 srcData += skipSizeInBytes; 673 674 if (!packPixels(srcData, sourceDataFormat, unpackParams.rowLength ? unpackParams.rowLength : width, height, IntRect(0, 0, width, height), 1, unpackParams.alignment, 0, format, type, (premultiplyAlpha ? AlphaOp::DoPremultiply : AlphaOp::DoNothing), data.data(), flipY)) 675 return false; 676 677 return true; 678 } 679 680 ALWAYS_INLINE unsigned TexelBytesForFormat(GraphicsContextGL::DataFormat format) 681 { 682 switch (format) { 683 case GraphicsContextGL::DataFormat::R8: 684 case GraphicsContextGL::DataFormat::R8_S: 685 case GraphicsContextGL::DataFormat::A8: 686 return 1; 687 case GraphicsContextGL::DataFormat::RG8: 688 case GraphicsContextGL::DataFormat::RG8_S: 689 case GraphicsContextGL::DataFormat::RA8: 690 case GraphicsContextGL::DataFormat::AR8: 691 case GraphicsContextGL::DataFormat::RGBA5551: 692 case GraphicsContextGL::DataFormat::RGBA4444: 693 case GraphicsContextGL::DataFormat::RGB565: 694 case GraphicsContextGL::DataFormat::A16F: 695 case GraphicsContextGL::DataFormat::R16: 696 case GraphicsContextGL::DataFormat::R16_S: 697 case GraphicsContextGL::DataFormat::R16F: 698 case GraphicsContextGL::DataFormat::D16: 699 return 2; 700 case GraphicsContextGL::DataFormat::RGB8: 701 case GraphicsContextGL::DataFormat::RGB8_S: 702 case GraphicsContextGL::DataFormat::BGR8: 703 return 3; 704 case GraphicsContextGL::DataFormat::RGBA8: 705 case GraphicsContextGL::DataFormat::RGBA8_S: 706 case GraphicsContextGL::DataFormat::ARGB8: 707 case GraphicsContextGL::DataFormat::ABGR8: 708 case GraphicsContextGL::DataFormat::BGRA8: 709 case GraphicsContextGL::DataFormat::R32: 710 case GraphicsContextGL::DataFormat::R32_S: 711 case GraphicsContextGL::DataFormat::R32F: 712 case GraphicsContextGL::DataFormat::A32F: 713 case GraphicsContextGL::DataFormat::RA16F: 714 case GraphicsContextGL::DataFormat::RGBA2_10_10_10: 715 case GraphicsContextGL::DataFormat::RGB10F11F11F: 716 case GraphicsContextGL::DataFormat::RGB5999: 717 case GraphicsContextGL::DataFormat::RG16: 718 case GraphicsContextGL::DataFormat::RG16_S: 719 case GraphicsContextGL::DataFormat::RG16F: 720 case GraphicsContextGL::DataFormat::D32: 721 case GraphicsContextGL::DataFormat::D32F: 722 case GraphicsContextGL::DataFormat::DS24_8: 723 return 4; 724 case GraphicsContextGL::DataFormat::RGB16: 725 case GraphicsContextGL::DataFormat::RGB16_S: 726 case GraphicsContextGL::DataFormat::RGB16F: 727 return 6; 728 case GraphicsContextGL::DataFormat::RGBA16: 729 case GraphicsContextGL::DataFormat::RGBA16_S: 730 case GraphicsContextGL::DataFormat::RA32F: 731 case GraphicsContextGL::DataFormat::RGBA16F: 732 case GraphicsContextGL::DataFormat::RG32: 733 case GraphicsContextGL::DataFormat::RG32_S: 734 case GraphicsContextGL::DataFormat::RG32F: 735 return 8; 736 case GraphicsContextGL::DataFormat::RGB32: 737 case GraphicsContextGL::DataFormat::RGB32_S: 738 case GraphicsContextGL::DataFormat::RGB32F: 739 return 12; 740 case GraphicsContextGL::DataFormat::RGBA32: 741 case GraphicsContextGL::DataFormat::RGBA32_S: 742 case GraphicsContextGL::DataFormat::RGBA32F: 743 return 16; 744 default: 745 return 0; 746 } 747 } 748 749 bool GraphicsContextGLOpenGL::packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned sourceDataWidth, unsigned sourceDataHeight, const IntRect& sourceDataSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, unsigned destinationFormat, unsigned destinationType, AlphaOp alphaOp, void* destinationData, bool flipY) 750 { 751 ASSERT(depth >= 1); 752 UNUSED_PARAM(sourceDataHeight); // Derived from sourceDataSubRectangle.height(). 753 if (!unpackImageHeight) 754 unpackImageHeight = sourceDataSubRectangle.height(); 755 int validSrc = sourceDataWidth * TexelBytesForFormat(sourceDataFormat); 756 int remainder = sourceUnpackAlignment ? (validSrc % sourceUnpackAlignment) : 0; 757 int srcStride = remainder ? (validSrc + sourceUnpackAlignment - remainder) : validSrc; 758 int srcRowOffset = sourceDataSubRectangle.x() * TexelBytesForFormat(sourceDataFormat); 759 760 DataFormat dstDataFormat = getDataFormat(destinationFormat, destinationType); 761 int dstStride = sourceDataSubRectangle.width() * TexelBytesForFormat(dstDataFormat); 762 if (flipY) { 763 destinationData = static_cast<uint8_t*>(destinationData) + dstStride * ((depth * sourceDataSubRectangle.height()) - 1); 764 dstStride = -dstStride; 765 } 766 if (!hasAlpha(sourceDataFormat) || !hasColor(sourceDataFormat) || !hasColor(dstDataFormat)) 767 alphaOp = AlphaOp::DoNothing; 768 769 if (sourceDataFormat == dstDataFormat && alphaOp == AlphaOp::DoNothing) { 770 const uint8_t* basePtr = sourceData + srcStride * sourceDataSubRectangle.y(); 771 const uint8_t* baseEnd = sourceData + srcStride * sourceDataSubRectangle.maxY(); 772 773 // If packing multiple images into a 3D texture, and flipY is true, 774 // then the sub-rectangle is pointing at the start of the 775 // "bottommost" of those images. Since the source pointer strides in 776 // the positive direction, we need to back it up to point at the 777 // last, or "topmost", of these images. 778 if (flipY && depth > 1) { 779 const ptrdiff_t distanceToTopImage = (depth - 1) * srcStride * unpackImageHeight; 780 basePtr -= distanceToTopImage; 781 baseEnd -= distanceToTopImage; 782 } 783 784 unsigned rowSize = (dstStride > 0) ? dstStride: -dstStride; 785 uint8_t* dst = static_cast<uint8_t*>(destinationData); 786 787 for (int i = 0; i < depth; ++i) { 788 const uint8_t* ptr = basePtr; 789 const uint8_t* ptrEnd = baseEnd; 790 while (ptr < ptrEnd) { 791 memcpy(dst, ptr + srcRowOffset, rowSize); 792 ptr += srcStride; 793 dst += dstStride; 794 } 795 basePtr += unpackImageHeight * srcStride; 796 baseEnd += unpackImageHeight * srcStride; 797 } 798 return true; 799 } 800 801 FormatConverter converter( 802 sourceDataSubRectangle, depth, 803 unpackImageHeight, sourceData, destinationData, 804 srcStride, srcRowOffset, dstStride); 805 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); 806 if (!converter.success()) 807 return false; 808 return true; 809 } 99 810 100 811 #if !PLATFORM(COCOA) -
branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h
r268578 r268755 88 88 class GraphicsContextGLOpenGLPrivate; 89 89 90 class GraphicsContextGLOpenGL final: public GraphicsContextGL90 class GraphicsContextGLOpenGL : 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 96 105 static RefPtr<GraphicsContextGLOpenGL> create(GraphicsContextGLAttributes, HostWindow*, Destination = Destination::Offscreen); 97 106 virtual ~GraphicsContextGLOpenGL(); … … 99 108 #if PLATFORM(COCOA) 100 109 static Ref<GraphicsContextGLOpenGL> createShared(GraphicsContextGLOpenGL& sharedContext); 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()); }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()); } 104 113 PlatformGraphicsContextGLDisplay platformDisplay() const { return m_displayObj; } 105 114 PlatformGraphicsContextGLConfig platformConfig() const { return m_configObj; } … … 122 131 #endif 123 132 133 void addClient(Client& client) { m_clients.add(&client); } 134 void removeClient(Client& client) { m_clients.remove(&client); } 135 124 136 // With multisampling on, blit from multisampleFBO to regular FBO. 125 137 void prepareTexture(); … … 134 146 void compileShaderDirect(PlatformGLObject); 135 147 148 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. 149 // Return true if no GL error is synthesized. 150 // By default, alignment is 4, the OpenGL default setting. 151 bool texImage2DResourceSafe(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLint alignment = 4); 152 153 bool isGLES2Compliant() const; 154 155 //---------------------------------------------------------------------- 156 // Helpers for texture uploading and pixel readback. 157 // 158 159 struct PixelStoreParams final { 160 PixelStoreParams(); 161 162 GCGLint alignment; 163 GCGLint rowLength; 164 GCGLint imageHeight; 165 GCGLint skipPixels; 166 GCGLint skipRows; 167 GCGLint skipImages; 168 }; 169 170 // Computes the components per pixel and bytes per component 171 // for the given format and type combination. Returns false if 172 // either was an invalid enum. 173 static bool computeFormatAndTypeParameters(GCGLenum format, 174 GCGLenum type, 175 unsigned* componentsPerPixel, 176 unsigned* bytesPerComponent); 177 178 // Computes the image size in bytes. If paddingInBytes is not null, padding 179 // is also calculated in return. Returns NO_ERROR if succeed, otherwise 180 // return the suggested GL error indicating the cause of the failure: 181 // INVALID_VALUE if width/height is negative or overflow happens. 182 // INVALID_ENUM if format/type is illegal. 183 static GCGLenum computeImageSizeInBytes(GCGLenum format, 184 GCGLenum type, 185 GCGLsizei width, 186 GCGLsizei height, 187 GCGLsizei depth, 188 const PixelStoreParams&, 189 unsigned* imageSizeInBytes, 190 unsigned* paddingInBytes, 191 unsigned* skipSizeInBytes); 192 136 193 #if !USE(ANGLE) 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; 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); 141 223 142 224 //---------------------------------------------------------------------- … … 456 538 void setBuffersToAutoClear(GCGLbitfield); 457 539 GCGLbitfield getBuffersToAutoClear() const; 458 void enablePreserveDrawingBuffer() final;540 void enablePreserveDrawingBuffer() override; 459 541 460 542 void dispatchContextChangedNotification(); … … 469 551 #endif 470 552 471 #if PLATFORM(COCOA) && PLATFORM(MAC) 553 #if PLATFORM(COCOA) 554 bool reshapeDisplayBufferBacking(); 555 bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer); 556 #if PLATFORM(MAC) 472 557 void updateCGLContext(); 473 558 #endif 474 475 void setContextVisibility(bool) final; 476 477 GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const final { return m_powerPreferenceUsedForCreation; } 559 #endif // PLATFORM(COCOA) 560 561 void setContextVisibility(bool); 562 563 GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const { return m_powerPreferenceUsedForCreation; } 478 564 479 565 // Support for buffer creation and deletion … … 492 578 void deleteTexture(PlatformGLObject) final; 493 579 494 void synthesizeGLError(GCGLenum error) final; 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); 495 589 496 590 // Read real OpenGL errors, and move them to the synthetic … … 504 598 ExtensionsGL& getExtensions() final; 505 599 506 void setFailNextGPUStatusCheck() final { m_failNextStatusCheck = true; } 507 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(); } 508 653 unsigned textureSeed(GCGLuint texture) { return m_state.textureSeedCount.count(texture); } 509 654 … … 513 658 #endif 514 659 515 void prepareForDisplay() final;660 void prepareForDisplay(); 516 661 517 662 private: 518 663 GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, Destination = Destination::Offscreen, GraphicsContextGLOpenGL* sharedContext = nullptr); 519 664 665 // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel 666 // data into the specified OpenGL destination format and type. 667 // A sourceUnpackAlignment of zero indicates that the source 668 // data is tightly packed. Non-zero values may take a slow path. 669 // Destination data will have no gaps between rows. 670 static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned sourceDataWidth, unsigned sourceDataHeight, const IntRect& sourceDataSubRectangle, int depth, unsigned sourceUnpackAlignment, int unpackImageHeight, unsigned destinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool flipY); 520 671 521 672 // Take into account the user's requested context creation attributes, … … 545 696 #if PLATFORM(COCOA) 546 697 bool allowOfflineRenderers() const; 547 bool reshapeDisplayBufferBacking();548 bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer);549 698 // WebGLLayerClient overrides. 550 void didDisplay() final; 551 #endif 699 void didDisplay() override; 700 #endif 701 702 int m_currentWidth { 0 }; 703 int m_currentHeight { 0 }; 552 704 553 705 #if PLATFORM(COCOA) … … 737 889 #endif 738 890 891 HashSet<Client*> m_clients; 892 739 893 bool m_isForWebGL2 { false }; 740 894 bool m_usingCoreProfile { false }; -
branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLCommon.cpp
r268578 r268755 426 426 } 427 427 428 IntSize GraphicsContextGLOpenGL::getInternalFramebufferSize() const 429 { 430 return IntSize(m_currentWidth, m_currentHeight); 431 } 432 428 433 void GraphicsContextGLOpenGL::activeTexture(GCGLenum texture) 429 434 { -
branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/win/GraphicsContextGLDirect2D.cpp
r268578 r268755 30 30 31 31 #include "COMPtr.h" 32 #include "GraphicsContextGLImageExtractor.h"33 32 #include "NotImplemented.h" 34 33 #include <d2d1.h> … … 37 36 namespace WebCore { 38 37 39 GraphicsContextGL ImageExtractor::~GraphicsContextGLImageExtractor() = default;38 GraphicsContextGLOpenGL::ImageExtractor::~ImageExtractor() = default; 40 39 41 bool GraphicsContextGL ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication)40 bool GraphicsContextGLOpenGL::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile, bool ignoreNativeImageAlphaPremultiplication) 42 41 { 43 42 if (!m_image)
Note:
See TracChangeset
for help on using the changeset viewer.