| 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/android_deferred_rendering_backing_strategy.h
" | 5 #include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h
" |
| 6 | 6 |
| 7 #include <EGL/egl.h> | 7 #include <EGL/egl.h> |
| 8 #include <EGL/eglext.h> | 8 #include <EGL/eglext.h> |
| 9 | 9 |
| 10 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 void AndroidDeferredRenderingBackingStrategy::Cleanup( | 73 void AndroidDeferredRenderingBackingStrategy::Cleanup( |
| 74 bool have_context, | 74 bool have_context, |
| 75 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { | 75 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { |
| 76 // If we failed before Initialize, then do nothing. | 76 // If we failed before Initialize, then do nothing. |
| 77 if (!shared_state_) | 77 if (!shared_state_) |
| 78 return; | 78 return; |
| 79 | 79 |
| 80 // Make sure that no PictureBuffer textures refer to the SurfaceTexture or to | 80 // Make sure that no PictureBuffer textures refer to the SurfaceTexture or to |
| 81 // the service_id that we created for it. | 81 // the service_id that we created for it. |
| 82 for (const std::pair<int, media::PictureBuffer>& entry : buffers) | 82 for (const std::pair<int, media::PictureBuffer>& entry : buffers) { |
| 83 ReleaseCodecBufferForPicture(entry.second); |
| 83 SetImageForPicture(entry.second, nullptr); | 84 SetImageForPicture(entry.second, nullptr); |
| 85 } |
| 84 | 86 |
| 85 // If we're rendering to a SurfaceTexture we can make a copy of the current | 87 // If we're rendering to a SurfaceTexture we can make a copy of the current |
| 86 // front buffer so that the PictureBuffer textures are still valid. | 88 // front buffer so that the PictureBuffer textures are still valid. |
| 87 if (surface_texture_ && have_context && ShouldCopyPictures()) | 89 if (surface_texture_ && have_context && ShouldCopyPictures()) |
| 88 CopySurfaceTextureToPictures(buffers); | 90 CopySurfaceTextureToPictures(buffers); |
| 89 | 91 |
| 90 // Now that no AVDACodecImages refer to the SurfaceTexture's texture, delete | 92 // Now that no AVDACodecImages refer to the SurfaceTexture's texture, delete |
| 91 // the texture name. | 93 // the texture name. |
| 92 GLuint service_id = shared_state_->surface_texture_service_id(); | 94 GLuint service_id = shared_state_->surface_texture_service_id(); |
| 93 if (service_id > 0 && have_context) | 95 if (service_id > 0 && have_context) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 glBindTexture(GL_TEXTURE_2D, picture_buffer.texture_ids()[0]); | 219 glBindTexture(GL_TEXTURE_2D, picture_buffer.texture_ids()[0]); |
| 218 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, | 220 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, |
| 219 GL_RGBA, GL_UNSIGNED_BYTE, rgba); | 221 GL_RGBA, GL_UNSIGNED_BYTE, rgba); |
| 220 } | 222 } |
| 221 } | 223 } |
| 222 | 224 |
| 223 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( | 225 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( |
| 224 const media::PictureBuffer& picture_buffer) { | 226 const media::PictureBuffer& picture_buffer) { |
| 225 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); | 227 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); |
| 226 | 228 |
| 229 if (!avda_image) |
| 230 return; |
| 231 |
| 227 // See if there is a media codec buffer still attached to this image. | 232 // See if there is a media codec buffer still attached to this image. |
| 228 const int32_t codec_buffer = avda_image->GetMediaCodecBufferIndex(); | 233 const int32_t codec_buffer = avda_image->GetMediaCodecBufferIndex(); |
| 229 | 234 |
| 230 if (codec_buffer >= 0) { | 235 if (codec_buffer >= 0) { |
| 231 // PictureBuffer wasn't displayed, so release the buffer. | 236 // PictureBuffer wasn't displayed, so release the buffer. |
| 232 media_codec_->ReleaseOutputBuffer(codec_buffer, false); | 237 media_codec_->ReleaseOutputBuffer(codec_buffer, false); |
| 233 avda_image->SetMediaCodecBufferIndex(-1); | 238 avda_image->SetMediaCodecBufferIndex(-1); |
| 234 } | 239 } |
| 235 } | 240 } |
| 236 | 241 |
| 237 void AndroidDeferredRenderingBackingStrategy::ReuseOnePictureBuffer( | 242 void AndroidDeferredRenderingBackingStrategy::ReuseOnePictureBuffer( |
| 238 const media::PictureBuffer& picture_buffer) { | 243 const media::PictureBuffer& picture_buffer) { |
| 239 // At this point, the CC must be done with the picture. We can't really | 244 // At this point, the CC must be done with the picture. We can't really |
| 240 // check for that here directly. it's guaranteed in gpu_video_decoder.cc, | 245 // check for that here directly. it's guaranteed in gpu_video_decoder.cc, |
| 241 // when it waits on the sync point before releasing the mailbox. That sync | 246 // when it waits on the sync point before releasing the mailbox. That sync |
| 242 // point is inserted by destroying the resource in VideoLayerImpl::DidDraw. | 247 // point is inserted by destroying the resource in VideoLayerImpl::DidDraw. |
| 243 ReleaseCodecBufferForPicture(picture_buffer); | 248 ReleaseCodecBufferForPicture(picture_buffer); |
| 244 } | 249 } |
| 245 | 250 |
| 251 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBuffers( |
| 252 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { |
| 253 for (const std::pair<int, media::PictureBuffer>& entry : buffers) |
| 254 ReleaseCodecBufferForPicture(entry.second); |
| 255 } |
| 256 |
| 246 void AndroidDeferredRenderingBackingStrategy::CodecChanged( | 257 void AndroidDeferredRenderingBackingStrategy::CodecChanged( |
| 247 media::VideoCodecBridge* codec, | 258 media::VideoCodecBridge* codec, |
| 248 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { | 259 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { |
| 249 // Clear any outstanding codec buffer indices, since the new codec (if any) | 260 // Clear any outstanding codec buffer indices, since the new codec (if any) |
| 250 // doesn't know about them. | 261 // doesn't know about them. |
| 251 media_codec_ = codec; | 262 media_codec_ = codec; |
| 252 for (const std::pair<int, media::PictureBuffer>& entry : buffers) { | 263 for (const std::pair<int, media::PictureBuffer>& entry : buffers) { |
| 253 AVDACodecImage* avda_image = GetImageForPicture(entry.second); | 264 AVDACodecImage* avda_image = GetImageForPicture(entry.second); |
| 254 avda_image->SetMediaCodec(codec); | 265 avda_image->SetMediaCodec(codec); |
| 255 avda_image->SetMediaCodecBufferIndex(-1); | 266 avda_image->SetMediaCodecBufferIndex(-1); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return !feature_info->workarounds().avda_dont_copy_pictures; | 408 return !feature_info->workarounds().avda_dont_copy_pictures; |
| 398 } | 409 } |
| 399 } | 410 } |
| 400 } | 411 } |
| 401 | 412 |
| 402 // Assume so. | 413 // Assume so. |
| 403 return true; | 414 return true; |
| 404 } | 415 } |
| 405 | 416 |
| 406 } // namespace content | 417 } // namespace content |
| OLD | NEW |