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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 12157002: Adding YUVA support for enabling Alpha Playback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 | Annotate | Revision Log
OLDNEW
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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 bool NeedsIOSurfaceReadbackWorkaround() { 72 bool NeedsIOSurfaceReadbackWorkaround() {
73 #if defined(OS_MACOSX) 73 #if defined(OS_MACOSX)
74 // This isn't strictly required in DumpRenderTree-mode when Mesa is used, 74 // This isn't strictly required in DumpRenderTree-mode when Mesa is used,
75 // but it doesn't seem to hurt. 75 // but it doesn't seem to hurt.
76 return true; 76 return true;
77 #else 77 #else
78 return false; 78 return false;
79 #endif 79 #endif
80 } 80 }
81 81
82 // These values are magic numbers that are used in the transformation from YUV t o RGB color values.
83 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb.php
84 float yuv_to_rgb[9] = {
85 1.164f, 1.164f, 1.164f,
86 0.f, -.391f, 2.018f,
87 1.596f, -.813f, 0.f,
88 };
89
90 // These values map to 16, 128, and 128 respectively, and are computed
91 // as a fraction over 256 (e.g. 16 / 256 = 0.0625).
92 // They are used in the YUV to RGBA conversion formula:
93 // Y - 16 : Gives 16 values of head and footroom for overshooting
94 // U - 128 : Turns unsigned U into signed U [-128,127]
95 // V - 128 : Turns unsigned V into signed V [-128,127]
96 float yuv_adjust[3] = { -0.0625f, -0.5f, -0.5f, };
97
82 } // anonymous namespace 98 } // anonymous namespace
83 99
84 scoped_ptr<GLRenderer> GLRenderer::Create(RendererClient* client, 100 scoped_ptr<GLRenderer> GLRenderer::Create(RendererClient* client,
85 OutputSurface* output_surface, 101 OutputSurface* output_surface,
86 ResourceProvider* resource_provider) { 102 ResourceProvider* resource_provider) {
87 scoped_ptr<GLRenderer> renderer( 103 scoped_ptr<GLRenderer> renderer(
88 new GLRenderer(client, output_surface, resource_provider)); 104 new GLRenderer(client, output_surface, resource_provider));
89 if (!renderer->Initialize()) 105 if (!renderer->Initialize())
90 return scoped_ptr<GLRenderer>(); 106 return scoped_ptr<GLRenderer>();
91 107
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 break; 335 break;
320 case DrawQuad::TEXTURE_CONTENT: 336 case DrawQuad::TEXTURE_CONTENT:
321 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); 337 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad));
322 break; 338 break;
323 case DrawQuad::TILED_CONTENT: 339 case DrawQuad::TILED_CONTENT:
324 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); 340 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad));
325 break; 341 break;
326 case DrawQuad::YUV_VIDEO_CONTENT: 342 case DrawQuad::YUV_VIDEO_CONTENT:
327 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); 343 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad));
328 break; 344 break;
345 case DrawQuad::YUVA_VIDEO_CONTENT:
346 DrawYUVAVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad));
347 break;
329 } 348 }
330 } 349 }
331 350
332 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, 351 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame,
333 const CheckerboardDrawQuad* quad) { 352 const CheckerboardDrawQuad* quad) {
334 SetBlendEnabled(quad->ShouldDrawWithBlending()); 353 SetBlendEnabled(quad->ShouldDrawWithBlending());
335 354
336 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); 355 const TileCheckerboardProgram* program = GetTileCheckerboardProgram();
337 DCHECK(program && (program->initialized() || IsContextLost())); 356 DCHECK(program && (program->initialized() || IsContextLost()));
338 SetUseProgram(program->program()); 357 SetUseProgram(program->program());
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 Context()->uniform2f(program->vertex_shader().tex_scale_location(), 1241 Context()->uniform2f(program->vertex_shader().tex_scale_location(),
1223 quad->tex_scale.width(), 1242 quad->tex_scale.width(),
1224 quad->tex_scale.height())); 1243 quad->tex_scale.height()));
1225 GLC(Context(), 1244 GLC(Context(),
1226 Context()->uniform1i(program->fragment_shader().y_texture_location(), 1)); 1245 Context()->uniform1i(program->fragment_shader().y_texture_location(), 1));
1227 GLC(Context(), 1246 GLC(Context(),
1228 Context()->uniform1i(program->fragment_shader().u_texture_location(), 2)); 1247 Context()->uniform1i(program->fragment_shader().u_texture_location(), 2));
1229 GLC(Context(), 1248 GLC(Context(),
1230 Context()->uniform1i(program->fragment_shader().v_texture_location(), 3)); 1249 Context()->uniform1i(program->fragment_shader().v_texture_location(), 3));
1231 1250
1232 // These values are magic numbers that are used in the transformation from YUV 1251 GLC(Context(),
1233 // to RGB color values. They are taken from the following webpage: 1252 Context()->uniformMatrix3fv(
1234 // http://www.fourcc.org/fccyvrgb.php 1253 program->fragment_shader().yuv_matrix_location(), 1, 0, yuv_to_rgb));
1235 float yuv_to_rgb[9] = { 1254 GLC(Context(),
1236 1.164f, 1.164f, 1.164f, 1255 Context()->uniform3fv(program->fragment_shader().yuv_adj_location(), 1,
1237 0.0f, -.391f, 2.018f, 1256 yuv_adjust));
1238 1.596f, -.813f, 0.0f, 1257
1239 }; 1258 SetShaderOpacity(quad->opacity(), program->fragment_shader().alpha_location()) ;
1259 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect,
1260 program->vertex_shader().matrix_location());
1261
1262 // Reset active texture back to texture 0.
1263 GLC(Context(), Context()->activeTexture(GL_TEXTURE0));
1264 }
1265
1266 void GLRenderer::DrawYUVAVideoQuad(const DrawingFrame* frame,
danakj 2013/03/28 20:59:24 Can you merge this function with DrawYUVVideoQuad?
vignesh 2013/04/02 20:56:15 Which enum value are you referring to ? Also, what
danakj 2013/04/03 00:41:12 Sorry, I am referring to the DrawQuad::Material en
vignesh 2013/04/04 00:37:33 I have eliminated the enum type and included both
1267 const YUVVideoDrawQuad* quad)
1268 {
1269 SetBlendEnabled(quad->ShouldDrawWithBlending());
1270
1271 const VideoYUVAProgram* program = GetVideoYUVAProgram();
1272 DCHECK(program && (program->initialized() || IsContextLost()));
1273
1274 const VideoLayerImpl::FramePlane& y_plane = quad->y_plane;
1275 const VideoLayerImpl::FramePlane& u_plane = quad->u_plane;
1276 const VideoLayerImpl::FramePlane& v_plane = quad->v_plane;
1277 const VideoLayerImpl::FramePlane& a_plane = quad->a_plane;
1278
1279 GLC(Context(), Context()->activeTexture(GL_TEXTURE1));
1280 ResourceProvider::ScopedSamplerGL y_plane_lock(
1281 resource_provider_, y_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR);
1282 GLC(Context(), Context()->activeTexture(GL_TEXTURE2));
1283 ResourceProvider::ScopedSamplerGL u_plane_lock(
1284 resource_provider_, u_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR);
1285 GLC(Context(), Context()->activeTexture(GL_TEXTURE3));
1286 ResourceProvider::ScopedSamplerGL v_plane_lock(
1287 resource_provider_, v_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR);
1288 ResourceProvider::ScopedSamplerGL A_plane_lock(
1289 resource_provider_, a_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR);
1290
1291 SetUseProgram(program->program());
1292
1293 GLC(Context(),
1294 Context()->uniform2f(program->vertex_shader().tex_scale_location(),
1295 quad->tex_scale.width(),
1296 quad->tex_scale.height()));
1297 GLC(Context(),
1298 Context()->uniform1i(program->fragment_shader().y_texture_location(), 1));
1299 GLC(Context(),
1300 Context()->uniform1i(program->fragment_shader().u_texture_location(), 2));
1301 GLC(Context(),
1302 Context()->uniform1i(program->fragment_shader().v_texture_location(), 3));
1303 GLC(Context(),
1304 Context()->uniform1i(program->fragment_shader().a_texture_location(), 4));
1305
1240 GLC(Context(), 1306 GLC(Context(),
1241 Context()->uniformMatrix3fv( 1307 Context()->uniformMatrix3fv(
1242 program->fragment_shader().yuv_matrix_location(), 1, 0, yuv_to_rgb)); 1308 program->fragment_shader().yuv_matrix_location(), 1, 0, yuv_to_rgb));
1243 1309
1244 // These values map to 16, 128, and 128 respectively, and are computed
1245 // as a fraction over 256 (e.g. 16 / 256 = 0.0625).
1246 // They are used in the YUV to RGBA conversion formula:
1247 // Y - 16 : Gives 16 values of head and footroom for overshooting
1248 // U - 128 : Turns unsigned U into signed U [-128,127]
1249 // V - 128 : Turns unsigned V into signed V [-128,127]
1250 float yuv_adjust[3] = { -0.0625f, -0.5f, -0.5f, };
1251 GLC(Context(), 1310 GLC(Context(),
1252 Context()->uniform3fv( 1311 Context()->uniform3fv(
1253 program->fragment_shader().yuv_adj_location(), 1, yuv_adjust)); 1312 program->fragment_shader().yuv_adj_location(), 1, yuv_adjust));
1254 1313
1255 SetShaderOpacity(quad->opacity(), 1314 SetShaderOpacity(quad->opacity(),
1256 program->fragment_shader().alpha_location()); 1315 program->fragment_shader().alpha_location());
1257 DrawQuadGeometry(frame, 1316 DrawQuadGeometry(frame,
1258 quad->quadTransform(), 1317 quad->quadTransform(),
1259 quad->rect, 1318 quad->rect,
1260 program->vertex_shader().matrix_location()); 1319 program->vertex_shader().matrix_location());
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram() { 2261 const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram() {
2203 if (!video_yuv_program_) 2262 if (!video_yuv_program_)
2204 video_yuv_program_ = make_scoped_ptr(new VideoYUVProgram(context_)); 2263 video_yuv_program_ = make_scoped_ptr(new VideoYUVProgram(context_));
2205 if (!video_yuv_program_->initialized()) { 2264 if (!video_yuv_program_->initialized()) {
2206 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); 2265 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize");
2207 video_yuv_program_->Initialize(context_, is_using_bind_uniform_); 2266 video_yuv_program_->Initialize(context_, is_using_bind_uniform_);
2208 } 2267 }
2209 return video_yuv_program_.get(); 2268 return video_yuv_program_.get();
2210 } 2269 }
2211 2270
2271 const GLRenderer::VideoYUVAProgram* GLRenderer::GetVideoYUVAProgram()
2272 {
2273 if (!video_yuva_program_)
2274 video_yuva_program_ = make_scoped_ptr(new VideoYUVAProgram(context_));
2275 if (!video_yuva_program_->initialized()) {
2276 TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize");
2277 video_yuva_program_->Initialize(context_, is_using_bind_uniform_);
2278 }
2279 return video_yuva_program_.get();
2280 }
2281
2212 const GLRenderer::VideoStreamTextureProgram* 2282 const GLRenderer::VideoStreamTextureProgram*
2213 GLRenderer::GetVideoStreamTextureProgram() { 2283 GLRenderer::GetVideoStreamTextureProgram() {
2214 if (!Capabilities().using_egl_image) 2284 if (!Capabilities().using_egl_image)
2215 return NULL; 2285 return NULL;
2216 if (!video_stream_texture_program_) 2286 if (!video_stream_texture_program_)
2217 video_stream_texture_program_ = 2287 video_stream_texture_program_ =
2218 make_scoped_ptr(new VideoStreamTextureProgram(context_)); 2288 make_scoped_ptr(new VideoStreamTextureProgram(context_));
2219 if (!video_stream_texture_program_->initialized()) { 2289 if (!video_stream_texture_program_->initialized()) {
2220 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); 2290 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize");
2221 video_stream_texture_program_->Initialize(context_, is_using_bind_uniform_); 2291 video_stream_texture_program_->Initialize(context_, is_using_bind_uniform_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 2324
2255 if (texture_program_) 2325 if (texture_program_)
2256 texture_program_->Cleanup(context_); 2326 texture_program_->Cleanup(context_);
2257 if (texture_program_flip_) 2327 if (texture_program_flip_)
2258 texture_program_flip_->Cleanup(context_); 2328 texture_program_flip_->Cleanup(context_);
2259 if (texture_io_surface_program_) 2329 if (texture_io_surface_program_)
2260 texture_io_surface_program_->Cleanup(context_); 2330 texture_io_surface_program_->Cleanup(context_);
2261 2331
2262 if (video_yuv_program_) 2332 if (video_yuv_program_)
2263 video_yuv_program_->Cleanup(context_); 2333 video_yuv_program_->Cleanup(context_);
2334 if (video_yuva_program_)
2335 video_yuva_program_->Cleanup(context_);
2264 if (video_stream_texture_program_) 2336 if (video_stream_texture_program_)
2265 video_stream_texture_program_->Cleanup(context_); 2337 video_stream_texture_program_->Cleanup(context_);
2266 2338
2267 if (debug_border_program_) 2339 if (debug_border_program_)
2268 debug_border_program_->Cleanup(context_); 2340 debug_border_program_->Cleanup(context_);
2269 if (solid_color_program_) 2341 if (solid_color_program_)
2270 solid_color_program_->Cleanup(context_); 2342 solid_color_program_->Cleanup(context_);
2271 if (solid_color_program_aa_) 2343 if (solid_color_program_aa_)
2272 solid_color_program_aa_->Cleanup(context_); 2344 solid_color_program_aa_->Cleanup(context_);
2273 2345
2274 if (offscreen_framebuffer_id_) 2346 if (offscreen_framebuffer_id_)
2275 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); 2347 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_));
2276 2348
2277 if (on_demand_tile_raster_resource_id_) 2349 if (on_demand_tile_raster_resource_id_)
2278 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); 2350 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_);
2279 2351
2280 ReleaseRenderPassTextures(); 2352 ReleaseRenderPassTextures();
2281 } 2353 }
2282 2354
2283 bool GLRenderer::IsContextLost() { 2355 bool GLRenderer::IsContextLost() {
2284 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); 2356 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR);
2285 } 2357 }
2286 2358
2287 } // namespace cc 2359 } // namespace cc
OLDNEW
« cc/output/gl_renderer.h ('K') | « cc/output/gl_renderer.h ('k') | cc/output/shader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698