Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1040)

Unified Diff: third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp

Issue 2016043002: Avoid copy pixel data in texImage2D(ImageBitmap) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: initialize to nullptr Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp
diff --git a/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp
index 67204a9facc19aa68490ebbe714478df25078954..fd8f73a7acaafae896960cf580391d9ff1b19fe2 100644
--- a/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp
+++ b/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp
@@ -1072,7 +1072,7 @@ void WebGL2RenderingContextBase::texSubImage3D(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, "texSubImage3D", "bad image data");
return;
}
@@ -1149,20 +1149,28 @@ void WebGL2RenderingContextBase::texSubImage3D(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;
+ uint8_t* pixelData = nullptr;
Justin Novosad 2016/05/27 14:16:19 Should use an OwnPtr for this.
xidachen 2016/05/27 15:10:13 I don't think we can do that. SkImage is in charge
Justin Novosad 2016/05/27 16:13:48 That just means you were not doing it right. Not u
xidachen 2016/05/27 17:14:56 Yes, that makes perfect sense. Thanks for pointing
+ bool peekSucceed = skImage->peekPixels(&pixmap);
+ if (peekSucceed)
+ pixelData = static_cast<uint8_t*>(pixmap.writable_addr());
+ else if (skImage->isTextureBacked())
+ pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha).leakPtr();
Vector<uint8_t> data;
bool needConversion = true;
- if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
+ if (((peekSucceed && pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType) || !peekSucceed) && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
Zhenyao Mo 2016/05/27 13:49:21 if peekSucceed is false, why needConversion is set
xidachen 2016/05/27 13:54:44 Sorry for this long if statement. Allow me to expl
Zhenyao Mo 2016/05/27 14:08:30 You are right. I got confused. Should not read co
Justin Novosad 2016/05/27 14:16:19 Please break-up long expressions make the code mor
xidachen 2016/05/27 15:10:13 Done.
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)) {
+ if ((peekSucceed && pixmap.colorType() == SkColorType::kBGRA_8888_SkColorType && !WebGLImageConversion::extractImageData(pixelData, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format, type, false, false, data))
+ || (((peekSucceed && pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType) || !peekSucceed) && !WebGLImageConversion::extractImageData(pixelData, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), format, type, false, false, data))) {
synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data");
return;
}
}
resetUnpackParameters();
- contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bitmap->width(), bitmap->height(), 1, format, type, needConversion ? data.data() : pixelData.get());
+ contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bitmap->width(), bitmap->height(), 1, format, type, needConversion ? data.data() : pixelData);
restoreUnpackParameters();
}

Powered by Google App Engine
This is Rietveld 408576698