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

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: change to OwnPtr 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..7cfd619db6c863d5bdcb01e239d49562bad9dadb 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,34 @@ 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;
+ 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, "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() : pixelDataPtr);
restoreUnpackParameters();
}

Powered by Google App Engine
This is Rietveld 408576698