Chromium Code Reviews| 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/gpu/WebGLImageConversion.h" | 6 #include "platform/graphics/gpu/WebGLImageConversion.h" |
| 7 | 7 |
| 8 #include "platform/CheckedInt.h" | 8 #include "platform/CheckedInt.h" |
| 9 #include "platform/graphics/ImageObserver.h" | 9 #include "platform/graphics/ImageObserver.h" |
| 10 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 10 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" |
| (...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1969 case GL_HALF_FLOAT: | 1969 case GL_HALF_FLOAT: |
| 1970 case GL_HALF_FLOAT_OES: // OES_texture_half_float | 1970 case GL_HALF_FLOAT_OES: // OES_texture_half_float |
| 1971 *bytesPerComponent = sizeof(GLushort); | 1971 *bytesPerComponent = sizeof(GLushort); |
| 1972 break; | 1972 break; |
| 1973 default: | 1973 default: |
| 1974 return false; | 1974 return false; |
| 1975 } | 1975 } |
| 1976 return true; | 1976 return true; |
| 1977 } | 1977 } |
| 1978 | 1978 |
| 1979 GLenum WebGLImageConversion::computeImageSizeInBytes(GLenum format, GLenum type, GLsizei width, GLsizei height, GLint alignment, unsigned* imageSizeInBytes, uns igned* paddingInBytes) | 1979 GLenum WebGLImageConversion::computeImageSizeInBytes(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLint alignment, unsigned* imageS izeInBytes, unsigned* paddingInBytes) |
| 1980 { | 1980 { |
| 1981 ASSERT(imageSizeInBytes); | 1981 ASSERT(imageSizeInBytes); |
| 1982 ASSERT(alignment == 1 || alignment == 2 || alignment == 4 || alignment == 8) ; | 1982 ASSERT(alignment == 1 || alignment == 2 || alignment == 4 || alignment == 8) ; |
| 1983 if (width < 0 || height < 0) | 1983 if (width < 0 || height < 0 || depth < 0) |
| 1984 return GL_INVALID_VALUE; | 1984 return GL_INVALID_VALUE; |
| 1985 unsigned bytesPerComponent, componentsPerPixel; | 1985 unsigned bytesPerComponent, componentsPerPixel; |
| 1986 if (!computeFormatAndTypeParameters(format, type, &bytesPerComponent, &compo nentsPerPixel)) | 1986 if (!computeFormatAndTypeParameters(format, type, &bytesPerComponent, &compo nentsPerPixel)) |
| 1987 return GL_INVALID_ENUM; | 1987 return GL_INVALID_ENUM; |
| 1988 if (!width || !height) { | 1988 if (!width || !height || !depth) { |
| 1989 *imageSizeInBytes = 0; | 1989 *imageSizeInBytes = 0; |
| 1990 if (paddingInBytes) | 1990 if (paddingInBytes) |
| 1991 *paddingInBytes = 0; | 1991 *paddingInBytes = 0; |
| 1992 return GL_NO_ERROR; | 1992 return GL_NO_ERROR; |
| 1993 } | 1993 } |
| 1994 CheckedInt<uint32_t> checkedValue(bytesPerComponent * componentsPerPixel); | 1994 CheckedInt<uint32_t> checkedValue(bytesPerComponent * componentsPerPixel); |
| 1995 checkedValue *= width; | 1995 checkedValue *= width; |
| 1996 if (!checkedValue.isValid()) | 1996 if (!checkedValue.isValid()) |
| 1997 return GL_INVALID_VALUE; | 1997 return GL_INVALID_VALUE; |
| 1998 unsigned validRowSize = checkedValue.value(); | 1998 unsigned validRowSize = checkedValue.value(); |
| 1999 unsigned padding = 0; | 1999 unsigned padding = 0; |
| 2000 unsigned residual = validRowSize % alignment; | 2000 unsigned residual = validRowSize % alignment; |
| 2001 if (residual) { | 2001 if (residual) { |
| 2002 padding = alignment - residual; | 2002 padding = alignment - residual; |
| 2003 checkedValue += padding; | 2003 checkedValue += padding; |
| 2004 } | 2004 } |
| 2005 // Last row needs no padding. | 2005 // Last row needs no padding. |
| 2006 checkedValue *= (height - 1); | 2006 checkedValue *= (height - 1); |
| 2007 checkedValue += validRowSize; | 2007 checkedValue += validRowSize; |
| 2008 if (!checkedValue.isValid()) | 2008 if (!checkedValue.isValid()) |
| 2009 return GL_INVALID_VALUE; | 2009 return GL_INVALID_VALUE; |
| 2010 checkedValue *= depth; | |
| 2011 if (!checkedValue.isValid()) | |
| 2012 return GL_INVALID_VALUE; | |
|
Zhenyao Mo
2015/11/12 11:31:52
Another issue: see above, "last row needs no paddi
qiankun
2015/11/13 08:29:59
Done.
| |
| 2010 *imageSizeInBytes = checkedValue.value(); | 2013 *imageSizeInBytes = checkedValue.value(); |
| 2011 if (paddingInBytes) | 2014 if (paddingInBytes) |
| 2012 *paddingInBytes = padding; | 2015 *paddingInBytes = padding; |
| 2013 return GL_NO_ERROR; | 2016 return GL_NO_ERROR; |
| 2014 } | 2017 } |
| 2015 | 2018 |
| 2016 WebGLImageConversion::ImageExtractor::ImageExtractor(Image* image, ImageHtmlDomS ource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile ) | 2019 WebGLImageConversion::ImageExtractor::ImageExtractor(Image* image, ImageHtmlDomS ource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile ) |
| 2017 { | 2020 { |
| 2018 m_image = image; | 2021 m_image = image; |
| 2019 m_imageHtmlDomSource = imageHtmlDomSource; | 2022 m_imageHtmlDomSource = imageHtmlDomSource; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2199 unsigned width, | 2202 unsigned width, |
| 2200 unsigned height, | 2203 unsigned height, |
| 2201 unsigned sourceUnpackAlignment, | 2204 unsigned sourceUnpackAlignment, |
| 2202 Vector<uint8_t>& data) | 2205 Vector<uint8_t>& data) |
| 2203 { | 2206 { |
| 2204 if (!pixels) | 2207 if (!pixels) |
| 2205 return false; | 2208 return false; |
| 2206 | 2209 |
| 2207 unsigned packedSize; | 2210 unsigned packedSize; |
| 2208 // Output data is tightly packed (alignment == 1). | 2211 // Output data is tightly packed (alignment == 1). |
| 2209 if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GL_NO_ERROR) | 2212 if (computeImageSizeInBytes(format, type, width, height, 1, 1, &packedSize, 0) != GL_NO_ERROR) |
| 2210 return false; | 2213 return false; |
| 2211 data.resize(packedSize); | 2214 data.resize(packedSize); |
| 2212 | 2215 |
| 2213 if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, widt h, height, sourceUnpackAlignment, format, type, alphaOp, data.data(), flipY)) | 2216 if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, widt h, height, sourceUnpackAlignment, format, type, alphaOp, data.data(), flipY)) |
| 2214 return false; | 2217 return false; |
| 2215 if (ImageObserver *observer = image->imageObserver()) | 2218 if (ImageObserver *observer = image->imageObserver()) |
| 2216 observer->didDraw(image); | 2219 observer->didDraw(image); |
| 2217 return true; | 2220 return true; |
| 2218 } | 2221 } |
| 2219 | 2222 |
| 2220 bool WebGLImageConversion::extractImageData( | 2223 bool WebGLImageConversion::extractImageData( |
| 2221 const uint8_t* imageData, | 2224 const uint8_t* imageData, |
| 2222 const IntSize& imageDataSize, | 2225 const IntSize& imageDataSize, |
| 2223 GLenum format, | 2226 GLenum format, |
| 2224 GLenum type, | 2227 GLenum type, |
| 2225 bool flipY, | 2228 bool flipY, |
| 2226 bool premultiplyAlpha, | 2229 bool premultiplyAlpha, |
| 2227 Vector<uint8_t>& data) | 2230 Vector<uint8_t>& data) |
| 2228 { | 2231 { |
| 2229 if (!imageData) | 2232 if (!imageData) |
| 2230 return false; | 2233 return false; |
| 2231 int width = imageDataSize.width(); | 2234 int width = imageDataSize.width(); |
| 2232 int height = imageDataSize.height(); | 2235 int height = imageDataSize.height(); |
| 2233 | 2236 |
| 2234 unsigned packedSize; | 2237 unsigned packedSize; |
| 2235 // Output data is tightly packed (alignment == 1). | 2238 // Output data is tightly packed (alignment == 1). |
| 2236 if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GL_NO_ERROR) | 2239 if (computeImageSizeInBytes(format, type, width, height, 1, 1, &packedSize, 0) != GL_NO_ERROR) |
| 2237 return false; | 2240 return false; |
| 2238 data.resize(packedSize); | 2241 data.resize(packedSize); |
| 2239 | 2242 |
| 2240 if (!packPixels(imageData, DataFormatRGBA8, width, height, 0, format, type, premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing, data.data(), flipY)) | 2243 if (!packPixels(imageData, DataFormatRGBA8, width, height, 0, format, type, premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing, data.data(), flipY)) |
| 2241 return false; | 2244 return false; |
| 2242 | 2245 |
| 2243 return true; | 2246 return true; |
| 2244 } | 2247 } |
| 2245 | 2248 |
| 2246 bool WebGLImageConversion::extractTextureData( | 2249 bool WebGLImageConversion::extractTextureData( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2307 } | 2310 } |
| 2308 | 2311 |
| 2309 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride); | 2312 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride); |
| 2310 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); | 2313 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); |
| 2311 if (!converter.Success()) | 2314 if (!converter.Success()) |
| 2312 return false; | 2315 return false; |
| 2313 return true; | 2316 return true; |
| 2314 } | 2317 } |
| 2315 | 2318 |
| 2316 } // namespace blink | 2319 } // namespace blink |
| OLD | NEW |