| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 OwnPtr<uint8_t[]> pixelData; |
| 1155 uint8_t* pixelDataPtr = nullptr; |
| 1156 bool peekSucceed = skImage->peekPixels(&pixmap); |
| 1157 if (peekSucceed) { |
| 1158 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); |
| 1159 } else if (skImage->isTextureBacked()) { |
| 1160 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip
lyAlpha : DontPremultiplyAlpha); |
| 1161 pixelDataPtr = pixelData.get(); |
| 1162 } |
| 1153 Vector<uint8_t> data; | 1163 Vector<uint8_t> data; |
| 1154 bool needConversion = true; | 1164 bool needConversion = true; |
| 1155 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) { | 1165 bool havePeekableRGBA = (peekSucceed && pixmap.colorType() == SkColorType::k
RGBA_8888_SkColorType); |
| 1166 bool isPixelDataRBGA = (havePeekableRGBA || !peekSucceed); |
| 1167 if (isPixelDataRBGA && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { |
| 1156 needConversion = false; | 1168 needConversion = false; |
| 1157 } else { | 1169 } else { |
| 1158 // In the case of ImageBitmap, we do not need to apply flipY or premulti
plyAlpha. | 1170 // 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)) { | 1171 bool isPixelDataBGRA = (peekSucceed && pixmap.colorType() == SkColorType
::kBGRA_8888_SkColorType); |
| 1172 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat
aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format,
type, false, false, data)) |
| 1173 || (isPixelDataRBGA && !WebGLImageConversion::extractImageData(pixel
DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form
at, type, false, false, data))) { |
| 1160 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data
"); | 1174 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data
"); |
| 1161 return; | 1175 return; |
| 1162 } | 1176 } |
| 1163 } | 1177 } |
| 1164 resetUnpackParameters(); | 1178 resetUnpackParameters(); |
| 1165 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bitmap-
>width(), bitmap->height(), 1, format, type, needConversion ? data.data() : pixe
lData.get()); | 1179 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bitmap-
>width(), bitmap->height(), 1, format, type, needConversion ? data.data() : pixe
lDataPtr); |
| 1166 restoreUnpackParameters(); | 1180 restoreUnpackParameters(); |
| 1167 } | 1181 } |
| 1168 | 1182 |
| 1169 void WebGL2RenderingContextBase::copyTexSubImage3D(GLenum target, GLint level, G
Lint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLs
izei height) | 1183 void WebGL2RenderingContextBase::copyTexSubImage3D(GLenum target, GLint level, G
Lint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLs
izei height) |
| 1170 { | 1184 { |
| 1171 if (isContextLost()) | 1185 if (isContextLost()) |
| 1172 return; | 1186 return; |
| 1173 if (!validateTexture3DBinding("copyTexSubImage3D", target)) | 1187 if (!validateTexture3DBinding("copyTexSubImage3D", target)) |
| 1174 return; | 1188 return; |
| 1175 WebGLFramebuffer* readFramebufferBinding = nullptr; | 1189 WebGLFramebuffer* readFramebufferBinding = nullptr; |
| (...skipping 2413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3589 params.skipPixels = m_unpackSkipPixels; | 3603 params.skipPixels = m_unpackSkipPixels; |
| 3590 params.skipRows = m_unpackSkipRows; | 3604 params.skipRows = m_unpackSkipRows; |
| 3591 if (dimension == Tex3D) { | 3605 if (dimension == Tex3D) { |
| 3592 params.imageHeight = m_unpackImageHeight; | 3606 params.imageHeight = m_unpackImageHeight; |
| 3593 params.skipImages = m_unpackSkipImages; | 3607 params.skipImages = m_unpackSkipImages; |
| 3594 } | 3608 } |
| 3595 return params; | 3609 return params; |
| 3596 } | 3610 } |
| 3597 | 3611 |
| 3598 } // namespace blink | 3612 } // namespace blink |
| OLD | NEW |