OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WebGLImageConversion_h | 5 #ifndef WebGLImageConversion_h |
6 #define WebGLImageConversion_h | 6 #define WebGLImageConversion_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/graphics/Image.h" | 9 #include "platform/graphics/Image.h" |
10 #include "platform/graphics/skia/ImagePixelLocker.h" | 10 #include "platform/graphics/skia/ImagePixelLocker.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 AlphaDoUnmultiply = 2 | 108 AlphaDoUnmultiply = 2 |
109 }; | 109 }; |
110 | 110 |
111 enum ImageHtmlDomSource { | 111 enum ImageHtmlDomSource { |
112 HtmlDomImage = 0, | 112 HtmlDomImage = 0, |
113 HtmlDomCanvas = 1, | 113 HtmlDomCanvas = 1, |
114 HtmlDomVideo = 2, | 114 HtmlDomVideo = 2, |
115 HtmlDomNone = 3 | 115 HtmlDomNone = 3 |
116 }; | 116 }; |
117 | 117 |
| 118 struct PLATFORM_EXPORT PixelStoreParams final { |
| 119 PixelStoreParams(); |
| 120 |
| 121 GLint alignment; |
| 122 GLint rowLength; |
| 123 GLint imageHeight; |
| 124 GLint skipPixels; |
| 125 GLint skipRows; |
| 126 GLint skipImages; |
| 127 }; |
| 128 |
118 class PLATFORM_EXPORT ImageExtractor final { | 129 class PLATFORM_EXPORT ImageExtractor final { |
119 STACK_ALLOCATED(); | 130 STACK_ALLOCATED(); |
120 public: | 131 public: |
121 ImageExtractor(Image*, ImageHtmlDomSource, bool premultiplyAlpha, bool i
gnoreGammaAndColorProfile); | 132 ImageExtractor(Image*, ImageHtmlDomSource, bool premultiplyAlpha, bool i
gnoreGammaAndColorProfile); |
122 | 133 |
123 const void* imagePixelData() { return m_imagePixelLocker ? m_imagePixelL
ocker->pixels() : nullptr; } | 134 const void* imagePixelData() { return m_imagePixelLocker ? m_imagePixelL
ocker->pixels() : nullptr; } |
124 unsigned imageWidth() { return m_imageWidth; } | 135 unsigned imageWidth() { return m_imageWidth; } |
125 unsigned imageHeight() { return m_imageHeight; } | 136 unsigned imageHeight() { return m_imageHeight; } |
126 DataFormat imageSourceFormat() { return m_imageSourceFormat; } | 137 DataFormat imageSourceFormat() { return m_imageSourceFormat; } |
127 AlphaOp imageAlphaOp() { return m_alphaOp; } | 138 AlphaOp imageAlphaOp() { return m_alphaOp; } |
(...skipping 17 matching lines...) Expand all Loading... |
145 // Computes the components per pixel and bytes per component | 156 // Computes the components per pixel and bytes per component |
146 // for the given format and type combination. Returns false if | 157 // for the given format and type combination. Returns false if |
147 // either was an invalid enum. | 158 // either was an invalid enum. |
148 static bool computeFormatAndTypeParameters(GLenum format, GLenum type, unsig
ned* componentsPerPixel, unsigned* bytesPerComponent); | 159 static bool computeFormatAndTypeParameters(GLenum format, GLenum type, unsig
ned* componentsPerPixel, unsigned* bytesPerComponent); |
149 | 160 |
150 // Computes the image size in bytes. If paddingInBytes is not null, padding | 161 // Computes the image size in bytes. If paddingInBytes is not null, padding |
151 // is also calculated in return. Returns NO_ERROR if succeed, otherwise | 162 // is also calculated in return. Returns NO_ERROR if succeed, otherwise |
152 // return the suggested GL error indicating the cause of the failure: | 163 // return the suggested GL error indicating the cause of the failure: |
153 // INVALID_VALUE if width/height/depth is negative or overflow happens. | 164 // INVALID_VALUE if width/height/depth is negative or overflow happens. |
154 // INVALID_ENUM if format/type is illegal. | 165 // INVALID_ENUM if format/type is illegal. |
155 static GLenum computeImageSizeInBytes(GLenum format, GLenum type, GLsizei wi
dth, GLsizei height, GLsizei depth, GLint alignment, unsigned* imageSizeInBytes,
unsigned* paddingInBytes); | 166 // Note that imageSizeBytes does not include skipSizeInBytes, but it is |
| 167 // guaranteed if NO_ERROR is returned, adding the two sizes won't cause |
| 168 // overflow. |
| 169 // |paddingInBytes| and |skipSizeInBytes| are optional and can be null, but |
| 170 // the overflow validation is still performed. |
| 171 static GLenum computeImageSizeInBytes(GLenum format, GLenum type, GLsizei wi
dth, GLsizei height, GLsizei depth, const PixelStoreParams&, unsigned* imageSize
InBytes, unsigned* paddingInBytes, unsigned* skipSizeInBytes); |
156 | 172 |
157 // Check if the format is one of the formats from the ImageData or DOM eleme
nts. | 173 // Check if the format is one of the formats from the ImageData or DOM eleme
nts. |
158 // The formats from ImageData is always RGBA8. | 174 // The formats from ImageData is always RGBA8. |
159 // The formats from DOM elements vary with Graphics ports. It can only be RG
BA8 or BGRA8. | 175 // The formats from DOM elements vary with Graphics ports. It can only be RG
BA8 or BGRA8. |
160 static ALWAYS_INLINE bool srcFormatComeFromDOMElementOrImageData(DataFormat
SrcFormat) | 176 static ALWAYS_INLINE bool srcFormatComeFromDOMElementOrImageData(DataFormat
SrcFormat) |
161 { | 177 { |
162 return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8; | 178 return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8; |
163 } | 179 } |
164 | 180 |
165 // The input can be either format or internalformat. | 181 // The input can be either format or internalformat. |
(...skipping 27 matching lines...) Expand all Loading... |
193 // A sourceUnpackAlignment of zero indicates that the source | 209 // A sourceUnpackAlignment of zero indicates that the source |
194 // data is tightly packed. Non-zero values may take a slow path. | 210 // data is tightly packed. Non-zero values may take a slow path. |
195 // Destination data will have no gaps between rows. | 211 // Destination data will have no gaps between rows. |
196 // Implemented in GraphicsContext3DImagePacking.cpp | 212 // Implemented in GraphicsContext3DImagePacking.cpp |
197 static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataForma
t, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned des
tinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool f
lipY); | 213 static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataForma
t, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned des
tinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool f
lipY); |
198 }; | 214 }; |
199 | 215 |
200 } // namespace blink | 216 } // namespace blink |
201 | 217 |
202 #endif // WebGLImageConversion_h | 218 #endif // WebGLImageConversion_h |
OLD | NEW |