| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/common/gpu/media/avda_codec_image.h" | 5 #include "content/common/gpu/media/avda_codec_image.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "content/common/gpu/media/avda_shared_state.h" | 10 #include "content/common/gpu/media/avda_shared_state.h" |
| 11 #include "gpu/command_buffer/service/context_group.h" | |
| 12 #include "gpu/command_buffer/service/context_state.h" | |
| 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 14 #include "gpu/command_buffer/service/texture_manager.h" | 12 #include "gpu/command_buffer/service/texture_manager.h" |
| 15 #include "ui/gl/android/surface_texture.h" | 13 #include "ui/gl/android/surface_texture.h" |
| 16 #include "ui/gl/gl_context.h" | 14 #include "ui/gl/gl_context.h" |
| 17 #include "ui/gl/scoped_make_current.h" | 15 #include "ui/gl/scoped_make_current.h" |
| 18 | 16 |
| 19 namespace content { | 17 namespace content { |
| 20 | 18 |
| 21 AVDACodecImage::AVDACodecImage( | 19 AVDACodecImage::AVDACodecImage( |
| 22 const scoped_refptr<AVDASharedState>& shared_state, | 20 const scoped_refptr<AVDASharedState>& shared_state, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 61 |
| 64 // Verify that the currently bound texture is the right one. If we're not | 62 // Verify that the currently bound texture is the right one. If we're not |
| 65 // copying to a Texture that shares our service_id, then we can't do much. | 63 // copying to a Texture that shares our service_id, then we can't do much. |
| 66 // This will force a copy. | 64 // This will force a copy. |
| 67 // TODO(liberato): Fall back to a copy that uses the texture matrix. | 65 // TODO(liberato): Fall back to a copy that uses the texture matrix. |
| 68 GLint bound_service_id = 0; | 66 GLint bound_service_id = 0; |
| 69 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); | 67 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); |
| 70 if (bound_service_id != shared_state_->surface_texture_service_id()) | 68 if (bound_service_id != shared_state_->surface_texture_service_id()) |
| 71 return false; | 69 return false; |
| 72 | 70 |
| 73 // Attach the surface texture to our GL context if needed. | 71 // Attach the surface texture to the first context we're bound on, so that |
| 72 // no context switch is needed later. |
| 74 if (!shared_state_->surface_texture_is_attached()) | 73 if (!shared_state_->surface_texture_is_attached()) |
| 75 AttachSurfaceTextureToContext(); | 74 AttachSurfaceTextureToContext(); |
| 76 | 75 |
| 77 // Make sure that we have the right image in the front buffer. | 76 // Make sure that we have the right image in the front buffer. |
| 78 UpdateSurfaceTexture(); | 77 UpdateSurfaceTexture(); |
| 79 | 78 |
| 79 // TODO(liberato): Improve the way we handle the texture matrix. |
| 80 // crbug.com/530681 |
| 80 InstallTextureMatrix(); | 81 InstallTextureMatrix(); |
| 81 | 82 |
| 82 // TODO(liberato): Handle the texture matrix properly. | |
| 83 // Either we can update the shader with it or we can move all of the logic | |
| 84 // to updateTexImage() to the right place in the cc to send it to the shader. | |
| 85 // For now, we just skip it. crbug.com/530681 | |
| 86 | |
| 87 // By setting image state to UNBOUND instead of COPIED we ensure that | 83 // By setting image state to UNBOUND instead of COPIED we ensure that |
| 88 // CopyTexImage() is called each time the surface texture is used for drawing. | 84 // CopyTexImage() is called each time the surface texture is used for drawing. |
| 89 // It would be nice if we could do this via asking for the currently bound | 85 // It would be nice if we could do this via asking for the currently bound |
| 90 // Texture, but the active unit never seems to change. | 86 // Texture, but the active unit never seems to change. |
| 91 texture_->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, | 87 texture_->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, |
| 92 gpu::gles2::Texture::UNBOUND); | 88 gpu::gles2::Texture::UNBOUND); |
| 93 | 89 |
| 94 return true; | 90 return true; |
| 95 } | 91 } |
| 96 | 92 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 154 } |
| 159 | 155 |
| 160 int AVDACodecImage::GetMediaCodecBufferIndex() const { | 156 int AVDACodecImage::GetMediaCodecBufferIndex() const { |
| 161 return codec_buffer_index_; | 157 return codec_buffer_index_; |
| 162 } | 158 } |
| 163 | 159 |
| 164 void AVDACodecImage::SetSize(const gfx::Size& size) { | 160 void AVDACodecImage::SetSize(const gfx::Size& size) { |
| 165 size_ = size; | 161 size_ = size; |
| 166 } | 162 } |
| 167 | 163 |
| 168 void AVDACodecImage::SetMediaCodec(media::MediaCodecBridge* codec) { | 164 void AVDACodecImage::SetMediaCodec(media::VideoCodecBridge* codec) { |
| 169 media_codec_ = codec; | 165 media_codec_ = codec; |
| 170 } | 166 } |
| 171 | 167 |
| 172 void AVDACodecImage::SetTexture(gpu::gles2::Texture* texture) { | 168 void AVDACodecImage::SetTexture(gpu::gles2::Texture* texture) { |
| 173 texture_ = texture; | 169 texture_ = texture; |
| 174 } | 170 } |
| 175 | 171 |
| 176 void AVDACodecImage::AttachSurfaceTextureToContext() { | 172 void AVDACodecImage::AttachSurfaceTextureToContext() { |
| 177 DCHECK(surface_texture_); | 173 DCHECK(surface_texture_); |
| 178 | 174 |
| 179 // Attach the surface texture to the first context we're bound on, so that | 175 // Attach the surface texture to the first context we're bound on, so that |
| 180 // no context switch is needed later. | 176 // no context switch is needed later. |
| 181 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 177 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 182 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 178 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 183 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 179 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 184 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 180 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 185 | 181 |
| 186 // The surface texture is already detached, so just attach it. | 182 // The surface texture is already detached, so just attach it. |
| 187 // We could do this earlier, but SurfaceTexture has context affinity, and we | 183 // We could do this earlier, but SurfaceTexture has context affinity, and we |
| 188 // don't want to require a context switch. | 184 // don't want to require a context switch. |
| 189 surface_texture_->AttachToGLContext(); | 185 surface_texture_->AttachToGLContext(); |
| 190 shared_state_->did_attach_surface_texture(); | 186 shared_state_->DidAttachSurfaceTexture(); |
| 191 } | 187 } |
| 192 | 188 |
| 193 void AVDACodecImage::InstallTextureMatrix() { | 189 void AVDACodecImage::InstallTextureMatrix() { |
| 194 DCHECK(surface_texture_); | 190 DCHECK(surface_texture_); |
| 195 | 191 |
| 196 // glUseProgram() has been run already -- just modify the uniform. | 192 // glUseProgram() has been run already -- just modify the uniform. |
| 197 // Updating this via VideoFrameProvider::Client::DidUpdateMatrix() would | 193 // Updating this via VideoFrameProvider::Client::DidUpdateMatrix() would |
| 198 // be a better solution, except that we'd definitely miss a frame at this | 194 // be a better solution, except that we'd definitely miss a frame at this |
| 199 // point in drawing. | 195 // point in drawing. |
| 200 // Our current method assumes that we'll end up being a stream resource, | 196 // Our current method assumes that we'll end up being a stream resource, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 214 // Only try once. | 210 // Only try once. |
| 215 need_shader_info_ = false; | 211 need_shader_info_ = false; |
| 216 } | 212 } |
| 217 | 213 |
| 218 if (texmatrix_uniform_location_ >= 0) { | 214 if (texmatrix_uniform_location_ >= 0) { |
| 219 glUniformMatrix4fv(texmatrix_uniform_location_, 1, false, gl_matrix_); | 215 glUniformMatrix4fv(texmatrix_uniform_location_, 1, false, gl_matrix_); |
| 220 } | 216 } |
| 221 } | 217 } |
| 222 | 218 |
| 223 } // namespace content | 219 } // namespace content |
| OLD | NEW |