| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 5245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5256 TexImageFunctionID functionID, | 5256 TexImageFunctionID functionID, |
| 5257 GLenum target, | 5257 GLenum target, |
| 5258 GLint level, | 5258 GLint level, |
| 5259 GLint internalformat, | 5259 GLint internalformat, |
| 5260 GLenum format, | 5260 GLenum format, |
| 5261 GLenum type, | 5261 GLenum type, |
| 5262 GLint xoffset, | 5262 GLint xoffset, |
| 5263 GLint yoffset, | 5263 GLint yoffset, |
| 5264 GLint zoffset, | 5264 GLint zoffset, |
| 5265 ImageBitmap* bitmap, | 5265 ImageBitmap* bitmap, |
| 5266 const IntRect& sourceSubRect, |
| 5267 GLsizei depth, |
| 5268 GLint unpackImageHeight, |
| 5266 ExceptionState& exceptionState) { | 5269 ExceptionState& exceptionState) { |
| 5267 const char* funcName = getTexImageFunctionName(functionID); | 5270 const char* funcName = getTexImageFunctionName(functionID); |
| 5268 if (isContextLost()) | 5271 if (isContextLost()) |
| 5269 return; | 5272 return; |
| 5270 if (!validateImageBitmap(funcName, bitmap, exceptionState)) | 5273 if (!validateImageBitmap(funcName, bitmap, exceptionState)) |
| 5271 return; | 5274 return; |
| 5272 WebGLTexture* texture = validateTexImageBinding(funcName, functionID, target); | 5275 WebGLTexture* texture = validateTexImageBinding(funcName, functionID, target); |
| 5273 if (!texture) | 5276 if (!texture) |
| 5274 return; | 5277 return; |
| 5278 |
| 5279 bool selectingSubRectangle = false; |
| 5280 if (!validateTexImageSubRectangle(funcName, functionID, bitmap, sourceSubRect, |
| 5281 depth, unpackImageHeight, |
| 5282 &selectingSubRectangle)) { |
| 5283 return; |
| 5284 } |
| 5285 |
| 5275 TexImageFunctionType functionType; | 5286 TexImageFunctionType functionType; |
| 5276 if (functionID == TexImage2D) | 5287 if (functionID == TexImage2D) |
| 5277 functionType = TexImage; | 5288 functionType = TexImage; |
| 5278 else | 5289 else |
| 5279 functionType = TexSubImage; | 5290 functionType = TexSubImage; |
| 5291 |
| 5292 GLsizei width = sourceSubRect.width(); |
| 5293 GLsizei height = sourceSubRect.height(); |
| 5280 if (!validateTexFunc(funcName, functionType, SourceImageBitmap, target, level, | 5294 if (!validateTexFunc(funcName, functionType, SourceImageBitmap, target, level, |
| 5281 internalformat, bitmap->width(), bitmap->height(), 1, 0, | 5295 internalformat, width, height, depth, 0, format, type, |
| 5282 format, type, xoffset, yoffset, zoffset)) | 5296 xoffset, yoffset, zoffset)) |
| 5283 return; | 5297 return; |
| 5284 ASSERT(bitmap->bitmapImage()); | 5298 ASSERT(bitmap->bitmapImage()); |
| 5285 | 5299 |
| 5286 if (functionID != TexSubImage3D && bitmap->isAccelerated() && | 5300 if (functionID != TexSubImage3D && functionID != TexImage3D && |
| 5287 canUseTexImageByGPU(functionID, internalformat, type)) { | 5301 bitmap->isAccelerated() && |
| 5302 canUseTexImageByGPU(functionID, internalformat, type) && |
| 5303 !selectingSubRectangle) { |
| 5288 if (functionID == TexImage2D) { | 5304 if (functionID == TexImage2D) { |
| 5289 texImage2DBase(target, level, internalformat, bitmap->width(), | 5305 texImage2DBase(target, level, internalformat, width, height, 0, format, |
| 5290 bitmap->height(), 0, format, type, 0); | 5306 type, 0); |
| 5291 texImageByGPU(TexImage2DByGPU, texture, target, level, internalformat, | 5307 texImageByGPU(TexImage2DByGPU, texture, target, level, internalformat, |
| 5292 type, 0, 0, 0, bitmap, getTextureSourceSize(bitmap)); | 5308 type, 0, 0, 0, bitmap, sourceSubRect); |
| 5293 } else if (functionID == TexSubImage2D) { | 5309 } else if (functionID == TexSubImage2D) { |
| 5294 texImageByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, type, | 5310 texImageByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, type, |
| 5295 xoffset, yoffset, 0, bitmap, getTextureSourceSize(bitmap)); | 5311 xoffset, yoffset, 0, bitmap, sourceSubRect); |
| 5296 } | 5312 } |
| 5297 return; | 5313 return; |
| 5298 } | 5314 } |
| 5299 sk_sp<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); | 5315 sk_sp<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); |
| 5300 SkPixmap pixmap; | 5316 SkPixmap pixmap; |
| 5301 uint8_t* pixelDataPtr = nullptr; | 5317 uint8_t* pixelDataPtr = nullptr; |
| 5302 RefPtr<Uint8Array> pixelData; | 5318 RefPtr<Uint8Array> pixelData; |
| 5303 // In the case where an ImageBitmap is not texture backed, peekPixels() always | 5319 // In the case where an ImageBitmap is not texture backed, peekPixels() always |
| 5304 // succeed. However, when it is texture backed and !canUseTexImageByGPU, we | 5320 // succeed. However, when it is texture backed and !canUseTexImageByGPU, we |
| 5305 // do a GPU read back. | 5321 // do a GPU read back. |
| 5306 bool peekSucceed = skImage->peekPixels(&pixmap); | 5322 bool peekSucceed = skImage->peekPixels(&pixmap); |
| 5307 if (peekSucceed) { | 5323 if (peekSucceed) { |
| 5308 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); | 5324 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); |
| 5309 } else { | 5325 } else { |
| 5310 pixelData = bitmap->copyBitmapData( | 5326 pixelData = bitmap->copyBitmapData( |
| 5311 bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha); | 5327 bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha); |
| 5312 pixelDataPtr = pixelData->data(); | 5328 pixelDataPtr = pixelData->data(); |
| 5313 } | 5329 } |
| 5314 Vector<uint8_t> data; | 5330 Vector<uint8_t> data; |
| 5315 bool needConversion = true; | 5331 bool needConversion = true; |
| 5316 bool havePeekableRGBA = | 5332 bool havePeekableRGBA = |
| 5317 (peekSucceed && | 5333 (peekSucceed && |
| 5318 pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType); | 5334 pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType); |
| 5319 bool isPixelDataRGBA = (havePeekableRGBA || !peekSucceed); | 5335 bool isPixelDataRGBA = (havePeekableRGBA || !peekSucceed); |
| 5320 if (isPixelDataRGBA && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { | 5336 if (isPixelDataRGBA && format == GL_RGBA && type == GL_UNSIGNED_BYTE && |
| 5337 !selectingSubRectangle) { |
| 5321 needConversion = false; | 5338 needConversion = false; |
| 5322 } else { | 5339 } else { |
| 5323 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | 5340 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { |
| 5324 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. | 5341 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. |
| 5325 type = GL_FLOAT; | 5342 type = GL_FLOAT; |
| 5326 } | 5343 } |
| 5327 IntRect sourceImageRect(0, 0, bitmap->width(), bitmap->height()); | |
| 5328 // In the case of ImageBitmap, we do not need to apply flipY or | 5344 // In the case of ImageBitmap, we do not need to apply flipY or |
| 5329 // premultiplyAlpha. | 5345 // premultiplyAlpha. |
| 5330 bool isPixelDataBGRA = | 5346 bool isPixelDataBGRA = |
| 5331 pixmap.colorType() == SkColorType::kBGRA_8888_SkColorType; | 5347 pixmap.colorType() == SkColorType::kBGRA_8888_SkColorType; |
| 5332 if ((isPixelDataBGRA && | 5348 if ((isPixelDataBGRA && |
| 5333 !WebGLImageConversion::extractImageData( | 5349 !WebGLImageConversion::extractImageData( |
| 5334 pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, | 5350 pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, |
| 5335 bitmap->size(), sourceImageRect, format, type, false, false, | 5351 bitmap->size(), sourceSubRect, format, type, false, false, |
| 5336 data)) || | 5352 data)) || |
| 5337 (isPixelDataRGBA && | 5353 (isPixelDataRGBA && |
| 5338 !WebGLImageConversion::extractImageData( | 5354 !WebGLImageConversion::extractImageData( |
| 5339 pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, | 5355 pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, |
| 5340 bitmap->size(), sourceImageRect, format, type, false, false, | 5356 bitmap->size(), sourceSubRect, format, type, false, false, |
| 5341 data))) { | 5357 data))) { |
| 5342 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); | 5358 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); |
| 5343 return; | 5359 return; |
| 5344 } | 5360 } |
| 5345 } | 5361 } |
| 5346 resetUnpackParameters(); | 5362 resetUnpackParameters(); |
| 5347 if (functionID == TexImage2D) { | 5363 if (functionID == TexImage2D) { |
| 5348 texImage2DBase(target, level, internalformat, bitmap->width(), | 5364 texImage2DBase(target, level, internalformat, width, height, 0, format, |
| 5349 bitmap->height(), 0, format, type, | 5365 type, needConversion ? data.data() : pixelDataPtr); |
| 5350 needConversion ? data.data() : pixelDataPtr); | |
| 5351 } else if (functionID == TexSubImage2D) { | 5366 } else if (functionID == TexSubImage2D) { |
| 5352 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->width(), | 5367 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, height, |
| 5353 bitmap->height(), format, type, | 5368 format, type, |
| 5354 needConversion ? data.data() : pixelDataPtr); | 5369 needConversion ? data.data() : pixelDataPtr); |
| 5370 } else if (functionID == TexImage3D) { |
| 5371 contextGL()->TexImage3D(target, level, internalformat, width, height, depth, |
| 5372 0, format, type, |
| 5373 needConversion ? data.data() : pixelDataPtr); |
| 5355 } else { | 5374 } else { |
| 5356 DCHECK_EQ(functionID, TexSubImage3D); | 5375 DCHECK_EQ(functionID, TexSubImage3D); |
| 5357 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, | 5376 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, |
| 5358 bitmap->width(), bitmap->height(), 1, format, | 5377 height, depth, format, type, |
| 5359 type, | |
| 5360 needConversion ? data.data() : pixelDataPtr); | 5378 needConversion ? data.data() : pixelDataPtr); |
| 5361 } | 5379 } |
| 5362 restoreUnpackParameters(); | 5380 restoreUnpackParameters(); |
| 5363 } | 5381 } |
| 5364 | 5382 |
| 5365 void WebGLRenderingContextBase::texImage2D(GLenum target, | 5383 void WebGLRenderingContextBase::texImage2D(GLenum target, |
| 5366 GLint level, | 5384 GLint level, |
| 5367 GLint internalformat, | 5385 GLint internalformat, |
| 5368 GLenum format, | 5386 GLenum format, |
| 5369 GLenum type, | 5387 GLenum type, |
| 5370 ImageBitmap* bitmap, | 5388 ImageBitmap* bitmap, |
| 5371 ExceptionState& exceptionState) { | 5389 ExceptionState& exceptionState) { |
| 5372 texImageHelperImageBitmap(TexImage2D, target, level, internalformat, format, | 5390 texImageHelperImageBitmap(TexImage2D, target, level, internalformat, format, |
| 5373 type, 0, 0, 0, bitmap, exceptionState); | 5391 type, 0, 0, 0, bitmap, getTextureSourceSize(bitmap), |
| 5392 1, 0, exceptionState); |
| 5374 } | 5393 } |
| 5375 | 5394 |
| 5376 void WebGLRenderingContextBase::texParameter(GLenum target, | 5395 void WebGLRenderingContextBase::texParameter(GLenum target, |
| 5377 GLenum pname, | 5396 GLenum pname, |
| 5378 GLfloat paramf, | 5397 GLfloat paramf, |
| 5379 GLint parami, | 5398 GLint parami, |
| 5380 bool isFloat) { | 5399 bool isFloat) { |
| 5381 if (isContextLost()) | 5400 if (isContextLost()) |
| 5382 return; | 5401 return; |
| 5383 if (!validateTextureBinding("texParameter", target)) | 5402 if (!validateTextureBinding("texParameter", target)) |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5514 | 5533 |
| 5515 void WebGLRenderingContextBase::texSubImage2D(GLenum target, | 5534 void WebGLRenderingContextBase::texSubImage2D(GLenum target, |
| 5516 GLint level, | 5535 GLint level, |
| 5517 GLint xoffset, | 5536 GLint xoffset, |
| 5518 GLint yoffset, | 5537 GLint yoffset, |
| 5519 GLenum format, | 5538 GLenum format, |
| 5520 GLenum type, | 5539 GLenum type, |
| 5521 ImageBitmap* bitmap, | 5540 ImageBitmap* bitmap, |
| 5522 ExceptionState& exceptionState) { | 5541 ExceptionState& exceptionState) { |
| 5523 texImageHelperImageBitmap(TexSubImage2D, target, level, 0, format, type, | 5542 texImageHelperImageBitmap(TexSubImage2D, target, level, 0, format, type, |
| 5524 xoffset, yoffset, 0, bitmap, exceptionState); | 5543 xoffset, yoffset, 0, bitmap, |
| 5544 getTextureSourceSize(bitmap), 1, 0, exceptionState); |
| 5525 } | 5545 } |
| 5526 | 5546 |
| 5527 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, | 5547 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, |
| 5528 GLfloat x) { | 5548 GLfloat x) { |
| 5529 if (isContextLost() || !location) | 5549 if (isContextLost() || !location) |
| 5530 return; | 5550 return; |
| 5531 | 5551 |
| 5532 if (location->program() != m_currentProgram) { | 5552 if (location->program() != m_currentProgram) { |
| 5533 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", | 5553 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", |
| 5534 "location not for current program"); | 5554 "location not for current program"); |
| (...skipping 2234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7769 | 7789 |
| 7770 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( | 7790 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( |
| 7771 HTMLCanvasElementOrOffscreenCanvas& result) const { | 7791 HTMLCanvasElementOrOffscreenCanvas& result) const { |
| 7772 if (canvas()) | 7792 if (canvas()) |
| 7773 result.setHTMLCanvasElement(canvas()); | 7793 result.setHTMLCanvasElement(canvas()); |
| 7774 else | 7794 else |
| 7775 result.setOffscreenCanvas(getOffscreenCanvas()); | 7795 result.setOffscreenCanvas(getOffscreenCanvas()); |
| 7776 } | 7796 } |
| 7777 | 7797 |
| 7778 } // namespace blink | 7798 } // namespace blink |
| OLD | NEW |