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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 2791813003: Fix broken draw/upload paths from videos to 2D canvas and WebGL. (Closed)
Patch Set: Disable GPU-GPU copies to floating-point textures on Android. Created 3 years, 8 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 /* 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 4897 matching lines...) Expand 10 before | Expand all | Expand 10 after
4908 GLint internalformat, 4908 GLint internalformat,
4909 GLenum format, 4909 GLenum format,
4910 GLenum type, 4910 GLenum type,
4911 HTMLImageElement* image, 4911 HTMLImageElement* image,
4912 ExceptionState& exception_state) { 4912 ExceptionState& exception_state) {
4913 TexImageHelperHTMLImageElement(kTexImage2D, target, level, internalformat, 4913 TexImageHelperHTMLImageElement(kTexImage2D, target, level, internalformat,
4914 format, type, 0, 0, 0, image, 4914 format, type, 0, 0, 0, image,
4915 SentinelEmptyRect(), 1, 0, exception_state); 4915 SentinelEmptyRect(), 1, 0, exception_state);
4916 } 4916 }
4917 4917
4918 bool WebGLRenderingContextBase::CanUseTexImageByGPU(GLenum type) { 4918 bool WebGLRenderingContextBase::CanUseTexImageByGPU(GLenum format,
4919 GLenum type) {
4919 #if OS(MACOSX) 4920 #if OS(MACOSX)
4920 // RGB5_A1 is not color-renderable on NVIDIA Mac, see crbug.com/676209. 4921 // RGB5_A1 is not color-renderable on NVIDIA Mac, see crbug.com/676209.
4921 // Though, glCopyTextureCHROMIUM can handle RGB5_A1 internalformat by doing a 4922 // Though, glCopyTextureCHROMIUM can handle RGB5_A1 internalformat by doing a
4922 // fallback path, but it doesn't know the type info. So, we still cannot do 4923 // fallback path, but it doesn't know the type info. So, we still cannot do
4923 // the fallback path in glCopyTextureCHROMIUM for 4924 // the fallback path in glCopyTextureCHROMIUM for
4924 // RGBA/RGBA/UNSIGNED_SHORT_5_5_5_1 format and type combination. 4925 // RGBA/RGBA/UNSIGNED_SHORT_5_5_5_1 format and type combination.
4925 if (type == GL_UNSIGNED_SHORT_5_5_5_1) 4926 if (type == GL_UNSIGNED_SHORT_5_5_5_1)
4926 return false; 4927 return false;
4927 #endif 4928 #endif
4929 // TODO(kbr): bugs were observed when using CopyTextureCHROMIUM to
4930 // copy hardware-accelerated video textures to red-channel textures.
4931 // These bugs were seen on macOS but may indicate more general
4932 // problems. Investigate the root cause of this and fix it.
4933 // crbug.com/710673
4934 if (format == GL_RED || format == GL_RED_INTEGER)
4935 return false;
4936
4937 #if OS(ANDROID)
4938 // TODO(kbr): bugs were seen on Android devices with NVIDIA GPUs
4939 // when copying hardware-accelerated video textures to
4940 // floating-point textures. Investigate the root cause of this and
4941 // fix it. crbug.com/710874
4942 if (type == GL_FLOAT)
4943 return false;
4944 #endif
4945
4928 // OES_texture_half_float doesn't support HALF_FLOAT_OES type for 4946 // OES_texture_half_float doesn't support HALF_FLOAT_OES type for
4929 // CopyTexImage/CopyTexSubImage. And OES_texture_half_float doesn't require 4947 // CopyTexImage/CopyTexSubImage. And OES_texture_half_float doesn't require
4930 // HALF_FLOAT_OES type texture to be renderable. So, HALF_FLOAT_OES type 4948 // HALF_FLOAT_OES type texture to be renderable. So, HALF_FLOAT_OES type
4931 // texture cannot be copied to or drawn to by glCopyTextureCHROMIUM. 4949 // texture cannot be copied to or drawn to by glCopyTextureCHROMIUM.
4932 if (type == GL_HALF_FLOAT_OES) 4950 if (type == GL_HALF_FLOAT_OES)
4933 return false; 4951 return false;
4934 4952
4935 return true; 4953 return true;
4936 } 4954 }
4937 4955
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
5109 func_name, function_id, canvas, source_sub_rectangle, depth, 5127 func_name, function_id, canvas, source_sub_rectangle, depth,
5110 unpack_image_height, &selecting_sub_rectangle)) { 5128 unpack_image_height, &selecting_sub_rectangle)) {
5111 return; 5129 return;
5112 } 5130 }
5113 5131
5114 if (function_id == kTexImage2D || function_id == kTexSubImage2D) { 5132 if (function_id == kTexImage2D || function_id == kTexSubImage2D) {
5115 // texImageByGPU relies on copyTextureCHROMIUM which doesn't support 5133 // texImageByGPU relies on copyTextureCHROMIUM which doesn't support
5116 // float/integer/sRGB internal format. 5134 // float/integer/sRGB internal format.
5117 // TODO(crbug.com/622958): relax the constrains if copyTextureCHROMIUM is 5135 // TODO(crbug.com/622958): relax the constrains if copyTextureCHROMIUM is
5118 // upgraded to handle more formats. 5136 // upgraded to handle more formats.
5119 if (!canvas->IsAccelerated() || !CanUseTexImageByGPU(type)) { 5137 if (!canvas->IsAccelerated() || !CanUseTexImageByGPU(format, type)) {
5120 // 2D canvas has only FrontBuffer. 5138 // 2D canvas has only FrontBuffer.
5121 TexImageImpl(function_id, target, level, internalformat, xoffset, yoffset, 5139 TexImageImpl(function_id, target, level, internalformat, xoffset, yoffset,
5122 zoffset, format, type, 5140 zoffset, format, type,
5123 canvas 5141 canvas
5124 ->CopiedImage(kFrontBuffer, kPreferAcceleration, 5142 ->CopiedImage(kFrontBuffer, kPreferAcceleration,
5125 FunctionIDToSnapshotReason(function_id)) 5143 FunctionIDToSnapshotReason(function_id))
5126 .Get(), 5144 .Get(),
5127 WebGLImageConversion::kHtmlDomCanvas, unpack_flip_y_, 5145 WebGLImageConversion::kHtmlDomCanvas, unpack_flip_y_,
5128 unpack_premultiply_alpha_, source_sub_rectangle, 1, 0); 5146 unpack_premultiply_alpha_, source_sub_rectangle, 1, 0);
5129 return; 5147 return;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
5221 if (!ValidateTexFunc(func_name, function_type, kSourceHTMLVideoElement, 5239 if (!ValidateTexFunc(func_name, function_type, kSourceHTMLVideoElement,
5222 target, level, internalformat, video->videoWidth(), 5240 target, level, internalformat, video->videoWidth(),
5223 video->videoHeight(), 1, 0, format, type, xoffset, 5241 video->videoHeight(), 1, 0, format, type, xoffset,
5224 yoffset, zoffset)) 5242 yoffset, zoffset))
5225 return; 5243 return;
5226 5244
5227 bool source_image_rect_is_default = 5245 bool source_image_rect_is_default =
5228 source_image_rect == SentinelEmptyRect() || 5246 source_image_rect == SentinelEmptyRect() ||
5229 source_image_rect == 5247 source_image_rect ==
5230 IntRect(0, 0, video->videoWidth(), video->videoHeight()); 5248 IntRect(0, 0, video->videoWidth(), video->videoHeight());
5231 const bool use_copyTextureCHROMIUM = 5249 const bool use_copyTextureCHROMIUM = function_id == kTexImage2D &&
5232 function_id == kTexImage2D && source_image_rect_is_default && 5250 source_image_rect_is_default &&
5233 depth == 1 && GL_TEXTURE_2D == target && CanUseTexImageByGPU(type); 5251 depth == 1 && GL_TEXTURE_2D == target &&
5252 CanUseTexImageByGPU(format, type);
5234 // Format of source video may be 16-bit format, e.g. Y16 format. 5253 // Format of source video may be 16-bit format, e.g. Y16 format.
5235 // glCopyTextureCHROMIUM requires the source texture to be in 8-bit format. 5254 // glCopyTextureCHROMIUM requires the source texture to be in 8-bit format.
5236 // Converting 16-bits formated source texture to 8-bits formated texture will 5255 // Converting 16-bits formated source texture to 8-bits formated texture will
5237 // cause precision lost. So, uploading such video texture to half float or 5256 // cause precision lost. So, uploading such video texture to half float or
5238 // float texture can not use GPU-GPU path. 5257 // float texture can not use GPU-GPU path.
5239 if (use_copyTextureCHROMIUM) { 5258 if (use_copyTextureCHROMIUM) {
5240 DCHECK_EQ(xoffset, 0); 5259 DCHECK_EQ(xoffset, 0);
5241 DCHECK_EQ(yoffset, 0); 5260 DCHECK_EQ(yoffset, 0);
5242 DCHECK_EQ(zoffset, 0); 5261 DCHECK_EQ(zoffset, 0);
5243 // Go through the fast path doing a GPU-GPU textures copy without a readback 5262 // Go through the fast path doing a GPU-GPU textures copy without a readback
5244 // to system memory if possible. Otherwise, it will fall back to the normal 5263 // to system memory if possible. Otherwise, it will fall back to the normal
5245 // SW path. 5264 // SW path.
5246 5265
5247 // Note that neither 5266 if (video->CopyVideoTextureToPlatformTexture(
5248 // HTMLVideoElement::copyVideoTextureToPlatformTexture nor 5267 ContextGL(), texture->Object(), internalformat, format, type,
5249 // ImageBuffer::copyToPlatformTexture allocate the destination texture 5268 unpack_premultiply_alpha_, unpack_flip_y_)) {
5250 // any more.
5251 TexImage2DBase(target, level, internalformat, video->videoWidth(),
5252 video->videoHeight(), 0, format, type, nullptr);
5253
5254 if (video->CopyVideoTextureToPlatformTexture(ContextGL(), texture->Object(),
5255 unpack_premultiply_alpha_,
5256 unpack_flip_y_)) {
5257 texture->UpdateLastUploadedVideo(video->GetWebMediaPlayer()); 5269 texture->UpdateLastUploadedVideo(video->GetWebMediaPlayer());
5258 return; 5270 return;
5259 } 5271 }
5260 } 5272 }
5261 5273
5262 if (source_image_rect_is_default) { 5274 if (source_image_rect_is_default) {
5263 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. It 5275 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. It
5264 // leaves early for other formats or if frame is stored on GPU. 5276 // leaves early for other formats or if frame is stored on GPU.
5265 ScopedUnpackParametersResetRestore( 5277 ScopedUnpackParametersResetRestore(
5266 this, unpack_flip_y_ || unpack_premultiply_alpha_); 5278 this, unpack_flip_y_ || unpack_premultiply_alpha_);
(...skipping 23 matching lines...) Expand all
5290 // using an AcceleratedImageBufferSurface, we enable the WebMediaPlayer 5302 // using an AcceleratedImageBufferSurface, we enable the WebMediaPlayer
5291 // implementation to do any necessary color space conversion on the GPU 5303 // implementation to do any necessary color space conversion on the GPU
5292 // (though it may still do a CPU conversion and upload the results). 5304 // (though it may still do a CPU conversion and upload the results).
5293 video->PaintCurrentFrame( 5305 video->PaintCurrentFrame(
5294 image_buffer->Canvas(), 5306 image_buffer->Canvas(),
5295 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr); 5307 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr);
5296 5308
5297 // This is a straight GPU-GPU copy, any necessary color space conversion 5309 // This is a straight GPU-GPU copy, any necessary color space conversion
5298 // was handled in the paintCurrentFrameInContext() call. 5310 // was handled in the paintCurrentFrameInContext() call.
5299 5311
5312 // Note that copyToPlatformTexture no longer allocates the destination
5313 // texture.
5314 TexImage2DBase(target, level, internalformat, video->videoWidth(),
5315 video->videoHeight(), 0, format, type, nullptr);
5316
5300 if (image_buffer->CopyToPlatformTexture( 5317 if (image_buffer->CopyToPlatformTexture(
5301 FunctionIDToSnapshotReason(function_id), ContextGL(), target, 5318 FunctionIDToSnapshotReason(function_id), ContextGL(), target,
5302 texture->Object(), unpack_premultiply_alpha_, unpack_flip_y_, 5319 texture->Object(), unpack_premultiply_alpha_, unpack_flip_y_,
5303 IntPoint(0, 0), 5320 IntPoint(0, 0),
5304 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) { 5321 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) {
5305 texture->UpdateLastUploadedVideo(video->GetWebMediaPlayer()); 5322 texture->UpdateLastUploadedVideo(video->GetWebMediaPlayer());
5306 return; 5323 return;
5307 } 5324 }
5308 } 5325 }
5309 } 5326 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
5386 GLsizei width = source_sub_rect.Width(); 5403 GLsizei width = source_sub_rect.Width();
5387 GLsizei height = source_sub_rect.Height(); 5404 GLsizei height = source_sub_rect.Height();
5388 if (!ValidateTexFunc(func_name, function_type, kSourceImageBitmap, target, 5405 if (!ValidateTexFunc(func_name, function_type, kSourceImageBitmap, target,
5389 level, internalformat, width, height, depth, 0, format, 5406 level, internalformat, width, height, depth, 0, format,
5390 type, xoffset, yoffset, zoffset)) 5407 type, xoffset, yoffset, zoffset))
5391 return; 5408 return;
5392 ASSERT(bitmap->BitmapImage()); 5409 ASSERT(bitmap->BitmapImage());
5393 5410
5394 // TODO(kbr): make this work for sub-rectangles of ImageBitmaps. 5411 // TODO(kbr): make this work for sub-rectangles of ImageBitmaps.
5395 if (function_id != kTexSubImage3D && function_id != kTexImage3D && 5412 if (function_id != kTexSubImage3D && function_id != kTexImage3D &&
5396 bitmap->IsAccelerated() && CanUseTexImageByGPU(type) && 5413 bitmap->IsAccelerated() && CanUseTexImageByGPU(format, type) &&
5397 !selecting_sub_rectangle) { 5414 !selecting_sub_rectangle) {
5398 if (function_id == kTexImage2D) { 5415 if (function_id == kTexImage2D) {
5399 TexImage2DBase(target, level, internalformat, width, height, 0, format, 5416 TexImage2DBase(target, level, internalformat, width, height, 0, format,
5400 type, 0); 5417 type, 0);
5401 TexImageByGPU(function_id, texture, target, level, 0, 0, 0, bitmap, 5418 TexImageByGPU(function_id, texture, target, level, 0, 0, 0, bitmap,
5402 source_sub_rect); 5419 source_sub_rect);
5403 } else if (function_id == kTexSubImage2D) { 5420 } else if (function_id == kTexSubImage2D) {
5404 TexImageByGPU(function_id, texture, target, level, xoffset, yoffset, 0, 5421 TexImageByGPU(function_id, texture, target, level, xoffset, yoffset, 0,
5405 bitmap, source_sub_rect); 5422 bitmap, source_sub_rect);
5406 } 5423 }
(...skipping 2410 matching lines...) Expand 10 before | Expand all | Expand 10 after
7817 7834
7818 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( 7835 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(
7819 HTMLCanvasElementOrOffscreenCanvas& result) const { 7836 HTMLCanvasElementOrOffscreenCanvas& result) const {
7820 if (canvas()) 7837 if (canvas())
7821 result.setHTMLCanvasElement(canvas()); 7838 result.setHTMLCanvasElement(canvas());
7822 else 7839 else
7823 result.setOffscreenCanvas(offscreenCanvas()); 7840 result.setOffscreenCanvas(offscreenCanvas());
7824 } 7841 }
7825 7842
7826 } // namespace blink 7843 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698