OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 2163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2174 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
2175 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2175 gl_, &highp_threshold_cache_, highp_threshold_min_, |
2176 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2176 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
2177 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() | 2177 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() |
2178 ? YUV_HAS_ALPHA_TEXTURE | 2178 ? YUV_HAS_ALPHA_TEXTURE |
2179 : YUV_NO_ALPHA_TEXTURE; | 2179 : YUV_NO_ALPHA_TEXTURE; |
2180 UVTextureMode uv_texture_mode = | 2180 UVTextureMode uv_texture_mode = |
2181 quad->v_plane_resource_id() == quad->u_plane_resource_id() | 2181 quad->v_plane_resource_id() == quad->u_plane_resource_id() |
2182 ? UV_TEXTURE_MODE_UV | 2182 ? UV_TEXTURE_MODE_UV |
2183 : UV_TEXTURE_MODE_U_V; | 2183 : UV_TEXTURE_MODE_U_V; |
2184 ColorConversionMode color_conversion_mode = | 2184 bool use_lut = base::FeatureList::IsEnabled(media::kVideoColorManagement); |
2185 base::FeatureList::IsEnabled(media::kVideoColorManagement) | |
2186 ? COLOR_CONVERSION_MODE_LUT_FROM_YUV | |
2187 : COLOR_CONVERSION_MODE_NONE; | |
2188 ResourceProvider::ScopedSamplerGL y_plane_lock( | 2185 ResourceProvider::ScopedSamplerGL y_plane_lock( |
2189 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); | 2186 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); |
2190 ResourceProvider::ScopedSamplerGL u_plane_lock( | 2187 ResourceProvider::ScopedSamplerGL u_plane_lock( |
2191 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); | 2188 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); |
2192 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); | 2189 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); |
2193 // TODO(jbauman): Use base::Optional when available. | 2190 // TODO(jbauman): Use base::Optional when available. |
2194 std::unique_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock; | 2191 std::unique_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock; |
2195 | 2192 |
2196 if (uv_texture_mode == UV_TEXTURE_MODE_U_V) { | 2193 if (uv_texture_mode == UV_TEXTURE_MODE_U_V) { |
2197 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( | 2194 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( |
2198 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, | 2195 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, |
2199 GL_LINEAR)); | 2196 GL_LINEAR)); |
2200 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target()); | 2197 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target()); |
2201 } | 2198 } |
2202 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; | 2199 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; |
2203 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) { | 2200 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) { |
2204 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( | 2201 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( |
2205 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, | 2202 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, |
2206 GL_LINEAR)); | 2203 GL_LINEAR)); |
2207 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); | 2204 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); |
2208 } | 2205 } |
2209 | 2206 |
2210 // All planes must have the same sampler type. | 2207 // All planes must have the same sampler type. |
2211 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); | 2208 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); |
2212 | 2209 |
2213 const Program* program = GetProgram( | 2210 const Program* program = GetProgram( |
2214 ProgramKey::YUVVideo(tex_coord_precision, sampler, alpha_texture_mode, | 2211 ProgramKey::YUVVideo(tex_coord_precision, sampler, alpha_texture_mode, |
2215 uv_texture_mode, color_conversion_mode)); | 2212 uv_texture_mode, use_lut)); |
2216 DCHECK(program && (program->initialized() || IsContextLost())); | 2213 DCHECK(program && (program->initialized() || IsContextLost())); |
2217 SetUseProgram(program->program()); | 2214 SetUseProgram(program->program()); |
2218 | 2215 |
2219 gfx::SizeF ya_tex_scale(1.0f, 1.0f); | 2216 gfx::SizeF ya_tex_scale(1.0f, 1.0f); |
2220 gfx::SizeF uv_tex_scale(1.0f, 1.0f); | 2217 gfx::SizeF uv_tex_scale(1.0f, 1.0f); |
2221 if (sampler != SAMPLER_TYPE_2D_RECT) { | 2218 if (sampler != SAMPLER_TYPE_2D_RECT) { |
2222 DCHECK(!quad->ya_tex_size.IsEmpty()); | 2219 DCHECK(!quad->ya_tex_size.IsEmpty()); |
2223 DCHECK(!quad->uv_tex_size.IsEmpty()); | 2220 DCHECK(!quad->uv_tex_size.IsEmpty()); |
2224 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), | 2221 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), |
2225 1.0f / quad->ya_tex_size.height()); | 2222 1.0f / quad->ya_tex_size.height()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2272 gl_->Uniform1i(program->y_texture_location(), 1); | 2269 gl_->Uniform1i(program->y_texture_location(), 1); |
2273 if (uv_texture_mode == UV_TEXTURE_MODE_UV) { | 2270 if (uv_texture_mode == UV_TEXTURE_MODE_UV) { |
2274 gl_->Uniform1i(program->uv_texture_location(), 2); | 2271 gl_->Uniform1i(program->uv_texture_location(), 2); |
2275 } else { | 2272 } else { |
2276 gl_->Uniform1i(program->u_texture_location(), 2); | 2273 gl_->Uniform1i(program->u_texture_location(), 2); |
2277 gl_->Uniform1i(program->v_texture_location(), 3); | 2274 gl_->Uniform1i(program->v_texture_location(), 3); |
2278 } | 2275 } |
2279 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) | 2276 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) |
2280 gl_->Uniform1i(program->a_texture_location(), 4); | 2277 gl_->Uniform1i(program->a_texture_location(), 4); |
2281 | 2278 |
2282 if (color_conversion_mode == COLOR_CONVERSION_MODE_LUT_FROM_YUV) { | 2279 if (use_lut) { |
2283 ColorLUTCache::LUT lut = color_lut_cache_.GetLUT(quad->video_color_space, | 2280 ColorLUTCache::LUT lut = color_lut_cache_.GetLUT(quad->video_color_space, |
2284 frame->device_color_space); | 2281 frame->device_color_space); |
2285 gl_->ActiveTexture(GL_TEXTURE5); | 2282 gl_->ActiveTexture(GL_TEXTURE5); |
2286 gl_->BindTexture(GL_TEXTURE_2D, lut.texture); | 2283 gl_->BindTexture(GL_TEXTURE_2D, lut.texture); |
2287 gl_->Uniform1i(program->lut_texture_location(), 5); | 2284 gl_->Uniform1i(program->lut_texture_location(), 5); |
2288 gl_->Uniform1f(program->lut_size_location(), lut.size); | 2285 gl_->Uniform1f(program->lut_size_location(), lut.size); |
2289 gl_->ActiveTexture(GL_TEXTURE0); | 2286 gl_->ActiveTexture(GL_TEXTURE0); |
2290 gl_->Uniform1f(program->resource_multiplier_location(), | 2287 gl_->Uniform1f(program->resource_multiplier_location(), |
2291 quad->resource_multiplier); | 2288 quad->resource_multiplier); |
2292 gl_->Uniform1f(program->resource_offset_location(), quad->resource_offset); | 2289 gl_->Uniform1f(program->resource_offset_location(), quad->resource_offset); |
2293 } else { | 2290 } else { |
2294 float yuv_to_rgb_multiplied[9] = {0}; | 2291 float yuv_to_rgb_multiplied[9] = {0}; |
2295 float yuv_adjust_with_offset[3] = {0}; | 2292 float yuv_adjust_with_offset[3] = {0}; |
2296 ComputeYUVToRGBMatrices(quad->color_space, quad->bits_per_channel, | 2293 ComputeYUVToRGBMatrices(quad->color_space, quad->bits_per_channel, |
2297 quad->resource_multiplier, quad->resource_offset, | 2294 quad->resource_multiplier, quad->resource_offset, |
2298 yuv_to_rgb_multiplied, yuv_adjust_with_offset); | 2295 yuv_to_rgb_multiplied, yuv_adjust_with_offset); |
2299 gl_->UniformMatrix3fv(program->yuv_matrix_location(), 1, 0, | 2296 DCHECK_NE(program->color_matrix_location(), -1); |
2300 yuv_to_rgb_multiplied); | 2297 DCHECK_NE(program->color_offset_location(), -1); |
2301 gl_->Uniform3fv(program->yuv_adj_location(), 1, yuv_adjust_with_offset); | 2298 |
| 2299 float matrix[16]; |
| 2300 SkMatrix44 m; |
| 2301 for (int i = 0; i < 4; ++i) { |
| 2302 for (int j = 0; j < 4; ++j) { |
| 2303 float x; |
| 2304 if (i == 3 && j == 3) { |
| 2305 x = 1.0f; |
| 2306 } else if (i == 3 || j == 3) { |
| 2307 x = 0.0f; |
| 2308 } else { |
| 2309 x = yuv_to_rgb_multiplied[i * 3 + j]; |
| 2310 } |
| 2311 m.set(j, i, x); |
| 2312 matrix[i * 4 + j] = x; |
| 2313 } |
| 2314 } |
| 2315 SkVector4 v(yuv_adjust_with_offset[0], yuv_adjust_with_offset[1], |
| 2316 yuv_adjust_with_offset[2], 0.0f); |
| 2317 v = m * v; |
| 2318 gl_->UniformMatrix4fv(program->color_matrix_location(), 1, false, matrix); |
| 2319 gl_->Uniform4fv(program->color_offset_location(), 1, v.fData); |
2302 } | 2320 } |
2303 | 2321 |
2304 // The transform and vertex data are used to figure out the extents that the | 2322 // The transform and vertex data are used to figure out the extents that the |
2305 // un-antialiased quad should have and which vertex this is and the float | 2323 // un-antialiased quad should have and which vertex this is and the float |
2306 // quad passed in via uniform is the actual geometry that gets used to draw | 2324 // quad passed in via uniform is the actual geometry that gets used to draw |
2307 // it. This is why this centered rect is used and not the original quad_rect. | 2325 // it. This is why this centered rect is used and not the original quad_rect. |
2308 auto tile_rect = gfx::RectF(quad->rect); | 2326 auto tile_rect = gfx::RectF(quad->rect); |
2309 | 2327 |
2310 SetShaderOpacity(quad->shared_quad_state->opacity, program->alpha_location()); | 2328 SetShaderOpacity(quad->shared_quad_state->opacity, program->alpha_location()); |
2311 if (!clip_region) { | 2329 if (!clip_region) { |
(...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3597 return; | 3615 return; |
3598 | 3616 |
3599 // Report GPU overdraw as a percentage of |max_result|. | 3617 // Report GPU overdraw as a percentage of |max_result|. |
3600 TRACE_COUNTER1( | 3618 TRACE_COUNTER1( |
3601 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | 3619 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", |
3602 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / | 3620 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / |
3603 max_result); | 3621 max_result); |
3604 } | 3622 } |
3605 | 3623 |
3606 } // namespace cc | 3624 } // namespace cc |
OLD | NEW |