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 #include "platform/graphics/gpu/WebGLImageConversion.h" | 5 #include "platform/graphics/gpu/WebGLImageConversion.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "platform/graphics/ImageObserver.h" | 8 #include "platform/graphics/ImageObserver.h" |
9 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 9 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" |
10 #include "platform/graphics/cpu/mips/WebGLImageConversionMSA.h" | 10 #include "platform/graphics/cpu/mips/WebGLImageConversionMSA.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 break; | 58 break; |
59 case GL_RGB: | 59 case GL_RGB: |
60 case GL_RGB_INTEGER: | 60 case GL_RGB_INTEGER: |
61 dst_format = WebGLImageConversion::kDataFormatRGB8_S; | 61 dst_format = WebGLImageConversion::kDataFormatRGB8_S; |
62 break; | 62 break; |
63 case GL_RGBA: | 63 case GL_RGBA: |
64 case GL_RGBA_INTEGER: | 64 case GL_RGBA_INTEGER: |
65 dst_format = WebGLImageConversion::kDataFormatRGBA8_S; | 65 dst_format = WebGLImageConversion::kDataFormatRGBA8_S; |
66 break; | 66 break; |
67 default: | 67 default: |
68 ASSERT_NOT_REACHED(); | 68 NOTREACHED(); |
69 } | 69 } |
70 break; | 70 break; |
71 case GL_UNSIGNED_BYTE: | 71 case GL_UNSIGNED_BYTE: |
72 switch (destination_format) { | 72 switch (destination_format) { |
73 case GL_RGB: | 73 case GL_RGB: |
74 case GL_RGB_INTEGER: | 74 case GL_RGB_INTEGER: |
75 case GL_SRGB_EXT: | 75 case GL_SRGB_EXT: |
76 dst_format = WebGLImageConversion::kDataFormatRGB8; | 76 dst_format = WebGLImageConversion::kDataFormatRGB8; |
77 break; | 77 break; |
78 case GL_RGBA: | 78 case GL_RGBA: |
(...skipping 10 matching lines...) Expand all Loading... |
89 dst_format = WebGLImageConversion::kDataFormatR8; | 89 dst_format = WebGLImageConversion::kDataFormatR8; |
90 break; | 90 break; |
91 case GL_RG: | 91 case GL_RG: |
92 case GL_RG_INTEGER: | 92 case GL_RG_INTEGER: |
93 dst_format = WebGLImageConversion::kDataFormatRG8; | 93 dst_format = WebGLImageConversion::kDataFormatRG8; |
94 break; | 94 break; |
95 case GL_LUMINANCE_ALPHA: | 95 case GL_LUMINANCE_ALPHA: |
96 dst_format = WebGLImageConversion::kDataFormatRA8; | 96 dst_format = WebGLImageConversion::kDataFormatRA8; |
97 break; | 97 break; |
98 default: | 98 default: |
99 ASSERT_NOT_REACHED(); | 99 NOTREACHED(); |
100 } | 100 } |
101 break; | 101 break; |
102 case GL_SHORT: | 102 case GL_SHORT: |
103 switch (destination_format) { | 103 switch (destination_format) { |
104 case GL_RED_INTEGER: | 104 case GL_RED_INTEGER: |
105 dst_format = WebGLImageConversion::kDataFormatR16_S; | 105 dst_format = WebGLImageConversion::kDataFormatR16_S; |
106 break; | 106 break; |
107 case GL_RG_INTEGER: | 107 case GL_RG_INTEGER: |
108 dst_format = WebGLImageConversion::kDataFormatRG16_S; | 108 dst_format = WebGLImageConversion::kDataFormatRG16_S; |
109 break; | 109 break; |
110 case GL_RGB_INTEGER: | 110 case GL_RGB_INTEGER: |
111 dst_format = WebGLImageConversion::kDataFormatRGB16_S; | 111 dst_format = WebGLImageConversion::kDataFormatRGB16_S; |
112 case GL_RGBA_INTEGER: | 112 case GL_RGBA_INTEGER: |
113 dst_format = WebGLImageConversion::kDataFormatRGBA16_S; | 113 dst_format = WebGLImageConversion::kDataFormatRGBA16_S; |
114 default: | 114 default: |
115 ASSERT_NOT_REACHED(); | 115 NOTREACHED(); |
116 } | 116 } |
117 break; | 117 break; |
118 case GL_UNSIGNED_SHORT: | 118 case GL_UNSIGNED_SHORT: |
119 switch (destination_format) { | 119 switch (destination_format) { |
120 case GL_RED_INTEGER: | 120 case GL_RED_INTEGER: |
121 dst_format = WebGLImageConversion::kDataFormatR16; | 121 dst_format = WebGLImageConversion::kDataFormatR16; |
122 break; | 122 break; |
123 case GL_DEPTH_COMPONENT: | 123 case GL_DEPTH_COMPONENT: |
124 dst_format = WebGLImageConversion::kDataFormatD16; | 124 dst_format = WebGLImageConversion::kDataFormatD16; |
125 break; | 125 break; |
126 case GL_RG_INTEGER: | 126 case GL_RG_INTEGER: |
127 dst_format = WebGLImageConversion::kDataFormatRG16; | 127 dst_format = WebGLImageConversion::kDataFormatRG16; |
128 break; | 128 break; |
129 case GL_RGB_INTEGER: | 129 case GL_RGB_INTEGER: |
130 dst_format = WebGLImageConversion::kDataFormatRGB16; | 130 dst_format = WebGLImageConversion::kDataFormatRGB16; |
131 break; | 131 break; |
132 case GL_RGBA_INTEGER: | 132 case GL_RGBA_INTEGER: |
133 dst_format = WebGLImageConversion::kDataFormatRGBA16; | 133 dst_format = WebGLImageConversion::kDataFormatRGBA16; |
134 break; | 134 break; |
135 default: | 135 default: |
136 ASSERT_NOT_REACHED(); | 136 NOTREACHED(); |
137 } | 137 } |
138 break; | 138 break; |
139 case GL_INT: | 139 case GL_INT: |
140 switch (destination_format) { | 140 switch (destination_format) { |
141 case GL_RED_INTEGER: | 141 case GL_RED_INTEGER: |
142 dst_format = WebGLImageConversion::kDataFormatR32_S; | 142 dst_format = WebGLImageConversion::kDataFormatR32_S; |
143 break; | 143 break; |
144 case GL_RG_INTEGER: | 144 case GL_RG_INTEGER: |
145 dst_format = WebGLImageConversion::kDataFormatRG32_S; | 145 dst_format = WebGLImageConversion::kDataFormatRG32_S; |
146 break; | 146 break; |
147 case GL_RGB_INTEGER: | 147 case GL_RGB_INTEGER: |
148 dst_format = WebGLImageConversion::kDataFormatRGB32_S; | 148 dst_format = WebGLImageConversion::kDataFormatRGB32_S; |
149 break; | 149 break; |
150 case GL_RGBA_INTEGER: | 150 case GL_RGBA_INTEGER: |
151 dst_format = WebGLImageConversion::kDataFormatRGBA32_S; | 151 dst_format = WebGLImageConversion::kDataFormatRGBA32_S; |
152 break; | 152 break; |
153 default: | 153 default: |
154 ASSERT_NOT_REACHED(); | 154 NOTREACHED(); |
155 } | 155 } |
156 break; | 156 break; |
157 case GL_UNSIGNED_INT: | 157 case GL_UNSIGNED_INT: |
158 switch (destination_format) { | 158 switch (destination_format) { |
159 case GL_RED_INTEGER: | 159 case GL_RED_INTEGER: |
160 dst_format = WebGLImageConversion::kDataFormatR32; | 160 dst_format = WebGLImageConversion::kDataFormatR32; |
161 break; | 161 break; |
162 case GL_DEPTH_COMPONENT: | 162 case GL_DEPTH_COMPONENT: |
163 dst_format = WebGLImageConversion::kDataFormatD32; | 163 dst_format = WebGLImageConversion::kDataFormatD32; |
164 break; | 164 break; |
165 case GL_RG_INTEGER: | 165 case GL_RG_INTEGER: |
166 dst_format = WebGLImageConversion::kDataFormatRG32; | 166 dst_format = WebGLImageConversion::kDataFormatRG32; |
167 break; | 167 break; |
168 case GL_RGB_INTEGER: | 168 case GL_RGB_INTEGER: |
169 dst_format = WebGLImageConversion::kDataFormatRGB32; | 169 dst_format = WebGLImageConversion::kDataFormatRGB32; |
170 break; | 170 break; |
171 case GL_RGBA_INTEGER: | 171 case GL_RGBA_INTEGER: |
172 dst_format = WebGLImageConversion::kDataFormatRGBA32; | 172 dst_format = WebGLImageConversion::kDataFormatRGBA32; |
173 break; | 173 break; |
174 default: | 174 default: |
175 ASSERT_NOT_REACHED(); | 175 NOTREACHED(); |
176 } | 176 } |
177 break; | 177 break; |
178 case GL_HALF_FLOAT_OES: // OES_texture_half_float | 178 case GL_HALF_FLOAT_OES: // OES_texture_half_float |
179 case GL_HALF_FLOAT: | 179 case GL_HALF_FLOAT: |
180 switch (destination_format) { | 180 switch (destination_format) { |
181 case GL_RGBA: | 181 case GL_RGBA: |
182 dst_format = WebGLImageConversion::kDataFormatRGBA16F; | 182 dst_format = WebGLImageConversion::kDataFormatRGBA16F; |
183 break; | 183 break; |
184 case GL_RGB: | 184 case GL_RGB: |
185 dst_format = WebGLImageConversion::kDataFormatRGB16F; | 185 dst_format = WebGLImageConversion::kDataFormatRGB16F; |
186 break; | 186 break; |
187 case GL_RG: | 187 case GL_RG: |
188 dst_format = WebGLImageConversion::kDataFormatRG16F; | 188 dst_format = WebGLImageConversion::kDataFormatRG16F; |
189 break; | 189 break; |
190 case GL_ALPHA: | 190 case GL_ALPHA: |
191 dst_format = WebGLImageConversion::kDataFormatA16F; | 191 dst_format = WebGLImageConversion::kDataFormatA16F; |
192 break; | 192 break; |
193 case GL_LUMINANCE: | 193 case GL_LUMINANCE: |
194 case GL_RED: | 194 case GL_RED: |
195 dst_format = WebGLImageConversion::kDataFormatR16F; | 195 dst_format = WebGLImageConversion::kDataFormatR16F; |
196 break; | 196 break; |
197 case GL_LUMINANCE_ALPHA: | 197 case GL_LUMINANCE_ALPHA: |
198 dst_format = WebGLImageConversion::kDataFormatRA16F; | 198 dst_format = WebGLImageConversion::kDataFormatRA16F; |
199 break; | 199 break; |
200 default: | 200 default: |
201 ASSERT_NOT_REACHED(); | 201 NOTREACHED(); |
202 } | 202 } |
203 break; | 203 break; |
204 case GL_FLOAT: // OES_texture_float | 204 case GL_FLOAT: // OES_texture_float |
205 switch (destination_format) { | 205 switch (destination_format) { |
206 case GL_RGBA: | 206 case GL_RGBA: |
207 dst_format = WebGLImageConversion::kDataFormatRGBA32F; | 207 dst_format = WebGLImageConversion::kDataFormatRGBA32F; |
208 break; | 208 break; |
209 case GL_RGB: | 209 case GL_RGB: |
210 dst_format = WebGLImageConversion::kDataFormatRGB32F; | 210 dst_format = WebGLImageConversion::kDataFormatRGB32F; |
211 break; | 211 break; |
212 case GL_RG: | 212 case GL_RG: |
213 dst_format = WebGLImageConversion::kDataFormatRG32F; | 213 dst_format = WebGLImageConversion::kDataFormatRG32F; |
214 break; | 214 break; |
215 case GL_ALPHA: | 215 case GL_ALPHA: |
216 dst_format = WebGLImageConversion::kDataFormatA32F; | 216 dst_format = WebGLImageConversion::kDataFormatA32F; |
217 break; | 217 break; |
218 case GL_LUMINANCE: | 218 case GL_LUMINANCE: |
219 case GL_RED: | 219 case GL_RED: |
220 dst_format = WebGLImageConversion::kDataFormatR32F; | 220 dst_format = WebGLImageConversion::kDataFormatR32F; |
221 break; | 221 break; |
222 case GL_DEPTH_COMPONENT: | 222 case GL_DEPTH_COMPONENT: |
223 dst_format = WebGLImageConversion::kDataFormatD32F; | 223 dst_format = WebGLImageConversion::kDataFormatD32F; |
224 break; | 224 break; |
225 case GL_LUMINANCE_ALPHA: | 225 case GL_LUMINANCE_ALPHA: |
226 dst_format = WebGLImageConversion::kDataFormatRA32F; | 226 dst_format = WebGLImageConversion::kDataFormatRA32F; |
227 break; | 227 break; |
228 default: | 228 default: |
229 ASSERT_NOT_REACHED(); | 229 NOTREACHED(); |
230 } | 230 } |
231 break; | 231 break; |
232 case GL_UNSIGNED_SHORT_4_4_4_4: | 232 case GL_UNSIGNED_SHORT_4_4_4_4: |
233 dst_format = WebGLImageConversion::kDataFormatRGBA4444; | 233 dst_format = WebGLImageConversion::kDataFormatRGBA4444; |
234 break; | 234 break; |
235 case GL_UNSIGNED_SHORT_5_5_5_1: | 235 case GL_UNSIGNED_SHORT_5_5_5_1: |
236 dst_format = WebGLImageConversion::kDataFormatRGBA5551; | 236 dst_format = WebGLImageConversion::kDataFormatRGBA5551; |
237 break; | 237 break; |
238 case GL_UNSIGNED_SHORT_5_6_5: | 238 case GL_UNSIGNED_SHORT_5_6_5: |
239 dst_format = WebGLImageConversion::kDataFormatRGB565; | 239 dst_format = WebGLImageConversion::kDataFormatRGB565; |
240 break; | 240 break; |
241 case GL_UNSIGNED_INT_5_9_9_9_REV: | 241 case GL_UNSIGNED_INT_5_9_9_9_REV: |
242 dst_format = WebGLImageConversion::kDataFormatRGB5999; | 242 dst_format = WebGLImageConversion::kDataFormatRGB5999; |
243 break; | 243 break; |
244 case GL_UNSIGNED_INT_24_8: | 244 case GL_UNSIGNED_INT_24_8: |
245 dst_format = WebGLImageConversion::kDataFormatDS24_8; | 245 dst_format = WebGLImageConversion::kDataFormatDS24_8; |
246 break; | 246 break; |
247 case GL_UNSIGNED_INT_10F_11F_11F_REV: | 247 case GL_UNSIGNED_INT_10F_11F_11F_REV: |
248 dst_format = WebGLImageConversion::kDataFormatRGB10F11F11F; | 248 dst_format = WebGLImageConversion::kDataFormatRGB10F11F11F; |
249 break; | 249 break; |
250 case GL_UNSIGNED_INT_2_10_10_10_REV: | 250 case GL_UNSIGNED_INT_2_10_10_10_REV: |
251 dst_format = WebGLImageConversion::kDataFormatRGBA2_10_10_10; | 251 dst_format = WebGLImageConversion::kDataFormatRGBA2_10_10_10; |
252 break; | 252 break; |
253 default: | 253 default: |
254 ASSERT_NOT_REACHED(); | 254 NOTREACHED(); |
255 } | 255 } |
256 return dst_format; | 256 return dst_format; |
257 } | 257 } |
258 | 258 |
259 // The following Float to Half-Float conversion code is from the implementation | 259 // The following Float to Half-Float conversion code is from the implementation |
260 // of ftp://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf, "Fast Half | 260 // of ftp://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf, "Fast Half |
261 // Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September | 261 // Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September |
262 // 2010). Specially, the basetable[512] and shifttable[512] are generated as | 262 // 2010). Specially, the basetable[512] and shifttable[512] are generated as |
263 // follows: | 263 // follows: |
264 /* | 264 /* |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // The following packing and unpacking routines are expressed in terms of | 394 // The following packing and unpacking routines are expressed in terms of |
395 // function templates and inline functions to achieve generality and speedup. | 395 // function templates and inline functions to achieve generality and speedup. |
396 // Explicit template specializations correspond to the cases that would occur. | 396 // Explicit template specializations correspond to the cases that would occur. |
397 // Some code are merged back from Mozilla code in | 397 // Some code are merged back from Mozilla code in |
398 // http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/WebGLTexelCo
nversions.h | 398 // http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/WebGLTexelCo
nversions.h |
399 | 399 |
400 //---------------------------------------------------------------------- | 400 //---------------------------------------------------------------------- |
401 // Pixel unpacking routines. | 401 // Pixel unpacking routines. |
402 template <int format, typename SourceType, typename DstType> | 402 template <int format, typename SourceType, typename DstType> |
403 void Unpack(const SourceType*, DstType*, unsigned) { | 403 void Unpack(const SourceType*, DstType*, unsigned) { |
404 ASSERT_NOT_REACHED(); | 404 NOTREACHED(); |
405 } | 405 } |
406 | 406 |
407 template <> | 407 template <> |
408 void Unpack<WebGLImageConversion::kDataFormatARGB8, uint8_t, uint8_t>( | 408 void Unpack<WebGLImageConversion::kDataFormatARGB8, uint8_t, uint8_t>( |
409 const uint8_t* source, | 409 const uint8_t* source, |
410 uint8_t* destination, | 410 uint8_t* destination, |
411 unsigned pixels_per_row) { | 411 unsigned pixels_per_row) { |
412 for (unsigned i = 0; i < pixels_per_row; ++i) { | 412 for (unsigned i = 0; i < pixels_per_row; ++i) { |
413 destination[0] = source[1]; | 413 destination[0] = source[1]; |
414 destination[1] = source[2]; | 414 destination[1] = source[2]; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 destination += 4; | 653 destination += 4; |
654 } | 654 } |
655 } | 655 } |
656 | 656 |
657 //---------------------------------------------------------------------- | 657 //---------------------------------------------------------------------- |
658 // Pixel packing routines. | 658 // Pixel packing routines. |
659 // | 659 // |
660 | 660 |
661 template <int format, int alphaOp, typename SourceType, typename DstType> | 661 template <int format, int alphaOp, typename SourceType, typename DstType> |
662 void Pack(const SourceType*, DstType*, unsigned) { | 662 void Pack(const SourceType*, DstType*, unsigned) { |
663 ASSERT_NOT_REACHED(); | 663 NOTREACHED(); |
664 } | 664 } |
665 | 665 |
666 template <> | 666 template <> |
667 void Pack<WebGLImageConversion::kDataFormatA8, | 667 void Pack<WebGLImageConversion::kDataFormatA8, |
668 WebGLImageConversion::kAlphaDoNothing, | 668 WebGLImageConversion::kAlphaDoNothing, |
669 uint8_t, | 669 uint8_t, |
670 uint8_t>(const uint8_t* source, | 670 uint8_t>(const uint8_t* source, |
671 uint8_t* destination, | 671 uint8_t* destination, |
672 unsigned pixels_per_row) { | 672 unsigned pixels_per_row) { |
673 for (unsigned i = 0; i < pixels_per_row; ++i) { | 673 for (unsigned i = 0; i < pixels_per_row; ++i) { |
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2259 dst_start_(dst_start), | 2259 dst_start_(dst_start), |
2260 src_stride_(src_stride), | 2260 src_stride_(src_stride), |
2261 src_row_offset_(src_row_offset), | 2261 src_row_offset_(src_row_offset), |
2262 dst_stride_(dst_stride), | 2262 dst_stride_(dst_stride), |
2263 success_(false) { | 2263 success_(false) { |
2264 const unsigned kMaxNumberOfComponents = 4; | 2264 const unsigned kMaxNumberOfComponents = 4; |
2265 const unsigned kMaxBytesPerComponent = 4; | 2265 const unsigned kMaxBytesPerComponent = 4; |
2266 unpacked_intermediate_src_data_ = WrapArrayUnique( | 2266 unpacked_intermediate_src_data_ = WrapArrayUnique( |
2267 new uint8_t[src_sub_rectangle_.Width() * kMaxNumberOfComponents * | 2267 new uint8_t[src_sub_rectangle_.Width() * kMaxNumberOfComponents * |
2268 kMaxBytesPerComponent]); | 2268 kMaxBytesPerComponent]); |
2269 ASSERT(unpacked_intermediate_src_data_.get()); | 2269 DCHECK(unpacked_intermediate_src_data_.get()); |
2270 } | 2270 } |
2271 | 2271 |
2272 void Convert(WebGLImageConversion::DataFormat src_format, | 2272 void Convert(WebGLImageConversion::DataFormat src_format, |
2273 WebGLImageConversion::DataFormat dst_format, | 2273 WebGLImageConversion::DataFormat dst_format, |
2274 WebGLImageConversion::AlphaOp); | 2274 WebGLImageConversion::AlphaOp); |
2275 bool Success() const { return success_; } | 2275 bool Success() const { return success_; } |
2276 | 2276 |
2277 private: | 2277 private: |
2278 template <WebGLImageConversion::DataFormat SrcFormat> | 2278 template <WebGLImageConversion::DataFormat SrcFormat> |
2279 void Convert(WebGLImageConversion::DataFormat dst_format, | 2279 void Convert(WebGLImageConversion::DataFormat dst_format, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2312 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatARGB8) | 2312 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatARGB8) |
2313 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatABGR8) | 2313 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatABGR8) |
2314 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatAR8) | 2314 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatAR8) |
2315 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatBGRA8) | 2315 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatBGRA8) |
2316 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatRGBA5551) | 2316 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatRGBA5551) |
2317 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatRGBA4444) | 2317 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatRGBA4444) |
2318 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatRGBA32F) | 2318 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::kDataFormatRGBA32F) |
2319 FORMATCONVERTER_CASE_SRCFORMAT( | 2319 FORMATCONVERTER_CASE_SRCFORMAT( |
2320 WebGLImageConversion::kDataFormatRGBA2_10_10_10) | 2320 WebGLImageConversion::kDataFormatRGBA2_10_10_10) |
2321 default: | 2321 default: |
2322 ASSERT_NOT_REACHED(); | 2322 NOTREACHED(); |
2323 } | 2323 } |
2324 #undef FORMATCONVERTER_CASE_SRCFORMAT | 2324 #undef FORMATCONVERTER_CASE_SRCFORMAT |
2325 } | 2325 } |
2326 | 2326 |
2327 template <WebGLImageConversion::DataFormat SrcFormat> | 2327 template <WebGLImageConversion::DataFormat SrcFormat> |
2328 void FormatConverter::Convert(WebGLImageConversion::DataFormat dst_format, | 2328 void FormatConverter::Convert(WebGLImageConversion::DataFormat dst_format, |
2329 WebGLImageConversion::AlphaOp alpha_op) { | 2329 WebGLImageConversion::AlphaOp alpha_op) { |
2330 #define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \ | 2330 #define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \ |
2331 case DstFormat: \ | 2331 case DstFormat: \ |
2332 return Convert<SrcFormat, DstFormat>(alpha_op); | 2332 return Convert<SrcFormat, DstFormat>(alpha_op); |
(...skipping 21 matching lines...) Expand all Loading... |
2354 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRGBA16) | 2354 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRGBA16) |
2355 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRGBA16_S) | 2355 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRGBA16_S) |
2356 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRGBA32) | 2356 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRGBA32) |
2357 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRGBA32_S) | 2357 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRGBA32_S) |
2358 FORMATCONVERTER_CASE_DSTFORMAT( | 2358 FORMATCONVERTER_CASE_DSTFORMAT( |
2359 WebGLImageConversion::kDataFormatRGBA2_10_10_10) | 2359 WebGLImageConversion::kDataFormatRGBA2_10_10_10) |
2360 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRG8) | 2360 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRG8) |
2361 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRG16F) | 2361 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRG16F) |
2362 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRG32F) | 2362 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::kDataFormatRG32F) |
2363 default: | 2363 default: |
2364 ASSERT_NOT_REACHED(); | 2364 NOTREACHED(); |
2365 } | 2365 } |
2366 | 2366 |
2367 #undef FORMATCONVERTER_CASE_DSTFORMAT | 2367 #undef FORMATCONVERTER_CASE_DSTFORMAT |
2368 } | 2368 } |
2369 | 2369 |
2370 template <WebGLImageConversion::DataFormat SrcFormat, | 2370 template <WebGLImageConversion::DataFormat SrcFormat, |
2371 WebGLImageConversion::DataFormat DstFormat> | 2371 WebGLImageConversion::DataFormat DstFormat> |
2372 void FormatConverter::Convert(WebGLImageConversion::AlphaOp alpha_op) { | 2372 void FormatConverter::Convert(WebGLImageConversion::AlphaOp alpha_op) { |
2373 #define FORMATCONVERTER_CASE_ALPHAOP(alphaOp) \ | 2373 #define FORMATCONVERTER_CASE_ALPHAOP(alphaOp) \ |
2374 case alphaOp: \ | 2374 case alphaOp: \ |
2375 return Convert<SrcFormat, DstFormat, alphaOp>(); | 2375 return Convert<SrcFormat, DstFormat, alphaOp>(); |
2376 | 2376 |
2377 switch (alpha_op) { | 2377 switch (alpha_op) { |
2378 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::kAlphaDoNothing) | 2378 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::kAlphaDoNothing) |
2379 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::kAlphaDoPremultiply) | 2379 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::kAlphaDoPremultiply) |
2380 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::kAlphaDoUnmultiply) | 2380 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::kAlphaDoUnmultiply) |
2381 default: | 2381 default: |
2382 ASSERT_NOT_REACHED(); | 2382 NOTREACHED(); |
2383 } | 2383 } |
2384 #undef FORMATCONVERTER_CASE_ALPHAOP | 2384 #undef FORMATCONVERTER_CASE_ALPHAOP |
2385 } | 2385 } |
2386 | 2386 |
2387 template <int Format> | 2387 template <int Format> |
2388 struct SupportsConversionFromDomElements { | 2388 struct SupportsConversionFromDomElements { |
2389 STATIC_ONLY(SupportsConversionFromDomElements); | 2389 STATIC_ONLY(SupportsConversionFromDomElements); |
2390 static const bool value = | 2390 static const bool value = |
2391 Format == WebGLImageConversion::kDataFormatRGBA8 || | 2391 Format == WebGLImageConversion::kDataFormatRGBA8 || |
2392 Format == WebGLImageConversion::kDataFormatRGB8 || | 2392 Format == WebGLImageConversion::kDataFormatRGB8 || |
(...skipping 16 matching lines...) Expand all Loading... |
2409 }; | 2409 }; |
2410 | 2410 |
2411 template <WebGLImageConversion::DataFormat SrcFormat, | 2411 template <WebGLImageConversion::DataFormat SrcFormat, |
2412 WebGLImageConversion::DataFormat DstFormat, | 2412 WebGLImageConversion::DataFormat DstFormat, |
2413 WebGLImageConversion::AlphaOp alphaOp> | 2413 WebGLImageConversion::AlphaOp alphaOp> |
2414 void FormatConverter::Convert() { | 2414 void FormatConverter::Convert() { |
2415 // Many instantiations of this template function will never be entered, so we | 2415 // Many instantiations of this template function will never be entered, so we |
2416 // try to return immediately in these cases to avoid generating useless code. | 2416 // try to return immediately in these cases to avoid generating useless code. |
2417 if (SrcFormat == DstFormat && | 2417 if (SrcFormat == DstFormat && |
2418 alphaOp == WebGLImageConversion::kAlphaDoNothing) { | 2418 alphaOp == WebGLImageConversion::kAlphaDoNothing) { |
2419 ASSERT_NOT_REACHED(); | 2419 NOTREACHED(); |
2420 return; | 2420 return; |
2421 } | 2421 } |
2422 if (!IsFloatFormat<DstFormat>::value && IsFloatFormat<SrcFormat>::value) { | 2422 if (!IsFloatFormat<DstFormat>::value && IsFloatFormat<SrcFormat>::value) { |
2423 ASSERT_NOT_REACHED(); | 2423 NOTREACHED(); |
2424 return; | 2424 return; |
2425 } | 2425 } |
2426 | 2426 |
2427 // Only textures uploaded from DOM elements or ImageData can allow DstFormat | 2427 // Only textures uploaded from DOM elements or ImageData can allow DstFormat |
2428 // != SrcFormat. | 2428 // != SrcFormat. |
2429 const bool src_format_comes_from_dom_element_or_image_data = | 2429 const bool src_format_comes_from_dom_element_or_image_data = |
2430 WebGLImageConversion::SrcFormatComeFromDOMElementOrImageData(SrcFormat); | 2430 WebGLImageConversion::SrcFormatComeFromDOMElementOrImageData(SrcFormat); |
2431 if (!src_format_comes_from_dom_element_or_image_data && | 2431 if (!src_format_comes_from_dom_element_or_image_data && |
2432 SrcFormat != DstFormat) { | 2432 SrcFormat != DstFormat) { |
2433 ASSERT_NOT_REACHED(); | 2433 NOTREACHED(); |
2434 return; | 2434 return; |
2435 } | 2435 } |
2436 // Likewise, only textures uploaded from DOM elements or ImageData can | 2436 // Likewise, only textures uploaded from DOM elements or ImageData can |
2437 // possibly need to be unpremultiplied. | 2437 // possibly need to be unpremultiplied. |
2438 if (!src_format_comes_from_dom_element_or_image_data && | 2438 if (!src_format_comes_from_dom_element_or_image_data && |
2439 alphaOp == WebGLImageConversion::kAlphaDoUnmultiply) { | 2439 alphaOp == WebGLImageConversion::kAlphaDoUnmultiply) { |
2440 ASSERT_NOT_REACHED(); | 2440 NOTREACHED(); |
2441 return; | 2441 return; |
2442 } | 2442 } |
2443 if (src_format_comes_from_dom_element_or_image_data && | 2443 if (src_format_comes_from_dom_element_or_image_data && |
2444 alphaOp == WebGLImageConversion::kAlphaDoUnmultiply && | 2444 alphaOp == WebGLImageConversion::kAlphaDoUnmultiply && |
2445 !SupportsConversionFromDomElements<DstFormat>::value) { | 2445 !SupportsConversionFromDomElements<DstFormat>::value) { |
2446 ASSERT_NOT_REACHED(); | 2446 NOTREACHED(); |
2447 return; | 2447 return; |
2448 } | 2448 } |
2449 if ((!HasAlpha(SrcFormat) || !HasColor(SrcFormat) || !HasColor(DstFormat)) && | 2449 if ((!HasAlpha(SrcFormat) || !HasColor(SrcFormat) || !HasColor(DstFormat)) && |
2450 alphaOp != WebGLImageConversion::kAlphaDoNothing) { | 2450 alphaOp != WebGLImageConversion::kAlphaDoNothing) { |
2451 ASSERT_NOT_REACHED(); | 2451 NOTREACHED(); |
2452 return; | 2452 return; |
2453 } | 2453 } |
2454 // If converting DOM element data to UNSIGNED_INT_5_9_9_9_REV or | 2454 // If converting DOM element data to UNSIGNED_INT_5_9_9_9_REV or |
2455 // UNSIGNED_INT_10F_11F_11F_REV, we should always switch to FLOAT instead to | 2455 // UNSIGNED_INT_10F_11F_11F_REV, we should always switch to FLOAT instead to |
2456 // avoid unpacking/packing these two types. | 2456 // avoid unpacking/packing these two types. |
2457 if (src_format_comes_from_dom_element_or_image_data && | 2457 if (src_format_comes_from_dom_element_or_image_data && |
2458 SrcFormat != DstFormat && | 2458 SrcFormat != DstFormat && |
2459 (DstFormat == WebGLImageConversion::kDataFormatRGB5999 || | 2459 (DstFormat == WebGLImageConversion::kDataFormatRGB5999 || |
2460 DstFormat == WebGLImageConversion::kDataFormatRGB10F11F11F)) { | 2460 DstFormat == WebGLImageConversion::kDataFormatRGB10F11F11F)) { |
2461 ASSERT_NOT_REACHED(); | 2461 NOTREACHED(); |
2462 return; | 2462 return; |
2463 } | 2463 } |
2464 | 2464 |
2465 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; | 2465 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; |
2466 typedef typename DataTypeForFormat<DstFormat>::Type DstType; | 2466 typedef typename DataTypeForFormat<DstFormat>::Type DstType; |
2467 const int kIntermFormat = IntermediateFormat<DstFormat>::value; | 2467 const int kIntermFormat = IntermediateFormat<DstFormat>::value; |
2468 typedef typename DataTypeForFormat<kIntermFormat>::Type IntermType; | 2468 typedef typename DataTypeForFormat<kIntermFormat>::Type IntermType; |
2469 const ptrdiff_t src_stride_in_elements = src_stride_ / sizeof(SrcType); | 2469 const ptrdiff_t src_stride_in_elements = src_stride_ / sizeof(SrcType); |
2470 const ptrdiff_t dst_stride_in_elements = dst_stride_ / sizeof(DstType); | 2470 const ptrdiff_t dst_stride_in_elements = dst_stride_ / sizeof(DstType); |
2471 const bool kTrivialUnpack = SrcFormat == kIntermFormat; | 2471 const bool kTrivialUnpack = SrcFormat == kIntermFormat; |
2472 const bool kTrivialPack = DstFormat == kIntermFormat && | 2472 const bool kTrivialPack = DstFormat == kIntermFormat && |
2473 alphaOp == WebGLImageConversion::kAlphaDoNothing; | 2473 alphaOp == WebGLImageConversion::kAlphaDoNothing; |
2474 ASSERT(!kTrivialUnpack || !kTrivialPack); | 2474 DCHECK(!kTrivialUnpack || !kTrivialPack); |
2475 | 2475 |
2476 const SrcType* src_row_start = | 2476 const SrcType* src_row_start = |
2477 static_cast<const SrcType*>(static_cast<const void*>( | 2477 static_cast<const SrcType*>(static_cast<const void*>( |
2478 static_cast<const uint8_t*>(src_start_) + | 2478 static_cast<const uint8_t*>(src_start_) + |
2479 ((src_stride_ * src_sub_rectangle_.Y()) + src_row_offset_))); | 2479 ((src_stride_ * src_sub_rectangle_.Y()) + src_row_offset_))); |
2480 | 2480 |
2481 // If packing multiple images into a 3D texture, and flipY is true, | 2481 // If packing multiple images into a 3D texture, and flipY is true, |
2482 // then the sub-rectangle is pointing at the start of the | 2482 // then the sub-rectangle is pointing at the start of the |
2483 // "bottommost" of those images. Since the source pointer strides in | 2483 // "bottommost" of those images. Since the source pointer strides in |
2484 // the positive direction, we need to back it up to point at the | 2484 // the positive direction, we need to back it up to point at the |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2628 GLenum WebGLImageConversion::ComputeImageSizeInBytes( | 2628 GLenum WebGLImageConversion::ComputeImageSizeInBytes( |
2629 GLenum format, | 2629 GLenum format, |
2630 GLenum type, | 2630 GLenum type, |
2631 GLsizei width, | 2631 GLsizei width, |
2632 GLsizei height, | 2632 GLsizei height, |
2633 GLsizei depth, | 2633 GLsizei depth, |
2634 const PixelStoreParams& params, | 2634 const PixelStoreParams& params, |
2635 unsigned* image_size_in_bytes, | 2635 unsigned* image_size_in_bytes, |
2636 unsigned* padding_in_bytes, | 2636 unsigned* padding_in_bytes, |
2637 unsigned* skip_size_in_bytes) { | 2637 unsigned* skip_size_in_bytes) { |
2638 ASSERT(image_size_in_bytes); | 2638 DCHECK(image_size_in_bytes); |
2639 ASSERT(params.alignment == 1 || params.alignment == 2 || | 2639 DCHECK(params.alignment == 1 || params.alignment == 2 || |
2640 params.alignment == 4 || params.alignment == 8); | 2640 params.alignment == 4 || params.alignment == 8); |
2641 ASSERT(params.row_length >= 0 && params.image_height >= 0); | 2641 DCHECK_GE(params.row_length, 0); |
2642 ASSERT(params.skip_pixels >= 0 && params.skip_rows >= 0 && | 2642 DCHECK_GE(params.image_height, 0); |
2643 params.skip_images >= 0); | 2643 DCHECK_GE(params.skip_pixels, 0); |
| 2644 DCHECK_GE(params.skip_rows, 0); |
| 2645 DCHECK_GE(params.skip_images, 0); |
2644 if (width < 0 || height < 0 || depth < 0) | 2646 if (width < 0 || height < 0 || depth < 0) |
2645 return GL_INVALID_VALUE; | 2647 return GL_INVALID_VALUE; |
2646 if (!width || !height || !depth) { | 2648 if (!width || !height || !depth) { |
2647 *image_size_in_bytes = 0; | 2649 *image_size_in_bytes = 0; |
2648 if (padding_in_bytes) | 2650 if (padding_in_bytes) |
2649 *padding_in_bytes = 0; | 2651 *padding_in_bytes = 0; |
2650 if (skip_size_in_bytes) | 2652 if (skip_size_in_bytes) |
2651 *skip_size_in_bytes = 0; | 2653 *skip_size_in_bytes = 0; |
2652 return GL_NO_ERROR; | 2654 return GL_NO_ERROR; |
2653 } | 2655 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2745 bool premultiply_alpha, | 2747 bool premultiply_alpha, |
2746 bool ignore_color_space) { | 2748 bool ignore_color_space) { |
2747 image_ = image; | 2749 image_ = image; |
2748 image_html_dom_source_ = image_html_dom_source; | 2750 image_html_dom_source_ = image_html_dom_source; |
2749 ExtractImage(premultiply_alpha, ignore_color_space); | 2751 ExtractImage(premultiply_alpha, ignore_color_space); |
2750 } | 2752 } |
2751 | 2753 |
2752 void WebGLImageConversion::ImageExtractor::ExtractImage( | 2754 void WebGLImageConversion::ImageExtractor::ExtractImage( |
2753 bool premultiply_alpha, | 2755 bool premultiply_alpha, |
2754 bool ignore_color_space) { | 2756 bool ignore_color_space) { |
2755 ASSERT(!image_pixel_locker_); | 2757 DCHECK(!image_pixel_locker_); |
2756 | 2758 |
2757 if (!image_) | 2759 if (!image_) |
2758 return; | 2760 return; |
2759 | 2761 |
2760 sk_sp<SkImage> skia_image = image_->ImageForCurrentFrame(); | 2762 sk_sp<SkImage> skia_image = image_->ImageForCurrentFrame(); |
2761 SkImageInfo info = | 2763 SkImageInfo info = |
2762 skia_image ? SkImageInfo::MakeN32Premul(image_->width(), image_->height()) | 2764 skia_image ? SkImageInfo::MakeN32Premul(image_->width(), image_->height()) |
2763 : SkImageInfo::MakeUnknown(); | 2765 : SkImageInfo::MakeUnknown(); |
2764 alpha_op_ = kAlphaDoNothing; | 2766 alpha_op_ = kAlphaDoNothing; |
2765 bool has_alpha = skia_image ? !skia_image->isOpaque() : true; | 2767 bool has_alpha = skia_image ? !skia_image->isOpaque() : true; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2802 alpha_op_ = kAlphaDoUnmultiply; | 2804 alpha_op_ = kAlphaDoUnmultiply; |
2803 } | 2805 } |
2804 | 2806 |
2805 if (!skia_image) | 2807 if (!skia_image) |
2806 return; | 2808 return; |
2807 | 2809 |
2808 image_source_format_ = SK_B32_SHIFT ? kDataFormatRGBA8 : kDataFormatBGRA8; | 2810 image_source_format_ = SK_B32_SHIFT ? kDataFormatRGBA8 : kDataFormatBGRA8; |
2809 image_source_unpack_alignment_ = | 2811 image_source_unpack_alignment_ = |
2810 0; // FIXME: this seems to always be zero - why use at all? | 2812 0; // FIXME: this seems to always be zero - why use at all? |
2811 | 2813 |
2812 ASSERT(skia_image->width() && skia_image->height()); | 2814 DCHECK(skia_image->width()); |
| 2815 DCHECK(skia_image->height()); |
2813 image_width_ = skia_image->width(); | 2816 image_width_ = skia_image->width(); |
2814 image_height_ = skia_image->height(); | 2817 image_height_ = skia_image->height(); |
2815 | 2818 |
2816 // Fail if the image was downsampled because of memory limits. | 2819 // Fail if the image was downsampled because of memory limits. |
2817 if (image_width_ != (unsigned)image_->width() || | 2820 if (image_width_ != (unsigned)image_->width() || |
2818 image_height_ != (unsigned)image_->height()) | 2821 image_height_ != (unsigned)image_->height()) |
2819 return; | 2822 return; |
2820 | 2823 |
2821 image_pixel_locker_.emplace(std::move(skia_image), info.alphaType(), | 2824 image_pixel_locker_.emplace(std::move(skia_image), info.alphaType(), |
2822 kN32_SkColorType); | 2825 kN32_SkColorType); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3191 Pack<WebGLImageConversion::kDataFormatRGB565, | 3194 Pack<WebGLImageConversion::kDataFormatRGB565, |
3192 WebGLImageConversion::kAlphaDoNothing>(src_row_start, dst_row_start, | 3195 WebGLImageConversion::kAlphaDoNothing>(src_row_start, dst_row_start, |
3193 pixels_per_row); | 3196 pixels_per_row); |
3194 } break; | 3197 } break; |
3195 default: | 3198 default: |
3196 break; | 3199 break; |
3197 } | 3200 } |
3198 } | 3201 } |
3199 | 3202 |
3200 } // namespace blink | 3203 } // namespace blink |
OLD | NEW |