| 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 "media/gpu/avda_codec_image.h" | 5 #include "media/gpu/avda_codec_image.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/metrics/histogram_macros.h" | |
| 12 #include "gpu/command_buffer/service/context_group.h" | 11 #include "gpu/command_buffer/service/context_group.h" |
| 13 #include "gpu/command_buffer/service/context_state.h" | 12 #include "gpu/command_buffer/service/context_state.h" |
| 14 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 15 #include "gpu/command_buffer/service/texture_manager.h" | 14 #include "gpu/command_buffer/service/texture_manager.h" |
| 16 #include "media/gpu/avda_shared_state.h" | 15 #include "media/gpu/avda_shared_state.h" |
| 17 #include "ui/gl/android/surface_texture.h" | 16 #include "ui/gl/android/surface_texture.h" |
| 18 #include "ui/gl/gl_context.h" | 17 #include "ui/gl/gl_context.h" |
| 19 #include "ui/gl/scoped_make_current.h" | 18 #include "ui/gl/scoped_make_current.h" |
| 20 | 19 |
| 21 namespace media { | 20 namespace media { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 if (update_mode == UpdateMode::DISCARD_CODEC_BUFFER) { | 217 if (update_mode == UpdateMode::DISCARD_CODEC_BUFFER) { |
| 219 if (codec_buffer_index_ != kUpdateOnly) | 218 if (codec_buffer_index_ != kUpdateOnly) |
| 220 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, false); | 219 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, false); |
| 221 codec_buffer_index_ = kInvalidCodecBufferIndex; | 220 codec_buffer_index_ = kInvalidCodecBufferIndex; |
| 222 return; | 221 return; |
| 223 } | 222 } |
| 224 | 223 |
| 225 DCHECK(update_mode == UpdateMode::RENDER_TO_BACK_BUFFER || | 224 DCHECK(update_mode == UpdateMode::RENDER_TO_BACK_BUFFER || |
| 226 update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER); | 225 update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER); |
| 227 | 226 |
| 228 // If we've already released to the back buffer, there's nothing left to do. | |
| 229 if (codec_buffer_index_ == kUpdateOnly) | |
| 230 return; | |
| 231 | |
| 232 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, true); | |
| 233 codec_buffer_index_ = kUpdateOnly; | |
| 234 | |
| 235 // If we're using a SurfaceView we're done! | |
| 236 if (!surface_texture_) { | 227 if (!surface_texture_) { |
| 228 DCHECK(update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER); |
| 229 DCHECK_GE(codec_buffer_index_, 0); |
| 230 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, true); |
| 237 codec_buffer_index_ = kInvalidCodecBufferIndex; | 231 codec_buffer_index_ = kInvalidCodecBufferIndex; |
| 238 return; | 232 return; |
| 239 } | 233 } |
| 240 | 234 |
| 241 // This must be synchronous, so wait for OnFrameAvailable. | 235 // If we've already released to the back buffer, there's nothing left to do, |
| 242 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame"); | 236 // but wait for the previously released buffer if necessary. |
| 243 shared_state_->WaitForFrameAvailable(); | 237 if (codec_buffer_index_ != kUpdateOnly) { |
| 238 DCHECK(surface_texture_); |
| 239 DCHECK_GE(codec_buffer_index_, 0); |
| 240 shared_state_->RenderCodecBufferToSurfaceTexture(media_codec_, |
| 241 codec_buffer_index_); |
| 242 codec_buffer_index_ = kUpdateOnly; |
| 243 } |
| 244 |
| 245 // Only wait for the SurfaceTexture update if we're rendering to the front. |
| 246 if (update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER) |
| 247 shared_state_->WaitForFrameAvailable(); |
| 244 } | 248 } |
| 245 | 249 |
| 246 void AVDACodecImage::AttachSurfaceTextureToContext() { | 250 void AVDACodecImage::AttachSurfaceTextureToContext() { |
| 247 DCHECK(surface_texture_); | 251 DCHECK(surface_texture_); |
| 248 | 252 |
| 249 // We assume that the currently bound texture is the intended one. | 253 // We assume that the currently bound texture is the intended one. |
| 250 | 254 |
| 251 // Attach the surface texture to the first context we're bound on, so that | 255 // Attach the surface texture to the first context we're bound on, so that |
| 252 // no context switch is needed later. | 256 // no context switch is needed later. |
| 253 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 257 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 278 if (surface_texture_) | 282 if (surface_texture_) |
| 279 UpdateSurface(UpdateMode::RENDER_TO_FRONT_BUFFER); | 283 UpdateSurface(UpdateMode::RENDER_TO_FRONT_BUFFER); |
| 280 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); | 284 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); |
| 281 } | 285 } |
| 282 | 286 |
| 283 bool AVDACodecImage::IsCodecBufferOutstanding() const { | 287 bool AVDACodecImage::IsCodecBufferOutstanding() const { |
| 284 return codec_buffer_index_ != kInvalidCodecBufferIndex && media_codec_; | 288 return codec_buffer_index_ != kInvalidCodecBufferIndex && media_codec_; |
| 285 } | 289 } |
| 286 | 290 |
| 287 } // namespace media | 291 } // namespace media |
| OLD | NEW |