diff options
author | reveman <reveman@chromium.org> | 2015-05-12 16:01:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-12 23:02:06 +0000 |
commit | b71e399156a93a2ea675c77f1cb98c84dac813eb (patch) | |
tree | fedf2b157319f491af6cfbbad7764f62fbae396f /cc | |
parent | 6021e9b9d234d8d87044c8ad8b6b114ae271e8eb (diff) | |
download | chromium_src-b71e399156a93a2ea675c77f1cb98c84dac813eb.zip chromium_src-b71e399156a93a2ea675c77f1cb98c84dac813eb.tar.gz chromium_src-b71e399156a93a2ea675c77f1cb98c84dac813eb.tar.bz2 |
cc: Add support for non-2D texture targets to YUVVideoQuad.
This removes the TEXTURE_2D target and normalized coordinates
assumption from the YUVVideoQuad code. This is a prerequisite
to using IOSurface/SurfaceTexture backed GpuMemoryBuffers for
zero-copy transfer of software decoded video frames to the
graphics hardware.
BUG=485859
TEST=cc_unittests --gtest_filter=VideoGLRendererPixelTest.*
Review URL: https://codereview.chromium.org/1131253003
Cr-Commit-Position: refs/heads/master@{#329524}
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layers/video_layer_impl.cc | 23 | ||||
-rw-r--r-- | cc/output/gl_renderer.cc | 120 | ||||
-rw-r--r-- | cc/output/gl_renderer.h | 14 | ||||
-rw-r--r-- | cc/output/gl_renderer_unittest.cc | 4 | ||||
-rw-r--r-- | cc/output/renderer_pixeltest.cc | 14 | ||||
-rw-r--r-- | cc/output/shader.cc | 40 | ||||
-rw-r--r-- | cc/output/shader.h | 12 | ||||
-rw-r--r-- | cc/quads/draw_quad_unittest.cc | 63 | ||||
-rw-r--r-- | cc/quads/tile_draw_quad.h | 6 | ||||
-rw-r--r-- | cc/quads/yuv_video_draw_quad.cc | 15 | ||||
-rw-r--r-- | cc/quads/yuv_video_draw_quad.h | 16 | ||||
-rw-r--r-- | cc/test/render_pass_test_common.cc | 3 |
12 files changed, 217 insertions, 113 deletions
diff --git a/cc/layers/video_layer_impl.cc b/cc/layers/video_layer_impl.cc index 5171971..6f72b01 100644 --- a/cc/layers/video_layer_impl.cc +++ b/cc/layers/video_layer_impl.cc @@ -184,10 +184,6 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass, static_cast<float>(visible_rect.width()) / coded_size.width(); const float tex_height_scale = static_cast<float>(visible_rect.height()) / coded_size.height(); - const float tex_x_offset = - static_cast<float>(visible_rect.x()) / coded_size.width(); - const float tex_y_offset = - static_cast<float>(visible_rect.y()) / coded_size.height(); switch (frame_resource_type_) { // TODO(danakj): Remove this, hide it in the hardware path. @@ -242,14 +238,25 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass, frame_->format(), media::VideoFrame::kAPlane, coded_size)); } - gfx::RectF tex_coord_rect( - tex_x_offset, tex_y_offset, tex_width_scale, tex_height_scale); + // Compute the UV sub-sampling factor based on the ratio between + // |ya_tex_size| and |uv_tex_size|. + float uv_subsampling_factor_x = + static_cast<float>(ya_tex_size.width()) / uv_tex_size.width(); + float uv_subsampling_factor_y = + static_cast<float>(ya_tex_size.height()) / uv_tex_size.height(); + gfx::RectF ya_tex_coord_rect(visible_rect); + gfx::RectF uv_tex_coord_rect( + visible_rect.x() / uv_subsampling_factor_x, + visible_rect.y() / uv_subsampling_factor_y, + visible_rect.width() / uv_subsampling_factor_x, + visible_rect.height() / uv_subsampling_factor_y); + YUVVideoDrawQuad* yuv_video_quad = render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); yuv_video_quad->SetNew( shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, - tex_coord_rect, ya_tex_size, uv_tex_size, frame_resources_[0], - frame_resources_[1], frame_resources_[2], + ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, uv_tex_size, + frame_resources_[0], frame_resources_[1], frame_resources_[2], frame_resources_.size() > 3 ? frame_resources_[3] : 0, color_space); ValidateQuadResources(yuv_video_quad); break; diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc index 6b7e8ff..cfe319b 100644 --- a/cc/output/gl_renderer.cc +++ b/cc/output/gl_renderer.cc @@ -1903,23 +1903,27 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, ResourceProvider::ScopedSamplerGL y_plane_lock( resource_provider_, quad->y_plane_resource_id, GL_TEXTURE1, GL_LINEAR); - DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), y_plane_lock.target()); ResourceProvider::ScopedSamplerGL u_plane_lock( resource_provider_, quad->u_plane_resource_id, GL_TEXTURE2, GL_LINEAR); - DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), u_plane_lock.target()); + DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); ResourceProvider::ScopedSamplerGL v_plane_lock( resource_provider_, quad->v_plane_resource_id, GL_TEXTURE3, GL_LINEAR); - DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), v_plane_lock.target()); + DCHECK_EQ(y_plane_lock.target(), v_plane_lock.target()); scoped_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; if (use_alpha_plane) { a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( resource_provider_, quad->a_plane_resource_id, GL_TEXTURE4, GL_LINEAR)); - DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), a_plane_lock->target()); + DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); } + // All planes must have the same sampler type. + SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); + int matrix_location = -1; - int tex_scale_location = -1; - int tex_offset_location = -1; + int ya_tex_scale_location = -1; + int ya_tex_offset_location = -1; + int uv_tex_scale_location = -1; + int uv_tex_offset_location = -1; int ya_clamp_rect_location = -1; int uv_clamp_rect_location = -1; int y_texture_location = -1; @@ -1930,12 +1934,15 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, int yuv_adj_location = -1; int alpha_location = -1; if (use_alpha_plane) { - const VideoYUVAProgram* program = GetVideoYUVAProgram(tex_coord_precision); + const VideoYUVAProgram* program = + GetVideoYUVAProgram(tex_coord_precision, sampler); DCHECK(program && (program->initialized() || IsContextLost())); SetUseProgram(program->program()); matrix_location = program->vertex_shader().matrix_location(); - tex_scale_location = program->vertex_shader().tex_scale_location(); - tex_offset_location = program->vertex_shader().tex_offset_location(); + ya_tex_scale_location = program->vertex_shader().ya_tex_scale_location(); + ya_tex_offset_location = program->vertex_shader().ya_tex_offset_location(); + uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location(); + uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location(); y_texture_location = program->fragment_shader().y_texture_location(); u_texture_location = program->fragment_shader().u_texture_location(); v_texture_location = program->fragment_shader().v_texture_location(); @@ -1948,12 +1955,15 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, program->fragment_shader().uv_clamp_rect_location(); alpha_location = program->fragment_shader().alpha_location(); } else { - const VideoYUVProgram* program = GetVideoYUVProgram(tex_coord_precision); + const VideoYUVProgram* program = + GetVideoYUVProgram(tex_coord_precision, sampler); DCHECK(program && (program->initialized() || IsContextLost())); SetUseProgram(program->program()); matrix_location = program->vertex_shader().matrix_location(); - tex_scale_location = program->vertex_shader().tex_scale_location(); - tex_offset_location = program->vertex_shader().tex_offset_location(); + ya_tex_scale_location = program->vertex_shader().ya_tex_scale_location(); + ya_tex_offset_location = program->vertex_shader().ya_tex_offset_location(); + uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location(); + uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location(); y_texture_location = program->fragment_shader().y_texture_location(); u_texture_location = program->fragment_shader().u_texture_location(); v_texture_location = program->fragment_shader().v_texture_location(); @@ -1966,23 +1976,52 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, alpha_location = program->fragment_shader().alpha_location(); } - gl_->Uniform2f(tex_scale_location, quad->tex_coord_rect.width(), - quad->tex_coord_rect.height()); - gl_->Uniform2f(tex_offset_location, quad->tex_coord_rect.x(), - quad->tex_coord_rect.y()); - // Clamping to half a texel inside the tex coord rect prevents bilinear - // filtering from filtering outside the tex coord rect. - gfx::RectF ya_clamp_rect(quad->tex_coord_rect); - // Special case: empty texture size implies no clamping. - if (!quad->ya_tex_size.IsEmpty()) { - ya_clamp_rect.Inset(0.5f / quad->ya_tex_size.width(), - 0.5f / quad->ya_tex_size.height()); - } - gfx::RectF uv_clamp_rect(quad->tex_coord_rect); - if (!quad->uv_tex_size.IsEmpty()) { - uv_clamp_rect.Inset(0.5f / quad->uv_tex_size.width(), - 0.5f / quad->uv_tex_size.height()); - } + gfx::SizeF ya_tex_scale(1.0f, 1.0f); + gfx::SizeF uv_tex_scale(1.0f, 1.0f); + if (sampler != SAMPLER_TYPE_2D_RECT) { + DCHECK(!quad->ya_tex_size.IsEmpty()); + DCHECK(!quad->uv_tex_size.IsEmpty()); + ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), + 1.0f / quad->ya_tex_size.height()); + uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(), + 1.0f / quad->uv_tex_size.height()); + } + + float ya_vertex_tex_translate_x = + quad->ya_tex_coord_rect.x() * ya_tex_scale.width(); + float ya_vertex_tex_translate_y = + quad->ya_tex_coord_rect.y() * ya_tex_scale.height(); + float ya_vertex_tex_scale_x = + quad->ya_tex_coord_rect.width() * ya_tex_scale.width(); + float ya_vertex_tex_scale_y = + quad->ya_tex_coord_rect.height() * ya_tex_scale.height(); + + float uv_vertex_tex_translate_x = + quad->uv_tex_coord_rect.x() * uv_tex_scale.width(); + float uv_vertex_tex_translate_y = + quad->uv_tex_coord_rect.y() * uv_tex_scale.height(); + float uv_vertex_tex_scale_x = + quad->uv_tex_coord_rect.width() * uv_tex_scale.width(); + float uv_vertex_tex_scale_y = + quad->uv_tex_coord_rect.height() * uv_tex_scale.height(); + + gl_->Uniform2f(ya_tex_scale_location, ya_vertex_tex_scale_x, + ya_vertex_tex_scale_y); + gl_->Uniform2f(ya_tex_offset_location, ya_vertex_tex_translate_x, + ya_vertex_tex_translate_y); + gl_->Uniform2f(uv_tex_scale_location, uv_vertex_tex_scale_x, + uv_vertex_tex_scale_y); + gl_->Uniform2f(uv_tex_offset_location, uv_vertex_tex_translate_x, + uv_vertex_tex_translate_y); + + gfx::RectF ya_clamp_rect(ya_vertex_tex_translate_x, ya_vertex_tex_translate_y, + ya_vertex_tex_scale_x, ya_vertex_tex_scale_y); + ya_clamp_rect.Inset(0.5f * ya_tex_scale.width(), + 0.5f * ya_tex_scale.height()); + gfx::RectF uv_clamp_rect(uv_vertex_tex_translate_x, uv_vertex_tex_translate_y, + uv_vertex_tex_scale_x, uv_vertex_tex_scale_y); + uv_clamp_rect.Inset(0.5f * uv_tex_scale.width(), + 0.5f * uv_tex_scale.height()); gl_->Uniform4f(ya_clamp_rect_location, ya_clamp_rect.x(), ya_clamp_rect.y(), ya_clamp_rect.right(), ya_clamp_rect.bottom()); gl_->Uniform4f(uv_clamp_rect_location, uv_clamp_rect.x(), uv_clamp_rect.y(), @@ -3284,27 +3323,33 @@ const GLRenderer::TextureProgram* GLRenderer::GetTextureIOSurfaceProgram( } const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( - TexCoordPrecision precision) { + TexCoordPrecision precision, + SamplerType sampler) { DCHECK_GE(precision, 0); DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); - VideoYUVProgram* program = &video_yuv_program_[precision]; + DCHECK_GE(sampler, 0); + DCHECK_LE(sampler, LAST_SAMPLER_TYPE); + VideoYUVProgram* program = &video_yuv_program_[precision][sampler]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); program->Initialize(output_surface_->context_provider(), precision, - SAMPLER_TYPE_2D); + sampler); } return program; } const GLRenderer::VideoYUVAProgram* GLRenderer::GetVideoYUVAProgram( - TexCoordPrecision precision) { + TexCoordPrecision precision, + SamplerType sampler) { DCHECK_GE(precision, 0); DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); - VideoYUVAProgram* program = &video_yuva_program_[precision]; + DCHECK_GE(sampler, 0); + DCHECK_LE(sampler, LAST_SAMPLER_TYPE); + VideoYUVAProgram* program = &video_yuva_program_[precision][sampler]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize"); program->Initialize(output_surface_->context_provider(), precision, - SAMPLER_TYPE_2D); + sampler); } return program; } @@ -3345,6 +3390,9 @@ void GLRenderer::CleanupSharedObjects() { render_pass_mask_color_matrix_program_[i][j][k][l].Cleanup(gl_); } } + + video_yuv_program_[i][j].Cleanup(gl_); + video_yuva_program_[i][j].Cleanup(gl_); } for (int j = 0; j <= LAST_BLEND_MODE; j++) { render_pass_program_[i][j].Cleanup(gl_); @@ -3361,8 +3409,6 @@ void GLRenderer::CleanupSharedObjects() { } texture_io_surface_program_[i].Cleanup(gl_); - video_yuv_program_[i].Cleanup(gl_); - video_yuva_program_[i].Cleanup(gl_); video_stream_texture_program_[i].Cleanup(gl_); } diff --git a/cc/output/gl_renderer.h b/cc/output/gl_renderer.h index 2bf308b..324a7bd 100644 --- a/cc/output/gl_renderer.h +++ b/cc/output/gl_renderer.h @@ -401,10 +401,10 @@ class CC_EXPORT GLRenderer : public DirectRenderer { const TextureProgram* GetTextureIOSurfaceProgram( TexCoordPrecision precision); - const VideoYUVProgram* GetVideoYUVProgram( - TexCoordPrecision precision); - const VideoYUVAProgram* GetVideoYUVAProgram( - TexCoordPrecision precision); + const VideoYUVProgram* GetVideoYUVProgram(TexCoordPrecision precision, + SamplerType sampler); + const VideoYUVAProgram* GetVideoYUVAProgram(TexCoordPrecision precision, + SamplerType sampler); const VideoStreamTextureProgram* GetVideoStreamTextureProgram( TexCoordPrecision precision); @@ -472,8 +472,10 @@ class CC_EXPORT GLRenderer : public DirectRenderer { [LAST_BLEND_MODE + 1] [LAST_MASK_VALUE + 1]; - VideoYUVProgram video_yuv_program_[LAST_TEX_COORD_PRECISION + 1]; - VideoYUVAProgram video_yuva_program_[LAST_TEX_COORD_PRECISION + 1]; + VideoYUVProgram + video_yuv_program_[LAST_TEX_COORD_PRECISION + 1][LAST_SAMPLER_TYPE + 1]; + VideoYUVAProgram + video_yuva_program_[LAST_TEX_COORD_PRECISION + 1][LAST_SAMPLER_TYPE + 1]; VideoStreamTextureProgram video_stream_texture_program_[LAST_TEX_COORD_PRECISION + 1]; diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc index 91abca1..8fe1e80 100644 --- a/cc/output/gl_renderer_unittest.cc +++ b/cc/output/gl_renderer_unittest.cc @@ -124,8 +124,6 @@ class GLRendererShaderPixelTest : public GLRendererPixelTest { void TestShadersWithPrecision(TexCoordPrecision precision) { EXPECT_PROGRAM_VALID(renderer()->GetTextureIOSurfaceProgram(precision)); - EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVProgram(precision)); - EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVAProgram(precision)); if (renderer()->Capabilities().using_egl_image) EXPECT_PROGRAM_VALID(renderer()->GetVideoStreamTextureProgram(precision)); else @@ -165,6 +163,8 @@ class GLRendererShaderPixelTest : public GLRendererPixelTest { renderer()->GetTileProgramSwizzleOpaque(precision, sampler)); EXPECT_PROGRAM_VALID( renderer()->GetTileProgramSwizzleAA(precision, sampler)); + EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVProgram(precision, sampler)); + EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVAProgram(precision, sampler)); } void TestShadersWithMasks(TexCoordPrecision precision, diff --git a/cc/output/renderer_pixeltest.cc b/cc/output/renderer_pixeltest.cc index 269ec58..6848f1e 100644 --- a/cc/output/renderer_pixeltest.cc +++ b/cc/output/renderer_pixeltest.cc @@ -260,11 +260,21 @@ void CreateTestYUVVideoDrawQuad_FromVideoFrame( video_frame->coded_size())); } + gfx::RectF ya_tex_coord_rect(tex_coord_rect.x() * ya_tex_size.width(), + tex_coord_rect.y() * ya_tex_size.height(), + tex_coord_rect.width() * ya_tex_size.width(), + tex_coord_rect.height() * ya_tex_size.height()); + gfx::RectF uv_tex_coord_rect(tex_coord_rect.x() * uv_tex_size.width(), + tex_coord_rect.y() * uv_tex_size.height(), + tex_coord_rect.width() * uv_tex_size.width(), + tex_coord_rect.height() * uv_tex_size.height()); + YUVVideoDrawQuad* yuv_quad = render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); yuv_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, - tex_coord_rect, ya_tex_size, uv_tex_size, y_resource, - u_resource, v_resource, a_resource, color_space); + ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, + uv_tex_size, y_resource, u_resource, v_resource, a_resource, + color_space); } void CreateTestYUVVideoDrawQuad_Striped( diff --git a/cc/output/shader.cc b/cc/output/shader.cc index d3d5148..15ad7e0 100644 --- a/cc/output/shader.cc +++ b/cc/output/shader.cc @@ -212,14 +212,18 @@ std::string VertexShaderPosTex::GetShaderBody() { } VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() - : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) { + : matrix_location_(-1), + ya_tex_scale_location_(-1), + ya_tex_offset_location_(-1), + uv_tex_scale_location_(-1), + uv_tex_offset_location_(-1) { } void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, unsigned program, int* base_uniform_index) { static const char* uniforms[] = { - "matrix", "texScale", "texOffset", + "matrix", "yaTexScale", "yaTexOffset", "uvTexScale", "uvTexOffset", }; int locations[arraysize(uniforms)]; @@ -230,8 +234,10 @@ void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, locations, base_uniform_index); matrix_location_ = locations[0]; - tex_scale_location_ = locations[1]; - tex_offset_location_ = locations[2]; + ya_tex_scale_location_ = locations[1]; + ya_tex_offset_location_ = locations[2]; + uv_tex_scale_location_ = locations[3]; + uv_tex_offset_location_ = locations[4]; } std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { @@ -244,9 +250,12 @@ std::string VertexShaderPosTexYUVStretchOffset::GetShaderHead() { attribute vec4 a_position; attribute TexCoordPrecision vec2 a_texCoord; uniform mat4 matrix; - varying TexCoordPrecision vec2 v_texCoord; - uniform TexCoordPrecision vec2 texScale; - uniform TexCoordPrecision vec2 texOffset; + varying TexCoordPrecision vec2 v_yaTexCoord; + varying TexCoordPrecision vec2 v_uvTexCoord; + uniform TexCoordPrecision vec2 yaTexScale; + uniform TexCoordPrecision vec2 yaTexOffset; + uniform TexCoordPrecision vec2 uvTexScale; + uniform TexCoordPrecision vec2 uvTexOffset; }); } @@ -254,7 +263,8 @@ std::string VertexShaderPosTexYUVStretchOffset::GetShaderBody() { return SHADER0([]() { void main() { gl_Position = matrix * a_position; - v_texCoord = a_texCoord * texScale + texOffset; + v_yaTexCoord = a_texCoord * yaTexScale + yaTexOffset; + v_uvTexCoord = a_texCoord * uvTexScale + uvTexOffset; } }); } @@ -2046,7 +2056,8 @@ std::string FragmentShaderYUVVideo::GetShaderHead() { return SHADER0([]() { precision mediump float; precision mediump int; - varying TexCoordPrecision vec2 v_texCoord; + varying TexCoordPrecision vec2 v_yaTexCoord; + varying TexCoordPrecision vec2 v_uvTexCoord; uniform SamplerType y_texture; uniform SamplerType u_texture; uniform SamplerType v_texture; @@ -2062,10 +2073,10 @@ std::string FragmentShaderYUVVideo::GetShaderBody() { return SHADER0([]() { void main() { vec2 ya_clamped = - max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_texCoord)); + max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord)); float y_raw = TextureLookup(y_texture, ya_clamped).x; vec2 uv_clamped = - max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_texCoord)); + max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); float u_unsigned = TextureLookup(u_texture, uv_clamped).x; float v_unsigned = TextureLookup(v_texture, uv_clamped).x; vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; @@ -2128,7 +2139,8 @@ std::string FragmentShaderYUVAVideo::GetShaderHead() { return SHADER0([]() { precision mediump float; precision mediump int; - varying TexCoordPrecision vec2 v_texCoord; + varying TexCoordPrecision vec2 v_yaTexCoord; + varying TexCoordPrecision vec2 v_uvTexCoord; uniform SamplerType y_texture; uniform SamplerType u_texture; uniform SamplerType v_texture; @@ -2145,10 +2157,10 @@ std::string FragmentShaderYUVAVideo::GetShaderBody() { return SHADER0([]() { void main() { vec2 ya_clamped = - max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_texCoord)); + max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord)); float y_raw = TextureLookup(y_texture, ya_clamped).x; vec2 uv_clamped = - max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_texCoord)); + max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); float u_unsigned = TextureLookup(u_texture, uv_clamped).x; float v_unsigned = TextureLookup(v_texture, uv_clamped).x; float a_raw = TextureLookup(a_texture, ya_clamped).x; diff --git a/cc/output/shader.h b/cc/output/shader.h index dcc01e2..d692a12 100644 --- a/cc/output/shader.h +++ b/cc/output/shader.h @@ -132,13 +132,17 @@ class VertexShaderPosTexYUVStretchOffset { static std::string GetShaderBody(); int matrix_location() const { return matrix_location_; } - int tex_scale_location() const { return tex_scale_location_; } - int tex_offset_location() const { return tex_offset_location_; } + int ya_tex_scale_location() const { return ya_tex_scale_location_; } + int ya_tex_offset_location() const { return ya_tex_offset_location_; } + int uv_tex_scale_location() const { return uv_tex_scale_location_; } + int uv_tex_offset_location() const { return uv_tex_offset_location_; } private: int matrix_location_; - int tex_scale_location_; - int tex_offset_location_; + int ya_tex_scale_location_; + int ya_tex_offset_location_; + int uv_tex_scale_location_; + int uv_tex_offset_location_; DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexYUVStretchOffset); }; diff --git a/cc/quads/draw_quad_unittest.cc b/cc/quads/draw_quad_unittest.cc index d55bfa5..02d57ba 100644 --- a/cc/quads/draw_quad_unittest.cc +++ b/cc/quads/draw_quad_unittest.cc @@ -313,23 +313,13 @@ void CompareDrawQuad(DrawQuad* quad, } \ SETUP_AND_COPY_QUAD_NEW(Type, quad_new); -#define CREATE_QUAD_9_ALL(Type, a, b, c, d, e, f, g, h, i) \ - { \ - QUAD_DATA quad_all->SetAll(shared_state, \ - quad_rect, \ - quad_opaque_rect, \ - quad_visible_rect, \ - needs_blending, \ - a, \ - b, \ - c, \ - d, \ - e, \ - f, \ - g, \ - h, \ - i); \ - } \ +#define CREATE_QUAD_9_ALL(Type, a, b, c, d, e, f, g, h, i) \ + Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \ + { \ + QUAD_DATA quad_all->SetAll(shared_state, quad_rect, quad_opaque_rect, \ + quad_visible_rect, needs_blending, a, b, c, d, \ + e, f, g, h, i); \ + } \ SETUP_AND_COPY_QUAD_ALL(Type, quad_all); #define CREATE_QUAD_10_NEW(Type, a, b, c, d, e, f, g, h, i, j) \ @@ -340,6 +330,14 @@ void CompareDrawQuad(DrawQuad* quad, } \ SETUP_AND_COPY_QUAD_NEW(Type, quad_new); +#define CREATE_QUAD_11_NEW(Type, a, b, c, d, e, f, g, h, i, j, k) \ + Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \ + { \ + QUAD_DATA quad_new->SetNew(shared_state, quad_rect, a, b, c, d, e, f, g, \ + h, i, j, k); \ + } \ + SETUP_AND_COPY_QUAD_NEW(Type, quad_new); + #define CREATE_QUAD_ALL_RP(Type, a, b, c, d, e, f, g, copy_a) \ Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \ { \ @@ -640,7 +638,8 @@ TEST(DrawQuadTest, CopyTileDrawQuad) { TEST(DrawQuadTest, CopyYUVVideoDrawQuad) { gfx::Rect opaque_rect(33, 47, 10, 12); gfx::Rect visible_rect(40, 50, 30, 20); - gfx::RectF tex_coord_rect(0.0f, 0.0f, 0.75f, 0.5f); + gfx::RectF ya_tex_coord_rect(40, 50, 30, 20); + gfx::RectF uv_tex_coord_rect(20, 25, 15, 10); gfx::Size ya_tex_size(32, 68); gfx::Size uv_tex_size(41, 51); ResourceProvider::ResourceId y_plane_resource_id = 45; @@ -650,14 +649,15 @@ TEST(DrawQuadTest, CopyYUVVideoDrawQuad) { YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::JPEG; CREATE_SHARED_STATE(); - CREATE_QUAD_10_NEW(YUVVideoDrawQuad, opaque_rect, visible_rect, - tex_coord_rect, ya_tex_size, uv_tex_size, - y_plane_resource_id, u_plane_resource_id, + CREATE_QUAD_11_NEW(YUVVideoDrawQuad, opaque_rect, visible_rect, + ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, + uv_tex_size, y_plane_resource_id, u_plane_resource_id, v_plane_resource_id, a_plane_resource_id, color_space); EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material); EXPECT_EQ(opaque_rect, copy_quad->opaque_rect); EXPECT_EQ(visible_rect, copy_quad->visible_rect); - EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect); + EXPECT_EQ(ya_tex_coord_rect, copy_quad->ya_tex_coord_rect); + EXPECT_EQ(uv_tex_coord_rect, copy_quad->uv_tex_coord_rect); EXPECT_EQ(ya_tex_size, copy_quad->ya_tex_size); EXPECT_EQ(uv_tex_size, copy_quad->uv_tex_size); EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id); @@ -666,11 +666,13 @@ TEST(DrawQuadTest, CopyYUVVideoDrawQuad) { EXPECT_EQ(a_plane_resource_id, copy_quad->a_plane_resource_id); EXPECT_EQ(color_space, copy_quad->color_space); - CREATE_QUAD_8_ALL(YUVVideoDrawQuad, tex_coord_rect, ya_tex_size, uv_tex_size, - y_plane_resource_id, u_plane_resource_id, - v_plane_resource_id, a_plane_resource_id, color_space); + CREATE_QUAD_9_ALL(YUVVideoDrawQuad, ya_tex_coord_rect, uv_tex_coord_rect, + ya_tex_size, uv_tex_size, y_plane_resource_id, + u_plane_resource_id, v_plane_resource_id, + a_plane_resource_id, color_space); EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material); - EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect); + EXPECT_EQ(ya_tex_coord_rect, copy_quad->ya_tex_coord_rect); + EXPECT_EQ(uv_tex_coord_rect, copy_quad->uv_tex_coord_rect); EXPECT_EQ(ya_tex_size, copy_quad->ya_tex_size); EXPECT_EQ(uv_tex_size, copy_quad->uv_tex_size); EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id); @@ -901,7 +903,8 @@ TEST_F(DrawQuadIteratorTest, TileDrawQuad) { TEST_F(DrawQuadIteratorTest, YUVVideoDrawQuad) { gfx::Rect opaque_rect(33, 47, 10, 12); gfx::Rect visible_rect(40, 50, 30, 20); - gfx::RectF tex_coord_rect(0.0f, 0.0f, 0.75f, 0.5f); + gfx::RectF ya_tex_coord_rect(0.0f, 0.0f, 0.75f, 0.5f); + gfx::RectF uv_tex_coord_rect(0.0f, 0.0f, 0.375f, 0.25f); gfx::Size ya_tex_size(32, 68); gfx::Size uv_tex_size(41, 51); ResourceProvider::ResourceId y_plane_resource_id = 45; @@ -911,9 +914,9 @@ TEST_F(DrawQuadIteratorTest, YUVVideoDrawQuad) { YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::JPEG; CREATE_SHARED_STATE(); - CREATE_QUAD_10_NEW(YUVVideoDrawQuad, opaque_rect, visible_rect, - tex_coord_rect, ya_tex_size, uv_tex_size, - y_plane_resource_id, u_plane_resource_id, + CREATE_QUAD_11_NEW(YUVVideoDrawQuad, opaque_rect, visible_rect, + ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, + uv_tex_size, y_plane_resource_id, u_plane_resource_id, v_plane_resource_id, a_plane_resource_id, color_space); EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material); EXPECT_EQ(y_plane_resource_id, quad_new->y_plane_resource_id); diff --git a/cc/quads/tile_draw_quad.h b/cc/quads/tile_draw_quad.h index d7ef20a..b858e14 100644 --- a/cc/quads/tile_draw_quad.h +++ b/cc/quads/tile_draw_quad.h @@ -19,6 +19,9 @@ class CC_EXPORT TileDrawQuad : public ContentDrawQuadBase { const gfx::Rect& opaque_rect, const gfx::Rect& visible_rect, unsigned resource_id, + // |tex_coord_rect| contains non-normalized coordinates. + // TODO(reveman): Make the use of normalized vs non-normalized + // coordinates consistent across all quad types: crbug.com/487370 const gfx::RectF& tex_coord_rect, const gfx::Size& texture_size, bool swizzle_contents, @@ -30,6 +33,9 @@ class CC_EXPORT TileDrawQuad : public ContentDrawQuadBase { const gfx::Rect& visible_rect, bool needs_blending, unsigned resource_id, + // |tex_coord_rect| contains non-normalized coordinates. + // TODO(reveman): Make the use of normalized vs non-normalized + // coordinates consistent across all quad types: crbug.com/487370 const gfx::RectF& tex_coord_rect, const gfx::Size& texture_size, bool swizzle_contents, diff --git a/cc/quads/yuv_video_draw_quad.cc b/cc/quads/yuv_video_draw_quad.cc index 483cc24..5706f28 100644 --- a/cc/quads/yuv_video_draw_quad.cc +++ b/cc/quads/yuv_video_draw_quad.cc @@ -22,7 +22,8 @@ void YUVVideoDrawQuad::SetNew(const SharedQuadState* shared_quad_state, const gfx::Rect& rect, const gfx::Rect& opaque_rect, const gfx::Rect& visible_rect, - const gfx::RectF& tex_coord_rect, + const gfx::RectF& ya_tex_coord_rect, + const gfx::RectF& uv_tex_coord_rect, const gfx::Size& ya_tex_size, const gfx::Size& uv_tex_size, unsigned y_plane_resource_id, @@ -33,7 +34,8 @@ void YUVVideoDrawQuad::SetNew(const SharedQuadState* shared_quad_state, bool needs_blending = false; DrawQuad::SetAll(shared_quad_state, DrawQuad::YUV_VIDEO_CONTENT, rect, opaque_rect, visible_rect, needs_blending); - this->tex_coord_rect = tex_coord_rect; + this->ya_tex_coord_rect = ya_tex_coord_rect; + this->uv_tex_coord_rect = uv_tex_coord_rect; this->ya_tex_size = ya_tex_size; this->uv_tex_size = uv_tex_size; this->y_plane_resource_id = y_plane_resource_id; @@ -48,7 +50,8 @@ void YUVVideoDrawQuad::SetAll(const SharedQuadState* shared_quad_state, const gfx::Rect& opaque_rect, const gfx::Rect& visible_rect, bool needs_blending, - const gfx::RectF& tex_coord_rect, + const gfx::RectF& ya_tex_coord_rect, + const gfx::RectF& uv_tex_coord_rect, const gfx::Size& ya_tex_size, const gfx::Size& uv_tex_size, unsigned y_plane_resource_id, @@ -58,7 +61,8 @@ void YUVVideoDrawQuad::SetAll(const SharedQuadState* shared_quad_state, ColorSpace color_space) { DrawQuad::SetAll(shared_quad_state, DrawQuad::YUV_VIDEO_CONTENT, rect, opaque_rect, visible_rect, needs_blending); - this->tex_coord_rect = tex_coord_rect; + this->ya_tex_coord_rect = ya_tex_coord_rect; + this->uv_tex_coord_rect = uv_tex_coord_rect; this->ya_tex_size = ya_tex_size; this->uv_tex_size = uv_tex_size; this->y_plane_resource_id = y_plane_resource_id; @@ -85,7 +89,8 @@ const YUVVideoDrawQuad* YUVVideoDrawQuad::MaterialCast( void YUVVideoDrawQuad::ExtendValue( base::trace_event::TracedValue* value) const { - MathUtil::AddToTracedValue("tex_coord_rect", tex_coord_rect, value); + MathUtil::AddToTracedValue("ya_tex_coord_rect", ya_tex_coord_rect, value); + MathUtil::AddToTracedValue("uv_tex_coord_rect", uv_tex_coord_rect, value); MathUtil::AddToTracedValue("ya_tex_size", ya_tex_size, value); MathUtil::AddToTracedValue("uv_tex_size", uv_tex_size, value); value->SetInteger("y_plane_resource_id", y_plane_resource_id); diff --git a/cc/quads/yuv_video_draw_quad.h b/cc/quads/yuv_video_draw_quad.h index 03276eb..deeca2c 100644 --- a/cc/quads/yuv_video_draw_quad.h +++ b/cc/quads/yuv_video_draw_quad.h @@ -29,7 +29,11 @@ class CC_EXPORT YUVVideoDrawQuad : public DrawQuad { const gfx::Rect& rect, const gfx::Rect& opaque_rect, const gfx::Rect& visible_rect, - const gfx::RectF& tex_coord_rect, + // |*_tex_coord_rect| contains non-normalized coordinates. + // TODO(reveman): Make the use of normalized vs non-normalized + // coordinates consistent across all quad types: crbug.com/487370 + const gfx::RectF& ya_tex_coord_rect, + const gfx::RectF& uv_tex_coord_rect, const gfx::Size& ya_tex_size, const gfx::Size& uv_tex_size, unsigned y_plane_resource_id, @@ -43,7 +47,11 @@ class CC_EXPORT YUVVideoDrawQuad : public DrawQuad { const gfx::Rect& opaque_rect, const gfx::Rect& visible_rect, bool needs_blending, - const gfx::RectF& tex_coord_rect, + // |*_tex_coord_rect| contains non-normalized coordinates. + // TODO(reveman): Make the use of normalized vs non-normalized + // coordinates consistent across all quad types: crbug.com/487370 + const gfx::RectF& ya_tex_coord_rect, + const gfx::RectF& uv_tex_coord_rect, const gfx::Size& ya_tex_size, const gfx::Size& uv_tex_size, unsigned y_plane_resource_id, @@ -52,8 +60,8 @@ class CC_EXPORT YUVVideoDrawQuad : public DrawQuad { unsigned a_plane_resource_id, ColorSpace color_space); - gfx::RectF tex_coord_rect; - // Empty texture size implies no clamping of texture coordinates. + gfx::RectF ya_tex_coord_rect; + gfx::RectF uv_tex_coord_rect; gfx::Size ya_tex_size; gfx::Size uv_tex_size; unsigned y_plane_resource_id; diff --git a/cc/test/render_pass_test_common.cc b/cc/test/render_pass_test_common.cc index 8b479fc..6895297 100644 --- a/cc/test/render_pass_test_common.cc +++ b/cc/test/render_pass_test_common.cc @@ -245,7 +245,8 @@ void TestRenderPass::AppendOneOfEveryQuadType( YUVVideoDrawQuad* yuv_quad = this->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); yuv_quad->SetNew(shared_state2, rect, opaque_rect, visible_rect, - gfx::RectF(0, 0, 100, 100), gfx::Size(100, 100), + gfx::RectF(.0f, .0f, 100.0f, 100.0f), + gfx::RectF(.0f, .0f, 50.0f, 50.0f), gfx::Size(100, 100), gfx::Size(50, 50), plane_resources[0], plane_resources[1], plane_resources[2], plane_resources[3], color_space); } |