| 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 "platform/graphics/ImageObserver.h" | 7 #include "platform/graphics/ImageObserver.h" |
| 8 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 8 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" |
| 9 #include "platform/graphics/cpu/mips/WebGLImageConversionMSA.h" | 9 #include "platform/graphics/cpu/mips/WebGLImageConversionMSA.h" |
| 10 #include "platform/graphics/cpu/x86/WebGLImageConversionSSE.h" | 10 #include "platform/graphics/cpu/x86/WebGLImageConversionSSE.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 dstFormat = WebGLImageConversion::DataFormatRGBA2_10_10_10; | 251 dstFormat = WebGLImageConversion::DataFormatRGBA2_10_10_10; |
| 252 break; | 252 break; |
| 253 default: | 253 default: |
| 254 ASSERT_NOT_REACHED(); | 254 ASSERT_NOT_REACHED(); |
| 255 } | 255 } |
| 256 return dstFormat; | 256 return dstFormat; |
| 257 } | 257 } |
| 258 | 258 |
| 259 // Following Float to Half-Float converion code is from the implementation of ft
p://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf, | 259 // The following Float to Half-Float conversion code is from the implementation |
| 260 // "Fast Half Float Conversions" by Jeroen van der Zijp, November 2008 (Revised
September 2010). | 260 // of ftp://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf, "Fast Half |
| 261 // Specially, the basetable[512] and shifttable[512] are generated as follows: | 261 // Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September |
| 262 // 2010). Specially, the basetable[512] and shifttable[512] are generated as |
| 263 // follows: |
| 262 /* | 264 /* |
| 263 unsigned short basetable[512]; | 265 unsigned short basetable[512]; |
| 264 unsigned char shifttable[512]; | 266 unsigned char shifttable[512]; |
| 265 | 267 |
| 266 void generatetables(){ | 268 void generatetables(){ |
| 267 unsigned int i; | 269 unsigned int i; |
| 268 int e; | 270 int e; |
| 269 for (i = 0; i < 256; ++i){ | 271 for (i = 0; i < 256; ++i){ |
| 270 e = i - 127; | 272 e = i - 127; |
| 271 if (e < -24){ // Very small numbers map to zero | 273 if (e < -24){ // Very small numbers map to zero |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13}; | 383 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13}; |
| 382 | 384 |
| 383 unsigned short convertFloatToHalfFloat(float f) { | 385 unsigned short convertFloatToHalfFloat(float f) { |
| 384 unsigned temp = *(reinterpret_cast<unsigned*>(&f)); | 386 unsigned temp = *(reinterpret_cast<unsigned*>(&f)); |
| 385 unsigned signexp = (temp >> 23) & 0x1ff; | 387 unsigned signexp = (temp >> 23) & 0x1ff; |
| 386 return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]); | 388 return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]); |
| 387 } | 389 } |
| 388 | 390 |
| 389 /* BEGIN CODE SHARED WITH MOZILLA FIREFOX */ | 391 /* BEGIN CODE SHARED WITH MOZILLA FIREFOX */ |
| 390 | 392 |
| 391 // The following packing and unpacking routines are expressed in terms of functi
on templates and inline functions to achieve generality and speedup. | 393 // The following packing and unpacking routines are expressed in terms of |
| 394 // function templates and inline functions to achieve generality and speedup. |
| 392 // Explicit template specializations correspond to the cases that would occur. | 395 // Explicit template specializations correspond to the cases that would occur. |
| 393 // Some code are merged back from Mozilla code in http://mxr.mozilla.org/mozilla
-central/source/content/canvas/src/WebGLTexelConversions.h | 396 // Some code are merged back from Mozilla code in |
| 397 // http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/WebGLTexelCo
nversions.h |
| 394 | 398 |
| 395 //---------------------------------------------------------------------- | 399 //---------------------------------------------------------------------- |
| 396 // Pixel unpacking routines. | 400 // Pixel unpacking routines. |
| 397 template <int format, typename SourceType, typename DstType> | 401 template <int format, typename SourceType, typename DstType> |
| 398 void unpack(const SourceType*, DstType*, unsigned) { | 402 void unpack(const SourceType*, DstType*, unsigned) { |
| 399 ASSERT_NOT_REACHED(); | 403 ASSERT_NOT_REACHED(); |
| 400 } | 404 } |
| 401 | 405 |
| 402 template <> | 406 template <> |
| 403 void unpack<WebGLImageConversion::DataFormatARGB8, uint8_t, uint8_t>( | 407 void unpack<WebGLImageConversion::DataFormatARGB8, uint8_t, uint8_t>( |
| (...skipping 1968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2372 Format == WebGLImageConversion::DataFormatR16F || | 2376 Format == WebGLImageConversion::DataFormatR16F || |
| 2373 Format == WebGLImageConversion::DataFormatRGBA5551 || | 2377 Format == WebGLImageConversion::DataFormatRGBA5551 || |
| 2374 Format == WebGLImageConversion::DataFormatRGBA4444 || | 2378 Format == WebGLImageConversion::DataFormatRGBA4444 || |
| 2375 Format == WebGLImageConversion::DataFormatRGB565; | 2379 Format == WebGLImageConversion::DataFormatRGB565; |
| 2376 }; | 2380 }; |
| 2377 | 2381 |
| 2378 template <WebGLImageConversion::DataFormat SrcFormat, | 2382 template <WebGLImageConversion::DataFormat SrcFormat, |
| 2379 WebGLImageConversion::DataFormat DstFormat, | 2383 WebGLImageConversion::DataFormat DstFormat, |
| 2380 WebGLImageConversion::AlphaOp alphaOp> | 2384 WebGLImageConversion::AlphaOp alphaOp> |
| 2381 void FormatConverter::convert() { | 2385 void FormatConverter::convert() { |
| 2382 // Many instantiations of this template function will never be entered, so we
try | 2386 // Many instantiations of this template function will never be entered, so we |
| 2383 // to return immediately in these cases to avoid the compiler to generate usel
ess code. | 2387 // try to return immediately in these cases to avoid generating useless code. |
| 2384 if (SrcFormat == DstFormat && | 2388 if (SrcFormat == DstFormat && |
| 2385 alphaOp == WebGLImageConversion::AlphaDoNothing) { | 2389 alphaOp == WebGLImageConversion::AlphaDoNothing) { |
| 2386 ASSERT_NOT_REACHED(); | 2390 ASSERT_NOT_REACHED(); |
| 2387 return; | 2391 return; |
| 2388 } | 2392 } |
| 2389 if (!IsFloatFormat<DstFormat>::value && IsFloatFormat<SrcFormat>::value) { | 2393 if (!IsFloatFormat<DstFormat>::value && IsFloatFormat<SrcFormat>::value) { |
| 2390 ASSERT_NOT_REACHED(); | 2394 ASSERT_NOT_REACHED(); |
| 2391 return; | 2395 return; |
| 2392 } | 2396 } |
| 2393 | 2397 |
| 2394 // Only textures uploaded from DOM elements or ImageData can allow DstFormat !
= SrcFormat. | 2398 // Only textures uploaded from DOM elements or ImageData can allow DstFormat |
| 2399 // != SrcFormat. |
| 2395 const bool srcFormatComesFromDOMElementOrImageData = | 2400 const bool srcFormatComesFromDOMElementOrImageData = |
| 2396 WebGLImageConversion::srcFormatComeFromDOMElementOrImageData(SrcFormat); | 2401 WebGLImageConversion::srcFormatComeFromDOMElementOrImageData(SrcFormat); |
| 2397 if (!srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat) { | 2402 if (!srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat) { |
| 2398 ASSERT_NOT_REACHED(); | 2403 ASSERT_NOT_REACHED(); |
| 2399 return; | 2404 return; |
| 2400 } | 2405 } |
| 2401 // Likewise, only textures uploaded from DOM elements or ImageData can possibl
y have to be unpremultiplied. | 2406 // Likewise, only textures uploaded from DOM elements or ImageData can |
| 2407 // possibly need to be unpremultiplied. |
| 2402 if (!srcFormatComesFromDOMElementOrImageData && | 2408 if (!srcFormatComesFromDOMElementOrImageData && |
| 2403 alphaOp == WebGLImageConversion::AlphaDoUnmultiply) { | 2409 alphaOp == WebGLImageConversion::AlphaDoUnmultiply) { |
| 2404 ASSERT_NOT_REACHED(); | 2410 ASSERT_NOT_REACHED(); |
| 2405 return; | 2411 return; |
| 2406 } | 2412 } |
| 2407 if (srcFormatComesFromDOMElementOrImageData && | 2413 if (srcFormatComesFromDOMElementOrImageData && |
| 2408 alphaOp == WebGLImageConversion::AlphaDoUnmultiply && | 2414 alphaOp == WebGLImageConversion::AlphaDoUnmultiply && |
| 2409 !SupportsConversionFromDomElements<DstFormat>::value) { | 2415 !SupportsConversionFromDomElements<DstFormat>::value) { |
| 2410 ASSERT_NOT_REACHED(); | 2416 ASSERT_NOT_REACHED(); |
| 2411 return; | 2417 return; |
| 2412 } | 2418 } |
| 2413 if ((!HasAlpha(SrcFormat) || !HasColor(SrcFormat) || !HasColor(DstFormat)) && | 2419 if ((!HasAlpha(SrcFormat) || !HasColor(SrcFormat) || !HasColor(DstFormat)) && |
| 2414 alphaOp != WebGLImageConversion::AlphaDoNothing) { | 2420 alphaOp != WebGLImageConversion::AlphaDoNothing) { |
| 2415 ASSERT_NOT_REACHED(); | 2421 ASSERT_NOT_REACHED(); |
| 2416 return; | 2422 return; |
| 2417 } | 2423 } |
| 2418 // If converting DOM element data to UNSIGNED_INT_5_9_9_9_REV or UNSIGNED_INT_
10F_11F_11F_REV, | 2424 // If converting DOM element data to UNSIGNED_INT_5_9_9_9_REV or |
| 2419 // we should always switch to FLOAT instead to avoid unpack/pack to these two
types. | 2425 // UNSIGNED_INT_10F_11F_11F_REV, we should always switch to FLOAT instead to |
| 2426 // avoid unpacking/packing these two types. |
| 2420 if (srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat && | 2427 if (srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat && |
| 2421 (DstFormat == WebGLImageConversion::DataFormatRGB5999 || | 2428 (DstFormat == WebGLImageConversion::DataFormatRGB5999 || |
| 2422 DstFormat == WebGLImageConversion::DataFormatRGB10F11F11F)) { | 2429 DstFormat == WebGLImageConversion::DataFormatRGB10F11F11F)) { |
| 2423 ASSERT_NOT_REACHED(); | 2430 ASSERT_NOT_REACHED(); |
| 2424 return; | 2431 return; |
| 2425 } | 2432 } |
| 2426 | 2433 |
| 2427 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; | 2434 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; |
| 2428 typedef typename DataTypeForFormat<DstFormat>::Type DstType; | 2435 typedef typename DataTypeForFormat<DstFormat>::Type DstType; |
| 2429 const int IntermFormat = IntermediateFormat<DstFormat>::value; | 2436 const int IntermFormat = IntermediateFormat<DstFormat>::value; |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2714 | 2721 |
| 2715 // TODO(fmalita): Partial frames are not supported currently: only fully | 2722 // TODO(fmalita): Partial frames are not supported currently: only fully |
| 2716 // decoded frames make it through. We could potentially relax this and | 2723 // decoded frames make it through. We could potentially relax this and |
| 2717 // use SkImage::MakeFromBitmap(bitmap) to make a copy. | 2724 // use SkImage::MakeFromBitmap(bitmap) to make a copy. |
| 2718 skiaImage = frame->finalizePixelsAndGetImage(); | 2725 skiaImage = frame->finalizePixelsAndGetImage(); |
| 2719 info = bitmap.info(); | 2726 info = bitmap.info(); |
| 2720 | 2727 |
| 2721 if (hasAlpha && premultiplyAlpha) | 2728 if (hasAlpha && premultiplyAlpha) |
| 2722 m_alphaOp = AlphaDoPremultiply; | 2729 m_alphaOp = AlphaDoPremultiply; |
| 2723 } else if (!premultiplyAlpha && hasAlpha) { | 2730 } else if (!premultiplyAlpha && hasAlpha) { |
| 2724 // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAlpha
had been applied and the alpha value for each pixel is 0xFF | 2731 // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAlpha |
| 2725 // which is true at present and may be changed in the future and needs adjus
tment accordingly. | 2732 // had been applied and the alpha value for each pixel is 0xFF. This is |
| 2726 // 2. For texImage2D with HTMLCanvasElement input in which Alpha is already
Premultiplied in this port, | 2733 // true at present; if it is changed in the future it will need |
| 2727 // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to false. | 2734 // adjustment accordingly. |
| 2735 // 2. For texImage2D with HTMLCanvasElement input in which alpha is already |
| 2736 // premultiplied in this port, do AlphaDoUnmultiply if |
| 2737 // UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to false. |
| 2728 if (m_imageHtmlDomSource != HtmlDomVideo) | 2738 if (m_imageHtmlDomSource != HtmlDomVideo) |
| 2729 m_alphaOp = AlphaDoUnmultiply; | 2739 m_alphaOp = AlphaDoUnmultiply; |
| 2730 } | 2740 } |
| 2731 | 2741 |
| 2732 if (!skiaImage) | 2742 if (!skiaImage) |
| 2733 return; | 2743 return; |
| 2734 | 2744 |
| 2735 m_imageSourceFormat = SK_B32_SHIFT ? DataFormatRGBA8 : DataFormatBGRA8; | 2745 m_imageSourceFormat = SK_B32_SHIFT ? DataFormatRGBA8 : DataFormatBGRA8; |
| 2736 m_imageSourceUnpackAlignment = | 2746 m_imageSourceUnpackAlignment = |
| 2737 0; // FIXME: this seems to always be zero - why use at all? | 2747 0; // FIXME: this seems to always be zero - why use at all? |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3072 pack<WebGLImageConversion::DataFormatRGB565, | 3082 pack<WebGLImageConversion::DataFormatRGB565, |
| 3073 WebGLImageConversion::AlphaDoNothing>(srcRowStart, dstRowStart, | 3083 WebGLImageConversion::AlphaDoNothing>(srcRowStart, dstRowStart, |
| 3074 pixelsPerRow); | 3084 pixelsPerRow); |
| 3075 } break; | 3085 } break; |
| 3076 default: | 3086 default: |
| 3077 break; | 3087 break; |
| 3078 } | 3088 } |
| 3079 } | 3089 } |
| 3080 | 3090 |
| 3081 } // namespace blink | 3091 } // namespace blink |
| OLD | NEW |