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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "modules/webgl/WebGL2RenderingContextBase.h" 5 #include "modules/webgl/WebGL2RenderingContextBase.h"
6 6
7 #include "bindings/modules/v8/WebGLAny.h" 7 #include "bindings/modules/v8/WebGLAny.h"
8 #include "core/frame/ImageBitmap.h" 8 #include "core/frame/ImageBitmap.h"
9 #include "core/html/HTMLCanvasElement.h" 9 #include "core/html/HTMLCanvasElement.h"
10 #include "core/html/HTMLImageElement.h" 10 #include "core/html/HTMLImageElement.h"
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 1065 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
1066 type = GL_FLOAT; 1066 type = GL_FLOAT;
1067 } 1067 }
1068 Vector<uint8_t> data; 1068 Vector<uint8_t> data;
1069 bool needConversion = true; 1069 bool needConversion = true;
1070 // The data from ImageData is always of format RGBA8. 1070 // The data from ImageData is always of format RGBA8.
1071 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 1071 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
1072 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) { 1072 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) {
1073 needConversion = false; 1073 needConversion = false;
1074 } else { 1074 } else {
1075 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 1075 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u npackFlipY, m_unpackPremultiplyAlpha, data)) {
1076 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data "); 1076 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data ");
1077 return; 1077 return;
1078 } 1078 }
1079 } 1079 }
1080 resetUnpackParameters(); 1080 resetUnpackParameters();
1081 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, pixels- >width(), pixels->height(), 1, format, type, needConversion ? data.data() : pixe ls->data()->data()); 1081 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, pixels- >width(), pixels->height(), 1, format, type, needConversion ? data.data() : pixe ls->data()->data());
1082 restoreUnpackParameters(); 1082 restoreUnpackParameters();
1083 } 1083 }
1084 1084
1085 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, HTMLImageEle ment* image, ExceptionState& exceptionState) 1085 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, HTMLImageEle ment* image, ExceptionState& exceptionState)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 return; 1142 return;
1143 if (!validateTexture3DBinding("texSubImage3D", target)) 1143 if (!validateTexture3DBinding("texSubImage3D", target))
1144 return; 1144 return;
1145 if (!validateTexFunc("texSubImage3D", TexSubImage, SourceImageBitmap, target , level, 0, bitmap->width(), bitmap->height(), 1, 0, format, type, xoffset, yoff set, zoffset)) 1145 if (!validateTexFunc("texSubImage3D", TexSubImage, SourceImageBitmap, target , level, 0, bitmap->width(), bitmap->height(), 1, 0, format, type, xoffset, yoff set, zoffset))
1146 return; 1146 return;
1147 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 1147 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
1148 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 1148 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
1149 type = GL_FLOAT; 1149 type = GL_FLOAT;
1150 } 1150 }
1151 ASSERT(bitmap->bitmapImage()); 1151 ASSERT(bitmap->bitmapImage());
1152 OwnPtr<uint8_t[]> pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied () ? PremultiplyAlpha : DontPremultiplyAlpha); 1152 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame();
1153 SkPixmap pixmap;
1154 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
1155 bool peekSucceed = skImage->peekPixels(&pixmap);
1156 if (peekSucceed)
1157 pixelData = static_cast<uint8_t*>(pixmap.writable_addr());
1158 else if (skImage->isTextureBacked())
1159 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip lyAlpha : DontPremultiplyAlpha).leakPtr();
1153 Vector<uint8_t> data; 1160 Vector<uint8_t> data;
1154 bool needConversion = true; 1161 bool needConversion = true;
1155 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) { 1162 if (((peekSucceed && pixmap.colorType() == SkColorType::kRGBA_8888_SkColorTy pe) || !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.
1156 needConversion = false; 1163 needConversion = false;
1157 } else { 1164 } else {
1158 // In the case of ImageBitmap, we do not need to apply flipY or premulti plyAlpha. 1165 // In the case of ImageBitmap, we do not need to apply flipY or premulti plyAlpha.
1159 if (!WebGLImageConversion::extractImageData(pixelData.get(), bitmap->siz e(), format, type, false, false, data)) { 1166 if ((peekSucceed && pixmap.colorType() == SkColorType::kBGRA_8888_SkColo rType && !WebGLImageConversion::extractImageData(pixelData, WebGLImageConversion ::DataFormat::DataFormatBGRA8, bitmap->size(), format, type, false, false, data) )
1167 || (((peekSucceed && pixmap.colorType() == SkColorType::kRGBA_8888_S kColorType) || !peekSucceed) && !WebGLImageConversion::extractImageData(pixelDat a, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), format, ty pe, false, false, data))) {
1160 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data "); 1168 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data ");
1161 return; 1169 return;
1162 } 1170 }
1163 } 1171 }
1164 resetUnpackParameters(); 1172 resetUnpackParameters();
1165 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bitmap- >width(), bitmap->height(), 1, format, type, needConversion ? data.data() : pixe lData.get()); 1173 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bitmap- >width(), bitmap->height(), 1, format, type, needConversion ? data.data() : pixe lData);
1166 restoreUnpackParameters(); 1174 restoreUnpackParameters();
1167 } 1175 }
1168 1176
1169 void WebGL2RenderingContextBase::copyTexSubImage3D(GLenum target, GLint level, G Lint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLs izei height) 1177 void WebGL2RenderingContextBase::copyTexSubImage3D(GLenum target, GLint level, G Lint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLs izei height)
1170 { 1178 {
1171 if (isContextLost()) 1179 if (isContextLost())
1172 return; 1180 return;
1173 if (!validateTexture3DBinding("copyTexSubImage3D", target)) 1181 if (!validateTexture3DBinding("copyTexSubImage3D", target))
1174 return; 1182 return;
1175 WebGLFramebuffer* readFramebufferBinding = nullptr; 1183 WebGLFramebuffer* readFramebufferBinding = nullptr;
(...skipping 2413 matching lines...) Expand 10 before | Expand all | Expand 10 after
3589 params.skipPixels = m_unpackSkipPixels; 3597 params.skipPixels = m_unpackSkipPixels;
3590 params.skipRows = m_unpackSkipRows; 3598 params.skipRows = m_unpackSkipRows;
3591 if (dimension == Tex3D) { 3599 if (dimension == Tex3D) {
3592 params.imageHeight = m_unpackImageHeight; 3600 params.imageHeight = m_unpackImageHeight;
3593 params.skipImages = m_unpackSkipImages; 3601 params.skipImages = m_unpackSkipImages;
3594 } 3602 }
3595 return params; 3603 return params;
3596 } 3604 }
3597 3605
3598 } // namespace blink 3606 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698