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/CheckedInt.h" | |
8 #include "platform/graphics/ImageObserver.h" | 7 #include "platform/graphics/ImageObserver.h" |
9 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 8 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" |
10 #include "platform/graphics/cpu/mips/WebGLImageConversionMSA.h" | 9 #include "platform/graphics/cpu/mips/WebGLImageConversionMSA.h" |
11 #include "platform/graphics/cpu/x86/WebGLImageConversionSSE.h" | 10 #include "platform/graphics/cpu/x86/WebGLImageConversionSSE.h" |
12 #include "platform/graphics/skia/SkiaUtils.h" | 11 #include "platform/graphics/skia/SkiaUtils.h" |
13 #include "platform/image-decoders/ImageDecoder.h" | 12 #include "platform/image-decoders/ImageDecoder.h" |
14 #include "third_party/skia/include/core/SkImage.h" | 13 #include "third_party/skia/include/core/SkImage.h" |
| 14 #include "wtf/CheckedNumeric.h" |
15 #include "wtf/PtrUtil.h" | 15 #include "wtf/PtrUtil.h" |
16 #include <memory> | 16 #include <memory> |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const float maxInt8Value = INT8_MAX; | 22 const float maxInt8Value = INT8_MAX; |
23 const float maxUInt8Value = UINT8_MAX; | 23 const float maxUInt8Value = UINT8_MAX; |
24 const float maxInt16Value = INT16_MAX; | 24 const float maxInt16Value = INT16_MAX; |
(...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 return GL_NO_ERROR; | 2055 return GL_NO_ERROR; |
2056 } | 2056 } |
2057 | 2057 |
2058 int rowLength = params.rowLength > 0 ? params.rowLength : width; | 2058 int rowLength = params.rowLength > 0 ? params.rowLength : width; |
2059 int imageHeight = params.imageHeight > 0 ? params.imageHeight : height; | 2059 int imageHeight = params.imageHeight > 0 ? params.imageHeight : height; |
2060 | 2060 |
2061 unsigned bytesPerComponent, componentsPerPixel; | 2061 unsigned bytesPerComponent, componentsPerPixel; |
2062 if (!computeFormatAndTypeParameters(format, type, &bytesPerComponent, &compo
nentsPerPixel)) | 2062 if (!computeFormatAndTypeParameters(format, type, &bytesPerComponent, &compo
nentsPerPixel)) |
2063 return GL_INVALID_ENUM; | 2063 return GL_INVALID_ENUM; |
2064 unsigned bytesPerGroup = bytesPerComponent * componentsPerPixel; | 2064 unsigned bytesPerGroup = bytesPerComponent * componentsPerPixel; |
2065 CheckedInt<uint32_t> checkedValue = static_cast<uint32_t>(rowLength); | 2065 CheckedNumeric<uint32_t> checkedValue = static_cast<uint32_t>(rowLength); |
2066 checkedValue *= bytesPerGroup; | 2066 checkedValue *= bytesPerGroup; |
2067 if (!checkedValue.isValid()) | 2067 if (!checkedValue.IsValid()) |
2068 return GL_INVALID_VALUE; | 2068 return GL_INVALID_VALUE; |
2069 | 2069 |
2070 unsigned lastRowSize; | 2070 unsigned lastRowSize; |
2071 if (params.rowLength > 0 && params.rowLength != width) { | 2071 if (params.rowLength > 0 && params.rowLength != width) { |
2072 CheckedInt<uint32_t> tmp = width; | 2072 CheckedNumeric<uint32_t> tmp = width; |
2073 tmp *= bytesPerGroup; | 2073 tmp *= bytesPerGroup; |
2074 if (!tmp.isValid()) | 2074 if (!tmp.IsValid()) |
2075 return GL_INVALID_VALUE; | 2075 return GL_INVALID_VALUE; |
2076 lastRowSize = tmp.value(); | 2076 lastRowSize = tmp.ValueOrDie(); |
2077 } else { | 2077 } else { |
2078 lastRowSize = checkedValue.value(); | 2078 lastRowSize = checkedValue.ValueOrDie(); |
2079 } | 2079 } |
2080 | 2080 |
2081 unsigned padding = 0; | 2081 unsigned padding = 0; |
2082 unsigned residual = checkedValue.value() % params.alignment; | 2082 unsigned residual = checkedValue.ValueOrDie() % params.alignment; |
2083 if (residual) { | 2083 if (residual) { |
2084 padding = params.alignment - residual; | 2084 padding = params.alignment - residual; |
2085 checkedValue += padding; | 2085 checkedValue += padding; |
2086 } | 2086 } |
2087 if (!checkedValue.isValid()) | 2087 if (!checkedValue.IsValid()) |
2088 return GL_INVALID_VALUE; | 2088 return GL_INVALID_VALUE; |
2089 unsigned paddedRowSize = checkedValue.value(); | 2089 unsigned paddedRowSize = checkedValue.ValueOrDie(); |
2090 | 2090 |
2091 CheckedInt<uint32_t> rows = imageHeight; | 2091 CheckedNumeric<uint32_t> rows = imageHeight; |
2092 rows *= (depth - 1); | 2092 rows *= (depth - 1); |
2093 // Last image is not affected by IMAGE_HEIGHT parameter. | 2093 // Last image is not affected by IMAGE_HEIGHT parameter. |
2094 rows += height; | 2094 rows += height; |
2095 if (!rows.isValid()) | 2095 if (!rows.IsValid()) |
2096 return GL_INVALID_VALUE; | 2096 return GL_INVALID_VALUE; |
2097 checkedValue *= (rows.value() - 1); | 2097 checkedValue *= (rows.ValueOrDie() - 1); |
2098 // Last row is not affected by ROW_LENGTH parameter. | 2098 // Last row is not affected by ROW_LENGTH parameter. |
2099 checkedValue += lastRowSize; | 2099 checkedValue += lastRowSize; |
2100 if (!checkedValue.isValid()) | 2100 if (!checkedValue.IsValid()) |
2101 return GL_INVALID_VALUE; | 2101 return GL_INVALID_VALUE; |
2102 *imageSizeInBytes = checkedValue.value(); | 2102 *imageSizeInBytes = checkedValue.ValueOrDie(); |
2103 if (paddingInBytes) | 2103 if (paddingInBytes) |
2104 *paddingInBytes = padding; | 2104 *paddingInBytes = padding; |
2105 | 2105 |
2106 CheckedInt<uint32_t> skipSize = 0; | 2106 CheckedNumeric<uint32_t> skipSize = 0; |
2107 if (params.skipImages > 0) { | 2107 if (params.skipImages > 0) { |
2108 CheckedInt<uint32_t> tmp = paddedRowSize; | 2108 CheckedNumeric<uint32_t> tmp = paddedRowSize; |
2109 tmp *= imageHeight; | 2109 tmp *= imageHeight; |
2110 tmp *= params.skipImages; | 2110 tmp *= params.skipImages; |
2111 if (!tmp.isValid()) | 2111 if (!tmp.IsValid()) |
2112 return GL_INVALID_VALUE; | 2112 return GL_INVALID_VALUE; |
2113 skipSize += tmp.value(); | 2113 skipSize += tmp.ValueOrDie(); |
2114 } | 2114 } |
2115 if (params.skipRows > 0) { | 2115 if (params.skipRows > 0) { |
2116 CheckedInt<uint32_t> tmp = paddedRowSize; | 2116 CheckedNumeric<uint32_t> tmp = paddedRowSize; |
2117 tmp *= params.skipRows; | 2117 tmp *= params.skipRows; |
2118 if (!tmp.isValid()) | 2118 if (!tmp.IsValid()) |
2119 return GL_INVALID_VALUE; | 2119 return GL_INVALID_VALUE; |
2120 skipSize += tmp.value(); | 2120 skipSize += tmp.ValueOrDie(); |
2121 } | 2121 } |
2122 if (params.skipPixels > 0) { | 2122 if (params.skipPixels > 0) { |
2123 CheckedInt<uint32_t> tmp = bytesPerGroup; | 2123 CheckedNumeric<uint32_t> tmp = bytesPerGroup; |
2124 tmp *= params.skipPixels; | 2124 tmp *= params.skipPixels; |
2125 if (!tmp.isValid()) | 2125 if (!tmp.IsValid()) |
2126 return GL_INVALID_VALUE; | 2126 return GL_INVALID_VALUE; |
2127 skipSize += tmp.value(); | 2127 skipSize += tmp.ValueOrDie(); |
2128 } | 2128 } |
2129 if (!skipSize.isValid()) | 2129 if (!skipSize.IsValid()) |
2130 return GL_INVALID_VALUE; | 2130 return GL_INVALID_VALUE; |
2131 if (skipSizeInBytes) | 2131 if (skipSizeInBytes) |
2132 *skipSizeInBytes = skipSize.value(); | 2132 *skipSizeInBytes = skipSize.ValueOrDie(); |
2133 | 2133 |
2134 checkedValue += skipSize.value(); | 2134 checkedValue += skipSize.ValueOrDie(); |
2135 if (!checkedValue.isValid()) | 2135 if (!checkedValue.IsValid()) |
2136 return GL_INVALID_VALUE; | 2136 return GL_INVALID_VALUE; |
2137 return GL_NO_ERROR; | 2137 return GL_NO_ERROR; |
2138 } | 2138 } |
2139 | 2139 |
2140 WebGLImageConversion::ImageExtractor::ImageExtractor(Image* image, ImageHtmlDomS
ource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile
) | 2140 WebGLImageConversion::ImageExtractor::ImageExtractor(Image* image, ImageHtmlDomS
ource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile
) |
2141 { | 2141 { |
2142 m_image = image; | 2142 m_image = image; |
2143 m_imageHtmlDomSource = imageHtmlDomSource; | 2143 m_imageHtmlDomSource = imageHtmlDomSource; |
2144 extractImage(premultiplyAlpha, ignoreGammaAndColorProfile); | 2144 extractImage(premultiplyAlpha, ignoreGammaAndColorProfile); |
2145 } | 2145 } |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 DstType* dstRowStart = static_cast<DstType*>(pdst); | 2516 DstType* dstRowStart = static_cast<DstType*>(pdst); |
2517 pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversion::A
lphaDoNothing>(srcRowStart, dstRowStart, pixelsPerRow); | 2517 pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversion::A
lphaDoNothing>(srcRowStart, dstRowStart, pixelsPerRow); |
2518 } | 2518 } |
2519 break; | 2519 break; |
2520 default: | 2520 default: |
2521 break; | 2521 break; |
2522 } | 2522 } |
2523 } | 2523 } |
2524 | 2524 |
2525 } // namespace blink | 2525 } // namespace blink |
OLD | NEW |