Chromium Code Reviews| Index: content/common/gpu/media/rendering_helper.cc |
| diff --git a/content/common/gpu/media/rendering_helper.cc b/content/common/gpu/media/rendering_helper.cc |
| index b0f540ea866def2bc102b5bd609d4137df593be8..c18cffc5b9fb8b424a5f0049510d5af586328573 100644 |
| --- a/content/common/gpu/media/rendering_helper.cc |
| +++ b/content/common/gpu/media/rendering_helper.cc |
| @@ -330,13 +330,21 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params, |
| }); |
| #if GL_VARIANT_EGL |
| - static const char kFragmentShader[] = STRINGIZE( |
| - precision mediump float; |
| - varying vec2 interp_tc; |
| - uniform sampler2D tex; |
| - void main() { |
| - gl_FragColor = texture2D(tex, interp_tc); |
| - }); |
| + static const char kFragmentShader[] = |
| + "#extension GL_OES_EGL_image_external : enable\n" |
|
Ami GONE FROM CHROMIUM
2013/11/12 19:36:44
Sure would be nice if you could use STRINGIZE
Ami GONE FROM CHROMIUM
2013/11/12 19:36:44
This works on windows/angle?
sheu
2013/11/12 19:41:45
Can't, since we have an "#extension" preprocessor
sheu
2013/11/12 19:41:45
It should. To the trybot!
|
| + "precision mediump float;\n" |
| + "varying vec2 interp_tc;\n" |
| + "uniform sampler2D tex;\n" |
| + "#ifdef GL_OES_EGL_image_external\n" |
| + "uniform samplerExternalOES tex_external;\n" |
| + "#endif\n" |
| + "void main() {\n" |
| + " vec4 color = texture2D(tex, interp_tc);\n" |
| + "#ifdef GL_OES_EGL_image_external\n" |
| + " color += texture2D(tex_external, interp_tc);\n" |
| + "#endif\n" |
| + " gl_FragColor = color;\n" |
| + "}\n"; |
| #else |
| static const char kFragmentShader[] = STRINGIZE( |
| varying vec2 interp_tc; |
| @@ -365,6 +373,10 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params, |
| glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0); |
| glUniform1i(glGetUniformLocation(program_, "tex"), 0); |
| + GLint tex_external = glGetUniformLocation(program_, "tex_external"); |
| + if (tex_external != -1) { |
| + glUniform1i(tex_external, 1); |
| + } |
| int pos_location = glGetAttribLocation(program_, "in_pos"); |
| glEnableVertexAttribArray(pos_location); |
| glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); |
| @@ -406,32 +418,33 @@ void RenderingHelper::CreateTexture(int window_id, |
| window_id, texture_target, texture_id, done)); |
| return; |
| } |
| - CHECK_EQ(static_cast<uint32>(GL_TEXTURE_2D), texture_target); |
| MakeCurrent(window_id); |
| glGenTextures(1, texture_id); |
| - glBindTexture(GL_TEXTURE_2D, *texture_id); |
| + glBindTexture(texture_target, *texture_id); |
| int dimensions_id = window_id % frame_dimensions_.size(); |
| - glTexImage2D(GL_TEXTURE_2D, |
| - 0, |
| - GL_RGBA, |
| - frame_dimensions_[dimensions_id].width(), |
| - frame_dimensions_[dimensions_id].height(), |
| - 0, |
| - GL_RGBA, |
| - GL_UNSIGNED_BYTE, |
| - NULL); |
| - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| + if (texture_target == GL_TEXTURE_2D) { |
| + glTexImage2D(GL_TEXTURE_2D, |
| + 0, |
| + GL_RGBA, |
| + frame_dimensions_[dimensions_id].width(), |
| + frame_dimensions_[dimensions_id].height(), |
| + 0, |
| + GL_RGBA, |
| + GL_UNSIGNED_BYTE, |
| + NULL); |
| + } |
| + glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| + glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| // OpenGLES2.0.25 section 3.8.2 requires CLAMP_TO_EDGE for NPOT textures. |
| - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| + glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| + glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
| CHECK(texture_id_to_surface_index_.insert( |
| std::make_pair(*texture_id, window_id)).second); |
| done->Signal(); |
| } |
| -void RenderingHelper::RenderTexture(uint32 texture_id) { |
| +void RenderingHelper::RenderTexture(uint32 texture_target, uint32 texture_id) { |
| CHECK_EQ(base::MessageLoop::current(), message_loop_); |
| size_t window_id = texture_id_to_surface_index_[texture_id]; |
| MakeCurrent(window_id); |
| @@ -460,8 +473,19 @@ void RenderingHelper::RenderTexture(uint32 texture_id) { |
| glUniform1i(glGetUniformLocation(program_, "tex_flip"), 1); |
| } |
| - glActiveTexture(GL_TEXTURE0); |
| - glBindTexture(GL_TEXTURE_2D, texture_id); |
| + // Unbound texture samplers default to (0, 0, 0, 1). Use this fact to switch |
| + // between GL_TEXTURE_2D and GL_TEXTURE_EXTERNAL_OES as appopriate. |
| + if (texture_target == GL_TEXTURE_2D) { |
| + glActiveTexture(GL_TEXTURE0 + 0); |
| + glBindTexture(GL_TEXTURE_2D, texture_id); |
| + glActiveTexture(GL_TEXTURE0 + 1); |
| + glBindTexture(texture_target, 0); |
| + } else if (texture_target == GL_TEXTURE_EXTERNAL_OES) { |
| + glActiveTexture(GL_TEXTURE0 + 0); |
| + glBindTexture(GL_TEXTURE_2D, 0); |
| + glActiveTexture(GL_TEXTURE0 + 1); |
| + glBindTexture(texture_target, texture_id); |
| + } |
| glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
| @@ -473,7 +497,10 @@ void RenderingHelper::RenderTexture(uint32 texture_id) { |
| glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| glViewport(0, 0, width, height); |
| glScissor(0, 0, width, height); |
| + glActiveTexture(GL_TEXTURE0 + 0); |
| glBindTexture(GL_TEXTURE_2D, thumbnails_texture_id_); |
| + glActiveTexture(GL_TEXTURE0 + 1); |
| + glBindTexture(texture_target, 0); |
| glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| } |
| @@ -552,6 +579,7 @@ void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, |
| GL_RGBA, |
| GL_UNSIGNED_BYTE, |
| &rgba[0]); |
| + glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| rgb->resize(num_pixels * 3); |
| // Drop the alpha channel, but check as we go that it is all 0xff. |
| bool solid = true; |