| Index: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
|
| diff --git a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
|
| index 7c7fd6a947e8c403149cc5fba350045ac2bf6445..b67e4a6ca84ce244d459c1346e967d5601da75c9 100644
|
| --- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
|
| +++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
|
| @@ -4107,7 +4107,7 @@ void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
|
| // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
|
| type = GL_FLOAT;
|
| }
|
| - if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixels->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
|
| + if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebGLImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
|
| synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
|
| return;
|
| }
|
| @@ -4310,10 +4310,24 @@ void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
|
| if (!validateTexFunc("texImage2D", TexImage, SourceImageBitmap, target, level, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0, 0))
|
| return;
|
| ASSERT(bitmap->bitmapImage());
|
| - OwnPtr<uint8_t[]> pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha);
|
| + RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame();
|
| + SkPixmap pixmap;
|
| + OwnPtr<uint8_t[]> pixelData;
|
| + uint8_t* pixelDataPtr = nullptr;
|
| + // TODO(crbug.com/613411): peekPixels fails if the SkImage is texture-backed
|
| + // Use texture mailbox in that case.
|
| + bool peekSucceed = skImage->peekPixels(&pixmap);
|
| + if (peekSucceed) {
|
| + pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr());
|
| + } else if (skImage->isTextureBacked()) {
|
| + pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha);
|
| + pixelDataPtr = pixelData.get();
|
| + }
|
| Vector<uint8_t> data;
|
| bool needConversion = true;
|
| - if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
|
| + bool havePeekableRGBA = (peekSucceed && pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType);
|
| + bool isPixelDataRBGA = (havePeekableRGBA || !peekSucceed);
|
| + if (isPixelDataRBGA && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
|
| needConversion = false;
|
| } else {
|
| if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
|
| @@ -4321,13 +4335,15 @@ void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
|
| type = GL_FLOAT;
|
| }
|
| // In the case of ImageBitmap, we do not need to apply flipY or premultiplyAlpha.
|
| - if (!WebGLImageConversion::extractImageData(pixelData.get(), bitmap->size(), format, type, false, false, data)) {
|
| + bool isPixelDataBGRA = (peekSucceed && pixmap.colorType() == SkColorType::kBGRA_8888_SkColorType);
|
| + if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format, type, false, false, data))
|
| + || (isPixelDataRBGA && !WebGLImageConversion::extractImageData(pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), format, type, false, false, data))) {
|
| synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
|
| return;
|
| }
|
| }
|
| resetUnpackParameters();
|
| - texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->height(), 0, format, type, needConversion ? data.data() : pixelData.get());
|
| + texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->height(), 0, format, type, needConversion ? data.data() : pixelDataPtr);
|
| restoreUnpackParameters();
|
| }
|
|
|
| @@ -4482,7 +4498,7 @@ void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
|
| if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha) {
|
| needConversion = false;
|
| } else {
|
| - if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixels->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
|
| + if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebGLImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
|
| synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data");
|
| return;
|
| }
|
| @@ -4580,20 +4596,34 @@ void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
|
| type = GL_FLOAT;
|
| }
|
| ASSERT(bitmap->bitmapImage());
|
| - OwnPtr<uint8_t[]> pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha);
|
| + RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame();
|
| + SkPixmap pixmap;
|
| + OwnPtr<uint8_t[]> pixelData;
|
| + uint8_t* pixelDataPtr = nullptr;
|
| + bool peekSucceed = skImage->peekPixels(&pixmap);
|
| + if (peekSucceed) {
|
| + pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr());
|
| + } else if (skImage->isTextureBacked()) {
|
| + pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha);
|
| + pixelDataPtr = pixelData.get();
|
| + }
|
| Vector<uint8_t> data;
|
| bool needConversion = true;
|
| - if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
|
| + bool havePeekableRGBA = (peekSucceed && pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType);
|
| + bool isPixelDataRBGA = (havePeekableRGBA || !peekSucceed);
|
| + if (isPixelDataRBGA && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
|
| needConversion = false;
|
| } else {
|
| // In the case of ImageBitmap, we do not need to apply flipY or premultiplyAlpha.
|
| - if (!WebGLImageConversion::extractImageData(pixelData.get(), bitmap->size(), format, type, false, false, data)) {
|
| + bool isPixelDataBGRA = (peekSucceed && pixmap.colorType() == SkColorType::kBGRA_8888_SkColorType);
|
| + if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format, type, false, false, data))
|
| + || (isPixelDataRBGA && !WebGLImageConversion::extractImageData(pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), format, type, false, false, data))) {
|
| synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data");
|
| return;
|
| }
|
| }
|
| resetUnpackParameters();
|
| - contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->width(), bitmap->height(), format, type, needConversion ? data.data() : pixelData.get());
|
| + contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->width(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr);
|
| restoreUnpackParameters();
|
| }
|
|
|
|
|