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

Side by Side Diff: Source/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp

Issue 6460020: Merge 77608 - 2011-02-03 Victoria Kirst <vrk@google.com>... (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/648/
Patch Set: Created 9 years, 10 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
« no previous file with comments | « Source/WebCore/platform/graphics/chromium/VideoLayerChromium.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 VideoLayerChromium::SharedValues::SharedValues(GraphicsContext3D* context) 54 VideoLayerChromium::SharedValues::SharedValues(GraphicsContext3D* context)
55 : m_context(context) 55 : m_context(context)
56 , m_yuvShaderProgram(0) 56 , m_yuvShaderProgram(0)
57 , m_rgbaShaderProgram(0) 57 , m_rgbaShaderProgram(0)
58 , m_yuvShaderMatrixLocation(0) 58 , m_yuvShaderMatrixLocation(0)
59 , m_yuvWidthScaleFactorLocation(0) 59 , m_yuvWidthScaleFactorLocation(0)
60 , m_rgbaShaderMatrixLocation(0) 60 , m_rgbaShaderMatrixLocation(0)
61 , m_rgbaWidthScaleFactorLocation(0) 61 , m_rgbaWidthScaleFactorLocation(0)
62 , m_ccMatrixLocation(0) 62 , m_ccMatrixLocation(0)
63 , m_signAdjLocation(0)
63 , m_yTextureLocation(0) 64 , m_yTextureLocation(0)
64 , m_uTextureLocation(0) 65 , m_uTextureLocation(0)
65 , m_vTextureLocation(0) 66 , m_vTextureLocation(0)
66 , m_rgbaTextureLocation(0) 67 , m_rgbaTextureLocation(0)
67 , m_yuvAlphaLocation(0) 68 , m_yuvAlphaLocation(0)
68 , m_rgbaAlphaLocation(0) 69 , m_rgbaAlphaLocation(0)
69 , m_initialized(false) 70 , m_initialized(false)
70 { 71 {
71 // Frame textures are allocated based on stride width, not visible frame 72 // Frame textures are allocated based on stride width, not visible frame
72 // width, such that there is a guarantee that the frame rows line up 73 // width, such that there is a guarantee that the frame rows line up
(...skipping 16 matching lines...) Expand all
89 "} \n"; 90 "} \n";
90 91
91 char yuvFragmentShaderString[] = 92 char yuvFragmentShaderString[] =
92 "precision mediump float; \n" 93 "precision mediump float; \n"
93 "precision mediump int; \n" 94 "precision mediump int; \n"
94 "varying vec2 v_texCoord; \n" 95 "varying vec2 v_texCoord; \n"
95 "uniform sampler2D y_texture; \n" 96 "uniform sampler2D y_texture; \n"
96 "uniform sampler2D u_texture; \n" 97 "uniform sampler2D u_texture; \n"
97 "uniform sampler2D v_texture; \n" 98 "uniform sampler2D v_texture; \n"
98 "uniform float alpha; \n" 99 "uniform float alpha; \n"
100 "uniform float adj; \n"
99 "uniform mat3 cc_matrix; \n" 101 "uniform mat3 cc_matrix; \n"
100 "void main() \n" 102 "void main() \n"
101 "{ \n" 103 "{ \n"
102 " float y = texture2D(y_texture, v_texCoord).x; \n" 104 " float y = texture2D(y_texture, v_texCoord).x; \n"
103 " float u = texture2D(u_texture, v_texCoord).r - .5; \n" 105 " float u = texture2D(u_texture, v_texCoord).x - adj; \n"
104 " float v = texture2D(v_texture, v_texCoord).r - .5; \n" 106 " float v = texture2D(v_texture, v_texCoord).x - adj; \n"
105 " vec3 rgb = cc_matrix * vec3(y, u, v); \n" 107 " vec3 rgb = cc_matrix * vec3(y, u, v); \n"
106 " gl_FragColor = vec4(rgb.x, rgb.y, rgb.z, 1.0) * alpha; \n" 108 " gl_FragColor = vec4(rgb, float(1)) * alpha; \n"
107 "} \n"; 109 "} \n";
108 110
109 char rgbaFragmentShaderString[] = 111 char rgbaFragmentShaderString[] =
110 "precision mediump float; \n" 112 "precision mediump float; \n"
111 "varying vec2 v_texCoord; \n" 113 "varying vec2 v_texCoord; \n"
112 "uniform sampler2D rgba_texture; \n" 114 "uniform sampler2D rgba_texture; \n"
113 "uniform float alpha; \n" 115 "uniform float alpha; \n"
114 "void main() \n" 116 "void main() \n"
115 "{ \n" 117 "{ \n"
116 " vec4 texColor = texture2D(rgba_texture, vec2(v_texCoord.x, 1.0 - v_te xCoord.y)); \n" 118 " vec4 texColor = texture2D(rgba_texture, vec2(v_texCoord.x, float(1) - v_texCoord.y)); \n"
117 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; \n" 119 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; \n"
118 "} \n"; 120 "} \n";
119 121
120 m_rgbaShaderProgram = createShaderProgram(m_context, vertexShaderString, rgb aFragmentShaderString); 122 m_rgbaShaderProgram = createShaderProgram(m_context, vertexShaderString, rgb aFragmentShaderString);
121 if (!m_rgbaShaderProgram) { 123 if (!m_rgbaShaderProgram) {
122 LOG_ERROR("VideoLayerChromium: Failed to create rgba shader program"); 124 LOG_ERROR("VideoLayerChromium: Failed to create rgba shader program");
123 return; 125 return;
124 } 126 }
125 127
126 m_yuvShaderProgram = createShaderProgram(m_context, vertexShaderString, yuvF ragmentShaderString); 128 m_yuvShaderProgram = createShaderProgram(m_context, vertexShaderString, yuvF ragmentShaderString);
127 if (!m_yuvShaderProgram) { 129 if (!m_yuvShaderProgram) {
128 LOG_ERROR("VideoLayerChromium: Failed to create yuv shader program"); 130 LOG_ERROR("VideoLayerChromium: Failed to create yuv shader program");
129 return; 131 return;
130 } 132 }
131 133
132 m_yuvShaderMatrixLocation = m_context->getUniformLocation(m_yuvShaderProgram , "matrix"); 134 m_yuvShaderMatrixLocation = m_context->getUniformLocation(m_yuvShaderProgram , "matrix");
133 m_yuvWidthScaleFactorLocation = m_context->getUniformLocation(m_yuvShaderPro gram, "widthScaleFactor"); 135 m_yuvWidthScaleFactorLocation = m_context->getUniformLocation(m_yuvShaderPro gram, "widthScaleFactor");
134 m_yTextureLocation = m_context->getUniformLocation(m_yuvShaderProgram, "y_te xture"); 136 m_yTextureLocation = m_context->getUniformLocation(m_yuvShaderProgram, "y_te xture");
135 m_uTextureLocation = m_context->getUniformLocation(m_yuvShaderProgram, "u_te xture"); 137 m_uTextureLocation = m_context->getUniformLocation(m_yuvShaderProgram, "u_te xture");
136 m_vTextureLocation = m_context->getUniformLocation(m_yuvShaderProgram, "v_te xture"); 138 m_vTextureLocation = m_context->getUniformLocation(m_yuvShaderProgram, "v_te xture");
137 m_ccMatrixLocation = m_context->getUniformLocation(m_yuvShaderProgram, "cc_m atrix"); 139 m_ccMatrixLocation = m_context->getUniformLocation(m_yuvShaderProgram, "cc_m atrix");
140 m_signAdjLocation = m_context->getUniformLocation(m_yuvShaderProgram, "adj") ;
138 m_yuvAlphaLocation = m_context->getUniformLocation(m_yuvShaderProgram, "alph a"); 141 m_yuvAlphaLocation = m_context->getUniformLocation(m_yuvShaderProgram, "alph a");
139 142
140 ASSERT(m_yuvShaderMatrixLocation != -1); 143 ASSERT(m_yuvShaderMatrixLocation != -1);
141 ASSERT(m_yuvWidthScaleFactorLocation != -1); 144 ASSERT(m_yuvWidthScaleFactorLocation != -1);
142 ASSERT(m_yTextureLocation != -1); 145 ASSERT(m_yTextureLocation != -1);
143 ASSERT(m_uTextureLocation != -1); 146 ASSERT(m_uTextureLocation != -1);
144 ASSERT(m_vTextureLocation != -1); 147 ASSERT(m_vTextureLocation != -1);
145 ASSERT(m_ccMatrixLocation != -1); 148 ASSERT(m_ccMatrixLocation != -1);
149 ASSERT(m_signAdjLocation != -1);
146 ASSERT(m_yuvAlphaLocation != -1); 150 ASSERT(m_yuvAlphaLocation != -1);
147 151
148 m_rgbaShaderMatrixLocation = m_context->getUniformLocation(m_rgbaShaderProgr am, "matrix"); 152 m_rgbaShaderMatrixLocation = m_context->getUniformLocation(m_rgbaShaderProgr am, "matrix");
149 m_rgbaTextureLocation = m_context->getUniformLocation(m_rgbaShaderProgram, " rgba_texture"); 153 m_rgbaTextureLocation = m_context->getUniformLocation(m_rgbaShaderProgram, " rgba_texture");
150 m_rgbaWidthScaleFactorLocation = m_context->getUniformLocation(m_rgbaShaderP rogram, "widthScaleFactor"); 154 m_rgbaWidthScaleFactorLocation = m_context->getUniformLocation(m_rgbaShaderP rogram, "widthScaleFactor");
151 m_rgbaAlphaLocation = m_context->getUniformLocation(m_rgbaShaderProgram, "al pha"); 155 m_rgbaAlphaLocation = m_context->getUniformLocation(m_rgbaShaderProgram, "al pha");
152 156
153 ASSERT(m_rgbaShaderMatrixLocation != -1); 157 ASSERT(m_rgbaShaderMatrixLocation != -1);
154 ASSERT(m_rgbaTextureLocation != -1); 158 ASSERT(m_rgbaTextureLocation != -1);
155 ASSERT(m_rgbaWidthScaleFactorLocation != -1); 159 ASSERT(m_rgbaWidthScaleFactorLocation != -1);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 layerRenderer()->useShader(sv->yuvShaderProgram()); 372 layerRenderer()->useShader(sv->yuvShaderProgram());
369 unsigned frameWidth = m_frameSizes[VideoFrameChromium::yPlane].width(); 373 unsigned frameWidth = m_frameSizes[VideoFrameChromium::yPlane].width();
370 unsigned textureWidth = m_textureSizes[VideoFrameChromium::yPlane].width(); 374 unsigned textureWidth = m_textureSizes[VideoFrameChromium::yPlane].width();
371 float widthScaleFactor = static_cast<float>(frameWidth) / textureWidth; 375 float widthScaleFactor = static_cast<float>(frameWidth) / textureWidth;
372 GLC(context, context->uniform1f(sv->yuvWidthScaleFactorLocation(), widthScal eFactor)); 376 GLC(context, context->uniform1f(sv->yuvWidthScaleFactorLocation(), widthScal eFactor));
373 377
374 GLC(context, context->uniform1i(sv->yTextureLocation(), 1)); 378 GLC(context, context->uniform1i(sv->yTextureLocation(), 1));
375 GLC(context, context->uniform1i(sv->uTextureLocation(), 2)); 379 GLC(context, context->uniform1i(sv->uTextureLocation(), 2));
376 GLC(context, context->uniform1i(sv->vTextureLocation(), 3)); 380 GLC(context, context->uniform1i(sv->vTextureLocation(), 3));
377 381
382 // This value of 0.5 maps to 128. It is used in the YUV to RGB conversion
383 // formula to turn unsigned u and v values to signed u and v values.
384 // This is loaded as a uniform because certain drivers have problems
385 // reading literal float values.
386 GLC(context, context->uniform1f(sv->signAdjLocation(), 0.5));
387
378 GLC(context, context->uniformMatrix3fv(sv->ccMatrixLocation(), 0, const_cast <float*>(yuv2RGB), 1)); 388 GLC(context, context->uniformMatrix3fv(sv->ccMatrixLocation(), 0, const_cast <float*>(yuv2RGB), 1));
379 389
380 drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform (), 390 drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform (),
381 bounds().width(), bounds().height(), drawOpacity(), 391 bounds().width(), bounds().height(), drawOpacity(),
382 sv->yuvShaderMatrixLocation(), sv->yuvAlphaLocation()); 392 sv->yuvShaderMatrixLocation(), sv->yuvAlphaLocation());
383 393
384 // Reset active texture back to texture 0. 394 // Reset active texture back to texture 0.
385 GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0)); 395 GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
386 } 396 }
387 397
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 for (unsigned plane = 0; plane < frame->planes(); plane++) { 430 for (unsigned plane = 0; plane < frame->planes(); plane++) {
421 m_textures[plane] = frame->texture(plane); 431 m_textures[plane] = frame->texture(plane);
422 m_textureSizes[plane] = frame->requiredTextureSize(plane); 432 m_textureSizes[plane] = frame->requiredTextureSize(plane);
423 m_frameSizes[plane] = m_textureSizes[plane]; 433 m_frameSizes[plane] = m_textureSizes[plane];
424 } 434 }
425 } 435 }
426 436
427 } // namespace WebCore 437 } // namespace WebCore
428 438
429 #endif // USE(ACCELERATED_COMPOSITING) 439 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW
« no previous file with comments | « Source/WebCore/platform/graphics/chromium/VideoLayerChromium.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698