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 4892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4903 GLint internalformat, | 4903 GLint internalformat, |
4904 GLenum format, | 4904 GLenum format, |
4905 GLenum type, | 4905 GLenum type, |
4906 HTMLImageElement* image, | 4906 HTMLImageElement* image, |
4907 ExceptionState& exception_state) { | 4907 ExceptionState& exception_state) { |
4908 TexImageHelperHTMLImageElement(kTexImage2D, target, level, internalformat, | 4908 TexImageHelperHTMLImageElement(kTexImage2D, target, level, internalformat, |
4909 format, type, 0, 0, 0, image, | 4909 format, type, 0, 0, 0, image, |
4910 SentinelEmptyRect(), 1, 0, exception_state); | 4910 SentinelEmptyRect(), 1, 0, exception_state); |
4911 } | 4911 } |
4912 | 4912 |
4913 bool WebGLRenderingContextBase::CanUseTexImageByGPU(GLenum format, | 4913 bool WebGLRenderingContextBase::CanUseTexImageByGPU(GLenum type) { |
4914 GLenum type) { | |
4915 #if OS(MACOSX) | 4914 #if OS(MACOSX) |
4916 // RGB5_A1 is not color-renderable on NVIDIA Mac, see crbug.com/676209. | 4915 // RGB5_A1 is not color-renderable on NVIDIA Mac, see crbug.com/676209. |
4917 // Though, glCopyTextureCHROMIUM can handle RGB5_A1 internalformat by doing a | 4916 // Though, glCopyTextureCHROMIUM can handle RGB5_A1 internalformat by doing a |
4918 // fallback path, but it doesn't know the type info. So, we still cannot do | 4917 // fallback path, but it doesn't know the type info. So, we still cannot do |
4919 // the fallback path in glCopyTextureCHROMIUM for | 4918 // the fallback path in glCopyTextureCHROMIUM for |
4920 // RGBA/RGBA/UNSIGNED_SHORT_5_5_5_1 format and type combination. | 4919 // RGBA/RGBA/UNSIGNED_SHORT_5_5_5_1 format and type combination. |
4921 if (type == GL_UNSIGNED_SHORT_5_5_5_1) | 4920 if (type == GL_UNSIGNED_SHORT_5_5_5_1) |
4922 return false; | 4921 return false; |
4923 #endif | 4922 #endif |
4924 // TODO(kbr): bugs were observed when using CopyTextureCHROMIUM to | |
4925 // copy hardware-accelerated video textures to red-channel textures. | |
4926 // These bugs were seen on macOS but may indicate more general | |
4927 // problems. Investigate the root cause of this and fix it. | |
4928 // crbug.com/710673 | |
4929 if (format == GL_RED || format == GL_RED_INTEGER) | |
4930 return false; | |
4931 | |
4932 // OES_texture_half_float doesn't support HALF_FLOAT_OES type for | 4923 // OES_texture_half_float doesn't support HALF_FLOAT_OES type for |
4933 // CopyTexImage/CopyTexSubImage. And OES_texture_half_float doesn't require | 4924 // CopyTexImage/CopyTexSubImage. And OES_texture_half_float doesn't require |
4934 // HALF_FLOAT_OES type texture to be renderable. So, HALF_FLOAT_OES type | 4925 // HALF_FLOAT_OES type texture to be renderable. So, HALF_FLOAT_OES type |
4935 // texture cannot be copied to or drawn to by glCopyTextureCHROMIUM. | 4926 // texture cannot be copied to or drawn to by glCopyTextureCHROMIUM. |
4936 if (type == GL_HALF_FLOAT_OES) | 4927 if (type == GL_HALF_FLOAT_OES) |
4937 return false; | 4928 return false; |
4938 | 4929 |
4939 return true; | 4930 return true; |
4940 } | 4931 } |
4941 | 4932 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5113 func_name, function_id, canvas, source_sub_rectangle, depth, | 5104 func_name, function_id, canvas, source_sub_rectangle, depth, |
5114 unpack_image_height, &selecting_sub_rectangle)) { | 5105 unpack_image_height, &selecting_sub_rectangle)) { |
5115 return; | 5106 return; |
5116 } | 5107 } |
5117 | 5108 |
5118 if (function_id == kTexImage2D || function_id == kTexSubImage2D) { | 5109 if (function_id == kTexImage2D || function_id == kTexSubImage2D) { |
5119 // texImageByGPU relies on copyTextureCHROMIUM which doesn't support | 5110 // texImageByGPU relies on copyTextureCHROMIUM which doesn't support |
5120 // float/integer/sRGB internal format. | 5111 // float/integer/sRGB internal format. |
5121 // TODO(crbug.com/622958): relax the constrains if copyTextureCHROMIUM is | 5112 // TODO(crbug.com/622958): relax the constrains if copyTextureCHROMIUM is |
5122 // upgraded to handle more formats. | 5113 // upgraded to handle more formats. |
5123 if (!canvas->IsAccelerated() || !CanUseTexImageByGPU(format, type)) { | 5114 if (!canvas->IsAccelerated() || !CanUseTexImageByGPU(type)) { |
5124 // 2D canvas has only FrontBuffer. | 5115 // 2D canvas has only FrontBuffer. |
5125 TexImageImpl(function_id, target, level, internalformat, xoffset, yoffset, | 5116 TexImageImpl(function_id, target, level, internalformat, xoffset, yoffset, |
5126 zoffset, format, type, | 5117 zoffset, format, type, |
5127 canvas | 5118 canvas |
5128 ->CopiedImage(kFrontBuffer, kPreferAcceleration, | 5119 ->CopiedImage(kFrontBuffer, kPreferAcceleration, |
5129 FunctionIDToSnapshotReason(function_id)) | 5120 FunctionIDToSnapshotReason(function_id)) |
5130 .Get(), | 5121 .Get(), |
5131 WebGLImageConversion::kHtmlDomCanvas, unpack_flip_y_, | 5122 WebGLImageConversion::kHtmlDomCanvas, unpack_flip_y_, |
5132 unpack_premultiply_alpha_, source_sub_rectangle, 1, 0); | 5123 unpack_premultiply_alpha_, source_sub_rectangle, 1, 0); |
5133 return; | 5124 return; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5225 if (!ValidateTexFunc(func_name, function_type, kSourceHTMLVideoElement, | 5216 if (!ValidateTexFunc(func_name, function_type, kSourceHTMLVideoElement, |
5226 target, level, internalformat, video->videoWidth(), | 5217 target, level, internalformat, video->videoWidth(), |
5227 video->videoHeight(), 1, 0, format, type, xoffset, | 5218 video->videoHeight(), 1, 0, format, type, xoffset, |
5228 yoffset, zoffset)) | 5219 yoffset, zoffset)) |
5229 return; | 5220 return; |
5230 | 5221 |
5231 bool source_image_rect_is_default = | 5222 bool source_image_rect_is_default = |
5232 source_image_rect == SentinelEmptyRect() || | 5223 source_image_rect == SentinelEmptyRect() || |
5233 source_image_rect == | 5224 source_image_rect == |
5234 IntRect(0, 0, video->videoWidth(), video->videoHeight()); | 5225 IntRect(0, 0, video->videoWidth(), video->videoHeight()); |
5235 const bool use_copyTextureCHROMIUM = function_id == kTexImage2D && | 5226 const bool use_copyTextureCHROMIUM = |
5236 source_image_rect_is_default && | 5227 function_id == kTexImage2D && source_image_rect_is_default && |
5237 depth == 1 && GL_TEXTURE_2D == target && | 5228 depth == 1 && GL_TEXTURE_2D == target && CanUseTexImageByGPU(type); |
5238 CanUseTexImageByGPU(format, type); | |
5239 // Format of source video may be 16-bit format, e.g. Y16 format. | 5229 // Format of source video may be 16-bit format, e.g. Y16 format. |
5240 // glCopyTextureCHROMIUM requires the source texture to be in 8-bit format. | 5230 // glCopyTextureCHROMIUM requires the source texture to be in 8-bit format. |
5241 // Converting 16-bits formated source texture to 8-bits formated texture will | 5231 // Converting 16-bits formated source texture to 8-bits formated texture will |
5242 // cause precision lost. So, uploading such video texture to half float or | 5232 // cause precision lost. So, uploading such video texture to half float or |
5243 // float texture can not use GPU-GPU path. | 5233 // float texture can not use GPU-GPU path. |
5244 if (use_copyTextureCHROMIUM) { | 5234 if (use_copyTextureCHROMIUM) { |
5245 DCHECK_EQ(xoffset, 0); | 5235 DCHECK_EQ(xoffset, 0); |
5246 DCHECK_EQ(yoffset, 0); | 5236 DCHECK_EQ(yoffset, 0); |
5247 DCHECK_EQ(zoffset, 0); | 5237 DCHECK_EQ(zoffset, 0); |
5248 // Go through the fast path doing a GPU-GPU textures copy without a readback | 5238 // Go through the fast path doing a GPU-GPU textures copy without a readback |
5249 // to system memory if possible. Otherwise, it will fall back to the normal | 5239 // to system memory if possible. Otherwise, it will fall back to the normal |
5250 // SW path. | 5240 // SW path. |
5251 | 5241 |
5252 if (video->CopyVideoTextureToPlatformTexture( | 5242 // Note that neither |
5253 ContextGL(), texture->Object(), internalformat, format, type, | 5243 // HTMLVideoElement::copyVideoTextureToPlatformTexture nor |
5254 unpack_premultiply_alpha_, unpack_flip_y_)) { | 5244 // ImageBuffer::copyToPlatformTexture allocate the destination texture |
| 5245 // any more. |
| 5246 TexImage2DBase(target, level, internalformat, video->videoWidth(), |
| 5247 video->videoHeight(), 0, format, type, nullptr); |
| 5248 |
| 5249 if (video->CopyVideoTextureToPlatformTexture(ContextGL(), texture->Object(), |
| 5250 unpack_premultiply_alpha_, |
| 5251 unpack_flip_y_)) { |
5255 texture->UpdateLastUploadedVideo(video->GetWebMediaPlayer()); | 5252 texture->UpdateLastUploadedVideo(video->GetWebMediaPlayer()); |
5256 return; | 5253 return; |
5257 } | 5254 } |
5258 } | 5255 } |
5259 | 5256 |
5260 if (source_image_rect_is_default) { | 5257 if (source_image_rect_is_default) { |
5261 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. It | 5258 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. It |
5262 // leaves early for other formats or if frame is stored on GPU. | 5259 // leaves early for other formats or if frame is stored on GPU. |
5263 ScopedUnpackParametersResetRestore( | 5260 ScopedUnpackParametersResetRestore( |
5264 this, unpack_flip_y_ || unpack_premultiply_alpha_); | 5261 this, unpack_flip_y_ || unpack_premultiply_alpha_); |
(...skipping 23 matching lines...) Expand all Loading... |
5288 // using an AcceleratedImageBufferSurface, we enable the WebMediaPlayer | 5285 // using an AcceleratedImageBufferSurface, we enable the WebMediaPlayer |
5289 // implementation to do any necessary color space conversion on the GPU | 5286 // implementation to do any necessary color space conversion on the GPU |
5290 // (though it may still do a CPU conversion and upload the results). | 5287 // (though it may still do a CPU conversion and upload the results). |
5291 video->PaintCurrentFrame( | 5288 video->PaintCurrentFrame( |
5292 image_buffer->Canvas(), | 5289 image_buffer->Canvas(), |
5293 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr); | 5290 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr); |
5294 | 5291 |
5295 // This is a straight GPU-GPU copy, any necessary color space conversion | 5292 // This is a straight GPU-GPU copy, any necessary color space conversion |
5296 // was handled in the paintCurrentFrameInContext() call. | 5293 // was handled in the paintCurrentFrameInContext() call. |
5297 | 5294 |
5298 // Note that copyToPlatformTexture no longer allocates the destination | |
5299 // texture. | |
5300 TexImage2DBase(target, level, internalformat, video->videoWidth(), | |
5301 video->videoHeight(), 0, format, type, nullptr); | |
5302 | |
5303 if (image_buffer->CopyToPlatformTexture( | 5295 if (image_buffer->CopyToPlatformTexture( |
5304 FunctionIDToSnapshotReason(function_id), ContextGL(), target, | 5296 FunctionIDToSnapshotReason(function_id), ContextGL(), target, |
5305 texture->Object(), unpack_premultiply_alpha_, unpack_flip_y_, | 5297 texture->Object(), unpack_premultiply_alpha_, unpack_flip_y_, |
5306 IntPoint(0, 0), | 5298 IntPoint(0, 0), |
5307 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) { | 5299 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) { |
5308 texture->UpdateLastUploadedVideo(video->GetWebMediaPlayer()); | 5300 texture->UpdateLastUploadedVideo(video->GetWebMediaPlayer()); |
5309 return; | 5301 return; |
5310 } | 5302 } |
5311 } | 5303 } |
5312 } | 5304 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5389 GLsizei width = source_sub_rect.Width(); | 5381 GLsizei width = source_sub_rect.Width(); |
5390 GLsizei height = source_sub_rect.Height(); | 5382 GLsizei height = source_sub_rect.Height(); |
5391 if (!ValidateTexFunc(func_name, function_type, kSourceImageBitmap, target, | 5383 if (!ValidateTexFunc(func_name, function_type, kSourceImageBitmap, target, |
5392 level, internalformat, width, height, depth, 0, format, | 5384 level, internalformat, width, height, depth, 0, format, |
5393 type, xoffset, yoffset, zoffset)) | 5385 type, xoffset, yoffset, zoffset)) |
5394 return; | 5386 return; |
5395 ASSERT(bitmap->BitmapImage()); | 5387 ASSERT(bitmap->BitmapImage()); |
5396 | 5388 |
5397 // TODO(kbr): make this work for sub-rectangles of ImageBitmaps. | 5389 // TODO(kbr): make this work for sub-rectangles of ImageBitmaps. |
5398 if (function_id != kTexSubImage3D && function_id != kTexImage3D && | 5390 if (function_id != kTexSubImage3D && function_id != kTexImage3D && |
5399 bitmap->IsAccelerated() && CanUseTexImageByGPU(format, type) && | 5391 bitmap->IsAccelerated() && CanUseTexImageByGPU(type) && |
5400 !selecting_sub_rectangle) { | 5392 !selecting_sub_rectangle) { |
5401 if (function_id == kTexImage2D) { | 5393 if (function_id == kTexImage2D) { |
5402 TexImage2DBase(target, level, internalformat, width, height, 0, format, | 5394 TexImage2DBase(target, level, internalformat, width, height, 0, format, |
5403 type, 0); | 5395 type, 0); |
5404 TexImageByGPU(function_id, texture, target, level, 0, 0, 0, bitmap, | 5396 TexImageByGPU(function_id, texture, target, level, 0, 0, 0, bitmap, |
5405 source_sub_rect); | 5397 source_sub_rect); |
5406 } else if (function_id == kTexSubImage2D) { | 5398 } else if (function_id == kTexSubImage2D) { |
5407 TexImageByGPU(function_id, texture, target, level, xoffset, yoffset, 0, | 5399 TexImageByGPU(function_id, texture, target, level, xoffset, yoffset, 0, |
5408 bitmap, source_sub_rect); | 5400 bitmap, source_sub_rect); |
5409 } | 5401 } |
(...skipping 2405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7815 | 7807 |
7816 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( | 7808 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( |
7817 HTMLCanvasElementOrOffscreenCanvas& result) const { | 7809 HTMLCanvasElementOrOffscreenCanvas& result) const { |
7818 if (canvas()) | 7810 if (canvas()) |
7819 result.setHTMLCanvasElement(canvas()); | 7811 result.setHTMLCanvasElement(canvas()); |
7820 else | 7812 else |
7821 result.setOffscreenCanvas(offscreenCanvas()); | 7813 result.setOffscreenCanvas(offscreenCanvas()); |
7822 } | 7814 } |
7823 | 7815 |
7824 } // namespace blink | 7816 } // namespace blink |
OLD | NEW |