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

Unified Diff: media/renderers/skcanvas_video_renderer.cc

Issue 2562003003: Fix the size of video textures uploaded to WebGL. (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/renderers/skcanvas_video_renderer.h ('k') | third_party/WebKit/Source/core/html/HTMLVideoElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/renderers/skcanvas_video_renderer.cc
diff --git a/media/renderers/skcanvas_video_renderer.cc b/media/renderers/skcanvas_video_renderer.cc
index 0467878ed9795ca24215234c965be2f2866ac90f..4f22adbcf3afc8f3df70f3344ee1df6b9d770de4 100644
--- a/media/renderers/skcanvas_video_renderer.cc
+++ b/media/renderers/skcanvas_video_renderer.cc
@@ -184,9 +184,12 @@ sk_sp<SkImage> NewSkImageFromVideoFrameNative(VideoFrame* video_frame,
gl->GenTextures(1, &source_texture);
DCHECK(source_texture);
gl->BindTexture(GL_TEXTURE_2D, source_texture);
+ const gfx::Size& natural_size = video_frame->natural_size();
+ gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, natural_size.width(),
+ natural_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
+ nullptr);
SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture(
- gl, video_frame, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, true,
- false);
+ gl, video_frame, source_texture, true, false);
} else {
gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData());
source_texture = gl->CreateAndConsumeTextureCHROMIUM(
@@ -750,8 +753,6 @@ void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture(
gpu::gles2::GLES2Interface* gl,
VideoFrame* video_frame,
unsigned int texture,
- unsigned int internal_format,
- unsigned int type,
bool premultiply_alpha,
bool flip_y) {
DCHECK(video_frame);
@@ -773,8 +774,15 @@ void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture(
// value down to get the expected result.
// "flip_y == true" means to reverse the video orientation while
// "flip_y == false" means to keep the intrinsic orientation.
- gl->CopyTextureCHROMIUM(source_texture, texture, internal_format, type,
- flip_y, premultiply_alpha, false);
+
+ // The video's texture might be larger than the natural size because
+ // the encoder might have had to round up to the size of a macroblock.
+ // Make sure to only copy the natural size to avoid putting garbage
+ // into the bottom of the destination texture.
+ const gfx::Size& natural_size = video_frame->natural_size();
+ gl->CopySubTextureCHROMIUM(source_texture, texture, 0, 0, 0, 0,
+ natural_size.width(), natural_size.height(),
+ flip_y, premultiply_alpha, false);
gl->DeleteTextures(1, &source_texture);
gl->Flush();
@@ -787,8 +795,6 @@ bool SkCanvasVideoRenderer::CopyVideoFrameTexturesToGLTexture(
gpu::gles2::GLES2Interface* destination_gl,
const scoped_refptr<VideoFrame>& video_frame,
unsigned int texture,
- unsigned int internal_format,
- unsigned int type,
bool premultiply_alpha,
bool flip_y) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -825,9 +831,14 @@ bool SkCanvasVideoRenderer::CopyVideoFrameTexturesToGLTexture(
destination_gl->CreateAndConsumeTextureCHROMIUM(
mailbox_holder.texture_target, mailbox_holder.mailbox.name);
- destination_gl->CopyTextureCHROMIUM(intermediate_texture, texture,
- internal_format, type, flip_y,
- premultiply_alpha, false);
+ // The video's texture might be larger than the natural size because
+ // the encoder might have had to round up to the size of a macroblock.
+ // Make sure to only copy the natural size to avoid putting garbage
+ // into the bottom of the destination texture.
+ gfx::Size natural_size = video_frame->natural_size();
DaleCurtis 2016/12/12 19:12:23 const& for consistency?
Ken Russell (switch to Gerrit) 2016/12/20 04:45:33 Yes, thanks. Done.
+ destination_gl->CopySubTextureCHROMIUM(
+ intermediate_texture, texture, 0, 0, 0, 0, natural_size.width(),
+ natural_size.height(), flip_y, premultiply_alpha, false);
destination_gl->DeleteTextures(1, &intermediate_texture);
// Wait for destination context to consume mailbox before deleting it in
@@ -843,8 +854,7 @@ bool SkCanvasVideoRenderer::CopyVideoFrameTexturesToGLTexture(
video_frame->UpdateReleaseSyncToken(&client);
} else {
CopyVideoFrameSingleTextureToGLTexture(destination_gl, video_frame.get(),
- texture, internal_format, type,
- premultiply_alpha, flip_y);
+ texture, premultiply_alpha, flip_y);
}
return true;
« no previous file with comments | « media/renderers/skcanvas_video_renderer.h ('k') | third_party/WebKit/Source/core/html/HTMLVideoElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698