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 * depth - 1); |
|
Ken Russell (switch to Gerrit)
2015/11/20 00:15:42
More changes are needed to this function in order
| |
| 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 *imageSizeInBytes = checkedValue.value(); | 2010 *imageSizeInBytes = checkedValue.value(); |
| 2011 if (paddingInBytes) | 2011 if (paddingInBytes) |
| 2012 *paddingInBytes = padding; | 2012 *paddingInBytes = padding; |
| 2013 return GL_NO_ERROR; | 2013 return GL_NO_ERROR; |
| 2014 } | 2014 } |
| 2015 | 2015 |
| 2016 WebGLImageConversion::ImageExtractor::ImageExtractor(Image* image, ImageHtmlDomS ource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile ) | 2016 WebGLImageConversion::ImageExtractor::ImageExtractor(Image* image, ImageHtmlDomS ource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile ) |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2199 unsigned width, | 2199 unsigned width, |
| 2200 unsigned height, | 2200 unsigned height, |
| 2201 unsigned sourceUnpackAlignment, | 2201 unsigned sourceUnpackAlignment, |
| 2202 Vector<uint8_t>& data) | 2202 Vector<uint8_t>& data) |
| 2203 { | 2203 { |
| 2204 if (!pixels) | 2204 if (!pixels) |
| 2205 return false; | 2205 return false; |
| 2206 | 2206 |
| 2207 unsigned packedSize; | 2207 unsigned packedSize; |
| 2208 // Output data is tightly packed (alignment == 1). | 2208 // Output data is tightly packed (alignment == 1). |
| 2209 if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GL_NO_ERROR) | 2209 if (computeImageSizeInBytes(format, type, width, height, 1, 1, &packedSize, 0) != GL_NO_ERROR) |
| 2210 return false; | 2210 return false; |
| 2211 data.resize(packedSize); | 2211 data.resize(packedSize); |
| 2212 | 2212 |
| 2213 if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, widt h, height, sourceUnpackAlignment, format, type, alphaOp, data.data(), flipY)) | 2213 if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, widt h, height, sourceUnpackAlignment, format, type, alphaOp, data.data(), flipY)) |
| 2214 return false; | 2214 return false; |
| 2215 if (ImageObserver *observer = image->imageObserver()) | 2215 if (ImageObserver *observer = image->imageObserver()) |
| 2216 observer->didDraw(image); | 2216 observer->didDraw(image); |
| 2217 return true; | 2217 return true; |
| 2218 } | 2218 } |
| 2219 | 2219 |
| 2220 bool WebGLImageConversion::extractImageData( | 2220 bool WebGLImageConversion::extractImageData( |
| 2221 const uint8_t* imageData, | 2221 const uint8_t* imageData, |
| 2222 const IntSize& imageDataSize, | 2222 const IntSize& imageDataSize, |
| 2223 GLenum format, | 2223 GLenum format, |
| 2224 GLenum type, | 2224 GLenum type, |
| 2225 bool flipY, | 2225 bool flipY, |
| 2226 bool premultiplyAlpha, | 2226 bool premultiplyAlpha, |
| 2227 Vector<uint8_t>& data) | 2227 Vector<uint8_t>& data) |
| 2228 { | 2228 { |
| 2229 if (!imageData) | 2229 if (!imageData) |
| 2230 return false; | 2230 return false; |
| 2231 int width = imageDataSize.width(); | 2231 int width = imageDataSize.width(); |
| 2232 int height = imageDataSize.height(); | 2232 int height = imageDataSize.height(); |
| 2233 | 2233 |
| 2234 unsigned packedSize; | 2234 unsigned packedSize; |
| 2235 // Output data is tightly packed (alignment == 1). | 2235 // Output data is tightly packed (alignment == 1). |
| 2236 if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GL_NO_ERROR) | 2236 if (computeImageSizeInBytes(format, type, width, height, 1, 1, &packedSize, 0) != GL_NO_ERROR) |
| 2237 return false; | 2237 return false; |
| 2238 data.resize(packedSize); | 2238 data.resize(packedSize); |
| 2239 | 2239 |
| 2240 if (!packPixels(imageData, DataFormatRGBA8, width, height, 0, format, type, premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing, data.data(), flipY)) | 2240 if (!packPixels(imageData, DataFormatRGBA8, width, height, 0, format, type, premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing, data.data(), flipY)) |
| 2241 return false; | 2241 return false; |
| 2242 | 2242 |
| 2243 return true; | 2243 return true; |
| 2244 } | 2244 } |
| 2245 | 2245 |
| 2246 bool WebGLImageConversion::extractTextureData( | 2246 bool WebGLImageConversion::extractTextureData( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2307 } | 2307 } |
| 2308 | 2308 |
| 2309 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride); | 2309 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride); |
| 2310 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); | 2310 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); |
| 2311 if (!converter.Success()) | 2311 if (!converter.Success()) |
| 2312 return false; | 2312 return false; |
| 2313 return true; | 2313 return true; |
| 2314 } | 2314 } |
| 2315 | 2315 |
| 2316 } // namespace blink | 2316 } // namespace blink |
| OLD | NEW |