| 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 2068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2079 | 2079 |
| 2080 static float gl_matrix[16]; | 2080 static float gl_matrix[16]; |
| 2081 ToGLMatrix(&gl_matrix[0], | 2081 ToGLMatrix(&gl_matrix[0], |
| 2082 frame->projection_matrix * | 2082 frame->projection_matrix * |
| 2083 quad->shared_quad_state->quad_to_target_transform); | 2083 quad->shared_quad_state->quad_to_target_transform); |
| 2084 gl_->UniformMatrix4fv(program->matrix_location(), 1, false, &gl_matrix[0]); | 2084 gl_->UniformMatrix4fv(program->matrix_location(), 1, false, &gl_matrix[0]); |
| 2085 | 2085 |
| 2086 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 2086 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
| 2087 } | 2087 } |
| 2088 | 2088 |
| 2089 // TODO(ccameron): This has been replicated in ui/gfx/color_transform.cc. Delete |
| 2090 // one of the instances. |
| 2091 void ComputeYUVToRGBMatrices(YUVVideoDrawQuad::ColorSpace color_space, |
| 2092 uint32_t bits_per_channel, |
| 2093 float resource_multiplier, |
| 2094 float resource_offset, |
| 2095 float* yuv_to_rgb_multiplied, |
| 2096 float* yuv_adjust_with_offset) { |
| 2097 // These values are magic numbers that are used in the transformation from YUV |
| 2098 // to RGB color values. They are taken from the following webpage: |
| 2099 // http://www.fourcc.org/fccyvrgb.php |
| 2100 float yuv_to_rgb_rec601[9] = { |
| 2101 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f, |
| 2102 }; |
| 2103 float yuv_to_rgb_jpeg[9] = { |
| 2104 1.f, 1.f, 1.f, 0.0f, -.34414f, 1.772f, 1.402f, -.71414f, 0.0f, |
| 2105 }; |
| 2106 float yuv_to_rgb_rec709[9] = { |
| 2107 1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.112f, 1.793f, -0.533f, 0.0f, |
| 2108 }; |
| 2109 |
| 2110 // They are used in the YUV to RGBA conversion formula: |
| 2111 // Y - 16 : Gives 16 values of head and footroom for overshooting |
| 2112 // U - 128 : Turns unsigned U into signed U [-128,127] |
| 2113 // V - 128 : Turns unsigned V into signed V [-128,127] |
| 2114 float yuv_adjust_constrained[3] = { |
| 2115 -16.f, -128.f, -128.f, |
| 2116 }; |
| 2117 |
| 2118 // Same as above, but without the head and footroom. |
| 2119 float yuv_adjust_full[3] = { |
| 2120 0.0f, -128.f, -128.f, |
| 2121 }; |
| 2122 |
| 2123 float* yuv_to_rgb = NULL; |
| 2124 float* yuv_adjust = NULL; |
| 2125 |
| 2126 switch (color_space) { |
| 2127 case YUVVideoDrawQuad::REC_601: |
| 2128 yuv_to_rgb = yuv_to_rgb_rec601; |
| 2129 yuv_adjust = yuv_adjust_constrained; |
| 2130 break; |
| 2131 case YUVVideoDrawQuad::REC_709: |
| 2132 yuv_to_rgb = yuv_to_rgb_rec709; |
| 2133 yuv_adjust = yuv_adjust_constrained; |
| 2134 break; |
| 2135 case YUVVideoDrawQuad::JPEG: |
| 2136 yuv_to_rgb = yuv_to_rgb_jpeg; |
| 2137 yuv_adjust = yuv_adjust_full; |
| 2138 break; |
| 2139 } |
| 2140 |
| 2141 // Formula according to BT.601-7 section 2.5.3. |
| 2142 DCHECK_LE(YUVVideoDrawQuad::kMinBitsPerChannel, bits_per_channel); |
| 2143 DCHECK_LE(bits_per_channel, YUVVideoDrawQuad::kMaxBitsPerChannel); |
| 2144 float adjustment_multiplier = |
| 2145 (1 << (bits_per_channel - 8)) * 1.0f / ((1 << bits_per_channel) - 1); |
| 2146 |
| 2147 for (int i = 0; i < 9; ++i) |
| 2148 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * resource_multiplier; |
| 2149 |
| 2150 for (int i = 0; i < 3; ++i) { |
| 2151 yuv_adjust_with_offset[i] = |
| 2152 yuv_adjust[i] * adjustment_multiplier / resource_multiplier - |
| 2153 resource_offset; |
| 2154 } |
| 2155 } |
| 2156 |
| 2089 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, | 2157 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, |
| 2090 const YUVVideoDrawQuad* quad, | 2158 const YUVVideoDrawQuad* quad, |
| 2091 const gfx::QuadF* clip_region) { | 2159 const gfx::QuadF* clip_region) { |
| 2092 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2160 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2093 | 2161 |
| 2094 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2162 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2095 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2163 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2096 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2164 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2097 | 2165 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() |
| 2098 bool use_alpha_plane = quad->a_plane_resource_id() != 0; | 2166 ? YUV_HAS_ALPHA_TEXTURE |
| 2099 bool use_nv12 = quad->v_plane_resource_id() == quad->u_plane_resource_id(); | 2167 : YUV_NO_ALPHA_TEXTURE; |
| 2100 bool use_color_lut = | 2168 UVTextureMode uv_texture_mode = |
| 2101 base::FeatureList::IsEnabled(media::kVideoColorManagement); | 2169 quad->v_plane_resource_id() == quad->u_plane_resource_id() |
| 2102 DCHECK(!(use_nv12 && use_alpha_plane)); | 2170 ? UV_TEXTURE_MODE_UV |
| 2103 | 2171 : UV_TEXTURE_MODE_U_V; |
| 2172 ColorConversionMode color_conversion_mode = |
| 2173 base::FeatureList::IsEnabled(media::kVideoColorManagement) |
| 2174 ? COLOR_CONVERSION_MODE_LUT_FROM_YUV |
| 2175 : COLOR_CONVERSION_MODE_NONE; |
| 2104 ResourceProvider::ScopedSamplerGL y_plane_lock( | 2176 ResourceProvider::ScopedSamplerGL y_plane_lock( |
| 2105 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); | 2177 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); |
| 2106 ResourceProvider::ScopedSamplerGL u_plane_lock( | 2178 ResourceProvider::ScopedSamplerGL u_plane_lock( |
| 2107 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); | 2179 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); |
| 2108 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); | 2180 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); |
| 2109 // TODO(jbauman): Use base::Optional when available. | 2181 // TODO(jbauman): Use base::Optional when available. |
| 2110 std::unique_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock; | 2182 std::unique_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock; |
| 2111 if (!use_nv12) { | 2183 |
| 2184 if (uv_texture_mode == UV_TEXTURE_MODE_U_V) { |
| 2112 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( | 2185 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( |
| 2113 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, | 2186 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, |
| 2114 GL_LINEAR)); | 2187 GL_LINEAR)); |
| 2115 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target()); | 2188 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target()); |
| 2116 } | 2189 } |
| 2117 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; | 2190 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; |
| 2118 if (use_alpha_plane) { | 2191 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) { |
| 2119 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( | 2192 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( |
| 2120 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, | 2193 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, |
| 2121 GL_LINEAR)); | 2194 GL_LINEAR)); |
| 2122 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); | 2195 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); |
| 2123 } | 2196 } |
| 2124 | 2197 |
| 2125 // All planes must have the same sampler type. | 2198 // All planes must have the same sampler type. |
| 2126 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); | 2199 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); |
| 2127 | 2200 |
| 2128 int matrix_location = -1; | 2201 const Program* program = GetProgram( |
| 2129 int ya_tex_scale_location = -1; | 2202 ProgramKey::YUVVideo(tex_coord_precision, sampler, alpha_texture_mode, |
| 2130 int ya_tex_offset_location = -1; | 2203 uv_texture_mode, color_conversion_mode)); |
| 2131 int uv_tex_scale_location = -1; | 2204 DCHECK(program && (program->initialized() || IsContextLost())); |
| 2132 int uv_tex_offset_location = -1; | |
| 2133 int ya_clamp_rect_location = -1; | |
| 2134 int uv_clamp_rect_location = -1; | |
| 2135 int y_texture_location = -1; | |
| 2136 int u_texture_location = -1; | |
| 2137 int v_texture_location = -1; | |
| 2138 int uv_texture_location = -1; | |
| 2139 int a_texture_location = -1; | |
| 2140 int lut_texture_location = -1; | |
| 2141 int yuv_matrix_location = -1; | |
| 2142 int yuv_adj_location = -1; | |
| 2143 int alpha_location = -1; | |
| 2144 int resource_multiplier_location = -1; | |
| 2145 int resource_offset_location = -1; | |
| 2146 const Program* program = GetProgram(ProgramKey::YUVVideo( | |
| 2147 tex_coord_precision, sampler, | |
| 2148 use_alpha_plane ? YUV_HAS_ALPHA_TEXTURE : YUV_NO_ALPHA_TEXTURE, | |
| 2149 use_nv12 ? UV_TEXTURE_MODE_UV : UV_TEXTURE_MODE_U_V, | |
| 2150 use_color_lut ? COLOR_CONVERSION_MODE_2D_LUT_AS_3D_FROM_YUV | |
| 2151 : COLOR_CONVERSION_MODE_NONE)); | |
| 2152 DCHECK(program); | |
| 2153 DCHECK(program->initialized() || IsContextLost()); | |
| 2154 SetUseProgram(program->program()); | 2205 SetUseProgram(program->program()); |
| 2155 matrix_location = program->matrix_location(); | |
| 2156 ya_tex_scale_location = program->ya_tex_scale_location(); | |
| 2157 ya_tex_offset_location = program->ya_tex_offset_location(); | |
| 2158 uv_tex_scale_location = program->uv_tex_scale_location(); | |
| 2159 uv_tex_offset_location = program->uv_tex_offset_location(); | |
| 2160 y_texture_location = program->y_texture_location(); | |
| 2161 u_texture_location = program->u_texture_location(); | |
| 2162 v_texture_location = program->v_texture_location(); | |
| 2163 uv_texture_location = program->uv_texture_location(); | |
| 2164 a_texture_location = program->a_texture_location(); | |
| 2165 lut_texture_location = program->lut_texture_location(); | |
| 2166 yuv_matrix_location = program->yuv_matrix_location(); | |
| 2167 yuv_adj_location = program->yuv_adj_location(); | |
| 2168 ya_clamp_rect_location = program->ya_clamp_rect_location(); | |
| 2169 uv_clamp_rect_location = program->uv_clamp_rect_location(); | |
| 2170 alpha_location = program->alpha_location(); | |
| 2171 resource_multiplier_location = program->resource_multiplier_location(); | |
| 2172 resource_offset_location = program->resource_offset_location(); | |
| 2173 | 2206 |
| 2174 gfx::SizeF ya_tex_scale(1.0f, 1.0f); | 2207 gfx::SizeF ya_tex_scale(1.0f, 1.0f); |
| 2175 gfx::SizeF uv_tex_scale(1.0f, 1.0f); | 2208 gfx::SizeF uv_tex_scale(1.0f, 1.0f); |
| 2176 if (sampler != SAMPLER_TYPE_2D_RECT) { | 2209 if (sampler != SAMPLER_TYPE_2D_RECT) { |
| 2177 DCHECK(!quad->ya_tex_size.IsEmpty()); | 2210 DCHECK(!quad->ya_tex_size.IsEmpty()); |
| 2178 DCHECK(!quad->uv_tex_size.IsEmpty()); | 2211 DCHECK(!quad->uv_tex_size.IsEmpty()); |
| 2179 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), | 2212 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), |
| 2180 1.0f / quad->ya_tex_size.height()); | 2213 1.0f / quad->ya_tex_size.height()); |
| 2181 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(), | 2214 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(), |
| 2182 1.0f / quad->uv_tex_size.height()); | 2215 1.0f / quad->uv_tex_size.height()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2193 | 2226 |
| 2194 float uv_vertex_tex_translate_x = | 2227 float uv_vertex_tex_translate_x = |
| 2195 quad->uv_tex_coord_rect.x() * uv_tex_scale.width(); | 2228 quad->uv_tex_coord_rect.x() * uv_tex_scale.width(); |
| 2196 float uv_vertex_tex_translate_y = | 2229 float uv_vertex_tex_translate_y = |
| 2197 quad->uv_tex_coord_rect.y() * uv_tex_scale.height(); | 2230 quad->uv_tex_coord_rect.y() * uv_tex_scale.height(); |
| 2198 float uv_vertex_tex_scale_x = | 2231 float uv_vertex_tex_scale_x = |
| 2199 quad->uv_tex_coord_rect.width() * uv_tex_scale.width(); | 2232 quad->uv_tex_coord_rect.width() * uv_tex_scale.width(); |
| 2200 float uv_vertex_tex_scale_y = | 2233 float uv_vertex_tex_scale_y = |
| 2201 quad->uv_tex_coord_rect.height() * uv_tex_scale.height(); | 2234 quad->uv_tex_coord_rect.height() * uv_tex_scale.height(); |
| 2202 | 2235 |
| 2203 gl_->Uniform2f(ya_tex_scale_location, ya_vertex_tex_scale_x, | 2236 gl_->Uniform2f(program->ya_tex_scale_location(), ya_vertex_tex_scale_x, |
| 2204 ya_vertex_tex_scale_y); | 2237 ya_vertex_tex_scale_y); |
| 2205 gl_->Uniform2f(ya_tex_offset_location, ya_vertex_tex_translate_x, | 2238 gl_->Uniform2f(program->ya_tex_offset_location(), ya_vertex_tex_translate_x, |
| 2206 ya_vertex_tex_translate_y); | 2239 ya_vertex_tex_translate_y); |
| 2207 gl_->Uniform2f(uv_tex_scale_location, uv_vertex_tex_scale_x, | 2240 gl_->Uniform2f(program->uv_tex_scale_location(), uv_vertex_tex_scale_x, |
| 2208 uv_vertex_tex_scale_y); | 2241 uv_vertex_tex_scale_y); |
| 2209 gl_->Uniform2f(uv_tex_offset_location, uv_vertex_tex_translate_x, | 2242 gl_->Uniform2f(program->uv_tex_offset_location(), uv_vertex_tex_translate_x, |
| 2210 uv_vertex_tex_translate_y); | 2243 uv_vertex_tex_translate_y); |
| 2211 | 2244 |
| 2212 gfx::RectF ya_clamp_rect(ya_vertex_tex_translate_x, ya_vertex_tex_translate_y, | 2245 gfx::RectF ya_clamp_rect(ya_vertex_tex_translate_x, ya_vertex_tex_translate_y, |
| 2213 ya_vertex_tex_scale_x, ya_vertex_tex_scale_y); | 2246 ya_vertex_tex_scale_x, ya_vertex_tex_scale_y); |
| 2214 ya_clamp_rect.Inset(0.5f * ya_tex_scale.width(), | 2247 ya_clamp_rect.Inset(0.5f * ya_tex_scale.width(), |
| 2215 0.5f * ya_tex_scale.height()); | 2248 0.5f * ya_tex_scale.height()); |
| 2216 gfx::RectF uv_clamp_rect(uv_vertex_tex_translate_x, uv_vertex_tex_translate_y, | 2249 gfx::RectF uv_clamp_rect(uv_vertex_tex_translate_x, uv_vertex_tex_translate_y, |
| 2217 uv_vertex_tex_scale_x, uv_vertex_tex_scale_y); | 2250 uv_vertex_tex_scale_x, uv_vertex_tex_scale_y); |
| 2218 uv_clamp_rect.Inset(0.5f * uv_tex_scale.width(), | 2251 uv_clamp_rect.Inset(0.5f * uv_tex_scale.width(), |
| 2219 0.5f * uv_tex_scale.height()); | 2252 0.5f * uv_tex_scale.height()); |
| 2220 gl_->Uniform4f(ya_clamp_rect_location, ya_clamp_rect.x(), ya_clamp_rect.y(), | 2253 gl_->Uniform4f(program->ya_clamp_rect_location(), ya_clamp_rect.x(), |
| 2221 ya_clamp_rect.right(), ya_clamp_rect.bottom()); | 2254 ya_clamp_rect.y(), ya_clamp_rect.right(), |
| 2222 gl_->Uniform4f(uv_clamp_rect_location, uv_clamp_rect.x(), uv_clamp_rect.y(), | 2255 ya_clamp_rect.bottom()); |
| 2223 uv_clamp_rect.right(), uv_clamp_rect.bottom()); | 2256 gl_->Uniform4f(program->uv_clamp_rect_location(), uv_clamp_rect.x(), |
| 2257 uv_clamp_rect.y(), uv_clamp_rect.right(), |
| 2258 uv_clamp_rect.bottom()); |
| 2224 | 2259 |
| 2225 gl_->Uniform1i(y_texture_location, 1); | 2260 gl_->Uniform1i(program->y_texture_location(), 1); |
| 2226 if (use_nv12) { | 2261 if (uv_texture_mode == UV_TEXTURE_MODE_UV) { |
| 2227 gl_->Uniform1i(uv_texture_location, 2); | 2262 gl_->Uniform1i(program->uv_texture_location(), 2); |
| 2228 } else { | 2263 } else { |
| 2229 gl_->Uniform1i(u_texture_location, 2); | 2264 gl_->Uniform1i(program->u_texture_location(), 2); |
| 2230 gl_->Uniform1i(v_texture_location, 3); | 2265 gl_->Uniform1i(program->v_texture_location(), 3); |
| 2231 } | 2266 } |
| 2232 if (use_alpha_plane) | 2267 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) |
| 2233 gl_->Uniform1i(a_texture_location, 4); | 2268 gl_->Uniform1i(program->a_texture_location(), 4); |
| 2234 | 2269 |
| 2235 // These values are magic numbers that are used in the transformation from YUV | 2270 if (color_conversion_mode == COLOR_CONVERSION_MODE_LUT_FROM_YUV) { |
| 2236 // to RGB color values. They are taken from the following webpage: | 2271 const int kLUTSize = 17; |
| 2237 // http://www.fourcc.org/fccyvrgb.php | |
| 2238 float yuv_to_rgb_rec601[9] = { | |
| 2239 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f, | |
| 2240 }; | |
| 2241 float yuv_to_rgb_jpeg[9] = { | |
| 2242 1.f, 1.f, 1.f, 0.0f, -.34414f, 1.772f, 1.402f, -.71414f, 0.0f, | |
| 2243 }; | |
| 2244 float yuv_to_rgb_rec709[9] = { | |
| 2245 1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.112f, 1.793f, -0.533f, 0.0f, | |
| 2246 }; | |
| 2247 | |
| 2248 // They are used in the YUV to RGBA conversion formula: | |
| 2249 // Y - 16 : Gives 16 values of head and footroom for overshooting | |
| 2250 // U - 128 : Turns unsigned U into signed U [-128,127] | |
| 2251 // V - 128 : Turns unsigned V into signed V [-128,127] | |
| 2252 float yuv_adjust_constrained[3] = { | |
| 2253 -16.f, -128.f, -128.f, | |
| 2254 }; | |
| 2255 | |
| 2256 // Same as above, but without the head and footroom. | |
| 2257 float yuv_adjust_full[3] = { | |
| 2258 0.0f, -128.f, -128.f, | |
| 2259 }; | |
| 2260 | |
| 2261 float* yuv_to_rgb = NULL; | |
| 2262 float* yuv_adjust = NULL; | |
| 2263 | |
| 2264 switch (quad->color_space) { | |
| 2265 case YUVVideoDrawQuad::REC_601: | |
| 2266 yuv_to_rgb = yuv_to_rgb_rec601; | |
| 2267 yuv_adjust = yuv_adjust_constrained; | |
| 2268 break; | |
| 2269 case YUVVideoDrawQuad::REC_709: | |
| 2270 yuv_to_rgb = yuv_to_rgb_rec709; | |
| 2271 yuv_adjust = yuv_adjust_constrained; | |
| 2272 break; | |
| 2273 case YUVVideoDrawQuad::JPEG: | |
| 2274 yuv_to_rgb = yuv_to_rgb_jpeg; | |
| 2275 yuv_adjust = yuv_adjust_full; | |
| 2276 break; | |
| 2277 } | |
| 2278 | |
| 2279 float yuv_to_rgb_multiplied[9]; | |
| 2280 float yuv_adjust_with_offset[3]; | |
| 2281 | |
| 2282 // Formula according to BT.601-7 section 2.5.3. | |
| 2283 DCHECK_LE(YUVVideoDrawQuad::kMinBitsPerChannel, quad->bits_per_channel); | |
| 2284 DCHECK_LE(quad->bits_per_channel, YUVVideoDrawQuad::kMaxBitsPerChannel); | |
| 2285 float adjustment_multiplier = (1 << (quad->bits_per_channel - 8)) * 1.0f / | |
| 2286 ((1 << quad->bits_per_channel) - 1); | |
| 2287 | |
| 2288 for (int i = 0; i < 9; ++i) | |
| 2289 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * quad->resource_multiplier; | |
| 2290 | |
| 2291 for (int i = 0; i < 3; ++i) { | |
| 2292 yuv_adjust_with_offset[i] = | |
| 2293 yuv_adjust[i] * adjustment_multiplier / quad->resource_multiplier - | |
| 2294 quad->resource_offset; | |
| 2295 } | |
| 2296 | |
| 2297 if (lut_texture_location != -1) { | |
| 2298 unsigned int lut_texture = color_lut_cache_.GetLUT( | 2272 unsigned int lut_texture = color_lut_cache_.GetLUT( |
| 2299 quad->video_color_space, frame->device_color_space, 17); | 2273 quad->video_color_space, frame->device_color_space, kLUTSize); |
| 2300 gl_->ActiveTexture(GL_TEXTURE5); | 2274 gl_->ActiveTexture(GL_TEXTURE5); |
| 2301 gl_->BindTexture(GL_TEXTURE_2D, lut_texture); | 2275 gl_->BindTexture(GL_TEXTURE_2D, lut_texture); |
| 2302 gl_->Uniform1i(lut_texture_location, 5); | 2276 gl_->Uniform1i(program->lut_texture_location(), 5); |
| 2277 gl_->Uniform1f(program->lut_size_location(), kLUTSize); |
| 2303 gl_->ActiveTexture(GL_TEXTURE0); | 2278 gl_->ActiveTexture(GL_TEXTURE0); |
| 2304 } | 2279 gl_->Uniform1f(program->resource_multiplier_location(), |
| 2305 | 2280 quad->resource_multiplier); |
| 2306 if (resource_multiplier_location != -1) { | 2281 gl_->Uniform1f(program->resource_offset_location(), quad->resource_offset); |
| 2307 gl_->Uniform1f(resource_multiplier_location, quad->resource_multiplier); | 2282 } else { |
| 2308 } | 2283 float yuv_to_rgb_multiplied[9] = {0}; |
| 2309 | 2284 float yuv_adjust_with_offset[3] = {0}; |
| 2310 if (resource_offset_location != -1) { | 2285 ComputeYUVToRGBMatrices(quad->color_space, quad->bits_per_channel, |
| 2311 gl_->Uniform1f(resource_offset_location, quad->resource_offset); | 2286 quad->resource_multiplier, quad->resource_offset, |
| 2287 yuv_to_rgb_multiplied, yuv_adjust_with_offset); |
| 2288 gl_->UniformMatrix3fv(program->yuv_matrix_location(), 1, 0, |
| 2289 yuv_to_rgb_multiplied); |
| 2290 gl_->Uniform3fv(program->yuv_adj_location(), 1, yuv_adjust_with_offset); |
| 2312 } | 2291 } |
| 2313 | 2292 |
| 2314 // The transform and vertex data are used to figure out the extents that the | 2293 // The transform and vertex data are used to figure out the extents that the |
| 2315 // un-antialiased quad should have and which vertex this is and the float | 2294 // un-antialiased quad should have and which vertex this is and the float |
| 2316 // quad passed in via uniform is the actual geometry that gets used to draw | 2295 // quad passed in via uniform is the actual geometry that gets used to draw |
| 2317 // it. This is why this centered rect is used and not the original quad_rect. | 2296 // it. This is why this centered rect is used and not the original quad_rect. |
| 2318 auto tile_rect = gfx::RectF(quad->rect); | 2297 auto tile_rect = gfx::RectF(quad->rect); |
| 2319 if (yuv_matrix_location != -1) { | |
| 2320 gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb_multiplied); | |
| 2321 } | |
| 2322 | 2298 |
| 2323 if (yuv_adj_location) { | 2299 SetShaderOpacity(quad->shared_quad_state->opacity, program->alpha_location()); |
| 2324 gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust_with_offset); | |
| 2325 } | |
| 2326 | |
| 2327 SetShaderOpacity(quad->shared_quad_state->opacity, alpha_location); | |
| 2328 if (!clip_region) { | 2300 if (!clip_region) { |
| 2329 DrawQuadGeometry(frame->projection_matrix, | 2301 DrawQuadGeometry(frame->projection_matrix, |
| 2330 quad->shared_quad_state->quad_to_target_transform, | 2302 quad->shared_quad_state->quad_to_target_transform, |
| 2331 tile_rect, matrix_location); | 2303 tile_rect, program->matrix_location()); |
| 2332 } else { | 2304 } else { |
| 2333 float uvs[8] = {0}; | 2305 float uvs[8] = {0}; |
| 2334 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2306 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2335 gfx::QuadF region_quad = *clip_region; | 2307 gfx::QuadF region_quad = *clip_region; |
| 2336 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | 2308 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
| 2337 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | 2309 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2338 DrawQuadGeometryClippedByQuadF( | 2310 DrawQuadGeometryClippedByQuadF( |
| 2339 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, | 2311 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, |
| 2340 region_quad, matrix_location, uvs); | 2312 region_quad, program->matrix_location(), uvs); |
| 2341 } | 2313 } |
| 2342 } | 2314 } |
| 2343 | 2315 |
| 2344 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 2316 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
| 2345 const StreamVideoDrawQuad* quad, | 2317 const StreamVideoDrawQuad* quad, |
| 2346 const gfx::QuadF* clip_region) { | 2318 const gfx::QuadF* clip_region) { |
| 2347 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2319 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2348 | 2320 |
| 2349 static float gl_matrix[16]; | 2321 static float gl_matrix[16]; |
| 2350 | 2322 |
| (...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3603 // Return early if we are expecting more results. | 3575 // Return early if we are expecting more results. |
| 3604 if (overdraw->size() < num_expected_results) | 3576 if (overdraw->size() < num_expected_results) |
| 3605 return; | 3577 return; |
| 3606 | 3578 |
| 3607 // Report the maximum amount of overdraw. | 3579 // Report the maximum amount of overdraw. |
| 3608 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | 3580 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", |
| 3609 *std::max_element(overdraw->begin(), overdraw->end())); | 3581 *std::max_element(overdraw->begin(), overdraw->end())); |
| 3610 } | 3582 } |
| 3611 | 3583 |
| 3612 } // namespace cc | 3584 } // namespace cc |
| OLD | NEW |