| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "content/common/gpu/gpu_channel.h" | 11 #include "content/common/gpu/gpu_channel.h" |
| 12 #include "content/common/gpu/gpu_surface_lookup.h" | 12 #include "content/common/gpu/gpu_surface_lookup.h" |
| 13 #include "content/common/gpu/media/avda_codec_image.h" | 13 #include "content/common/gpu/media/avda_codec_image.h" |
| 14 #include "content/common/gpu/media/avda_return_on_failure.h" | 14 #include "content/common/gpu/media/avda_return_on_failure.h" |
| 15 #include "content/common/gpu/media/avda_shared_state.h" | 15 #include "content/common/gpu/media/avda_shared_state.h" |
| 16 #include "gpu/command_buffer/service/texture_manager.h" | 16 #include "gpu/command_buffer/service/texture_manager.h" |
| 17 #include "ui/gl/android/surface_texture.h" | 17 #include "ui/gl/android/surface_texture.h" |
| 18 #include "ui/gl/gl_bindings.h" | 18 #include "ui/gl/gl_bindings.h" |
| 19 #include "ui/gl/gl_stream_texture_image.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 AndroidDeferredRenderingBackingStrategy:: | 23 AndroidDeferredRenderingBackingStrategy:: |
| 23 AndroidDeferredRenderingBackingStrategy(AVDAStateProvider* state_provider) | 24 AndroidDeferredRenderingBackingStrategy(AVDAStateProvider* state_provider) |
| 24 : state_provider_(state_provider), media_codec_(nullptr) {} | 25 : state_provider_(state_provider), media_codec_(nullptr) {} |
| 25 | 26 |
| 26 AndroidDeferredRenderingBackingStrategy:: | 27 AndroidDeferredRenderingBackingStrategy:: |
| 27 ~AndroidDeferredRenderingBackingStrategy() {} | 28 ~AndroidDeferredRenderingBackingStrategy() {} |
| 28 | 29 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 41 surface_texture_->DetachFromGLContext(); | 42 surface_texture_->DetachFromGLContext(); |
| 42 surface = gfx::ScopedJavaSurface(surface_texture_.get()); | 43 surface = gfx::ScopedJavaSurface(surface_texture_.get()); |
| 43 } | 44 } |
| 44 | 45 |
| 45 // Create a texture for the SurfaceTexture to use. We don't attach it here | 46 // Create a texture for the SurfaceTexture to use. We don't attach it here |
| 46 // so that it gets attached in the compositor gl context in the common case. | 47 // so that it gets attached in the compositor gl context in the common case. |
| 47 GLuint service_id = 0; | 48 GLuint service_id = 0; |
| 48 glGenTextures(1, &service_id); | 49 glGenTextures(1, &service_id); |
| 49 DCHECK(service_id); | 50 DCHECK(service_id); |
| 50 shared_state_->set_surface_texture_service_id(service_id); | 51 shared_state_->set_surface_texture_service_id(service_id); |
| 52 shared_state_->set_share_group(gfx::GLContext::GetCurrent()->share_group()); |
| 51 | 53 |
| 52 return surface; | 54 return surface; |
| 53 } | 55 } |
| 54 | 56 |
| 55 void AndroidDeferredRenderingBackingStrategy::Cleanup( | 57 void AndroidDeferredRenderingBackingStrategy::Cleanup( |
| 56 bool have_context, | 58 bool have_context, |
| 57 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { | 59 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { |
| 58 // If we failed before Initialize, then do nothing. | 60 // If we failed before Initialize, then do nothing. |
| 59 if (!shared_state_) | 61 if (!shared_state_) |
| 60 return; | 62 return; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 const media::PictureBuffer& picture_buffer) { | 100 const media::PictureBuffer& picture_buffer) { |
| 99 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); | 101 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); |
| 100 RETURN_NULL_IF_NULL(texture_ref); | 102 RETURN_NULL_IF_NULL(texture_ref); |
| 101 gl::GLImage* image = | 103 gl::GLImage* image = |
| 102 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); | 104 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); |
| 103 return static_cast<AVDACodecImage*>(image); | 105 return static_cast<AVDACodecImage*>(image); |
| 104 } | 106 } |
| 105 | 107 |
| 106 void AndroidDeferredRenderingBackingStrategy::SetImageForPicture( | 108 void AndroidDeferredRenderingBackingStrategy::SetImageForPicture( |
| 107 const media::PictureBuffer& picture_buffer, | 109 const media::PictureBuffer& picture_buffer, |
| 108 const scoped_refptr<gl::GLImage>& image) { | 110 const scoped_refptr<gl::GLStreamTextureImage>& image) { |
| 109 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); | 111 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); |
| 110 RETURN_IF_NULL(texture_ref); | 112 RETURN_IF_NULL(texture_ref); |
| 111 | 113 |
| 112 gpu::gles2::TextureManager* texture_manager = | 114 gpu::gles2::TextureManager* texture_manager = |
| 113 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); | 115 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); |
| 114 RETURN_IF_NULL(texture_manager); | 116 RETURN_IF_NULL(texture_manager); |
| 115 | 117 |
| 116 if (image) { | 118 if (image) { |
| 117 // Also set the parameters for the level if we're not clearing | 119 // Also set the parameters for the level if we're not clearing |
| 118 // the image. | 120 // the image. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 138 // For SurfaceTexture we set the image to UNBOUND so that the implementation | 140 // For SurfaceTexture we set the image to UNBOUND so that the implementation |
| 139 // will call CopyTexImage, which is where AVDACodecImage updates the | 141 // will call CopyTexImage, which is where AVDACodecImage updates the |
| 140 // SurfaceTexture to the right frame. | 142 // SurfaceTexture to the right frame. |
| 141 // For SurfaceView we set the image to be BOUND because ScheduleOverlayPlane | 143 // For SurfaceView we set the image to be BOUND because ScheduleOverlayPlane |
| 142 // expects it. If something tries to sample from this texture it won't work, | 144 // expects it. If something tries to sample from this texture it won't work, |
| 143 // but there's no way to sample from a SurfaceView anyway, so it doesn't | 145 // but there's no way to sample from a SurfaceView anyway, so it doesn't |
| 144 // matter. The only way to use this texture is to schedule it as an overlay. | 146 // matter. The only way to use this texture is to schedule it as an overlay. |
| 145 const gpu::gles2::Texture::ImageState image_state = | 147 const gpu::gles2::Texture::ImageState image_state = |
| 146 surface_texture_ ? gpu::gles2::Texture::UNBOUND | 148 surface_texture_ ? gpu::gles2::Texture::UNBOUND |
| 147 : gpu::gles2::Texture::BOUND; | 149 : gpu::gles2::Texture::BOUND; |
| 148 texture_manager->SetLevelImage(texture_ref, GetTextureTarget(), 0, | 150 texture_manager->SetLevelStreamTextureImage(texture_ref, GetTextureTarget(), |
| 149 image.get(), image_state); | 151 0, image.get(), image_state); |
| 150 } | 152 } |
| 151 | 153 |
| 152 void AndroidDeferredRenderingBackingStrategy::UseCodecBufferForPictureBuffer( | 154 void AndroidDeferredRenderingBackingStrategy::UseCodecBufferForPictureBuffer( |
| 153 int32_t codec_buf_index, | 155 int32_t codec_buf_index, |
| 154 const media::PictureBuffer& picture_buffer) { | 156 const media::PictureBuffer& picture_buffer) { |
| 155 // Make sure that the decoder is available. | 157 // Make sure that the decoder is available. |
| 156 RETURN_IF_NULL(state_provider_->GetGlDecoder()); | 158 RETURN_IF_NULL(state_provider_->GetGlDecoder()); |
| 157 | 159 |
| 158 // Notify the AVDACodecImage for picture_buffer that it should use the | 160 // Notify the AVDACodecImage for picture_buffer that it should use the |
| 159 // decoded buffer codec_buf_index to render this frame. | 161 // decoded buffer codec_buf_index to render this frame. |
| 160 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); | 162 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); |
| 161 RETURN_IF_NULL(avda_image); | 163 RETURN_IF_NULL(avda_image); |
| 162 DCHECK_EQ(avda_image->GetMediaCodecBufferIndex(), -1); | 164 DCHECK_EQ(avda_image->GetMediaCodecBufferIndex(), -1); |
| 163 // Note that this is not a race, since we do not re-use a PictureBuffer | 165 // Note that this is not a race, since we do not re-use a PictureBuffer |
| 164 // until after the CC is done drawing it. | 166 // until after the CC is done drawing it. |
| 165 avda_image->SetMediaCodecBufferIndex(codec_buf_index); | 167 avda_image->SetMediaCodecBufferIndex(codec_buf_index); |
| 166 avda_image->SetSize(state_provider_->GetSize()); | 168 avda_image->SetSize(state_provider_->GetSize()); |
| 167 } | 169 } |
| 168 | 170 |
| 169 void AndroidDeferredRenderingBackingStrategy::AssignOnePictureBuffer( | 171 void AndroidDeferredRenderingBackingStrategy::AssignOnePictureBuffer( |
| 170 const media::PictureBuffer& picture_buffer) { | 172 const media::PictureBuffer& picture_buffer) { |
| 171 // Attach a GLImage to each texture that will use the surface texture. | 173 // Attach a GLImage to each texture that will use the surface texture. |
| 172 // We use a refptr here in case SetImageForPicture fails. | 174 // We use a refptr here in case SetImageForPicture fails. |
| 173 scoped_refptr<gl::GLImage> gl_image = | 175 scoped_refptr<gl::GLStreamTextureImage> gl_image = |
| 174 new AVDACodecImage(shared_state_, media_codec_, | 176 new AVDACodecImage(shared_state_, media_codec_, |
| 175 state_provider_->GetGlDecoder(), surface_texture_); | 177 state_provider_->GetGlDecoder(), surface_texture_); |
| 176 SetImageForPicture(picture_buffer, gl_image); | 178 SetImageForPicture(picture_buffer, gl_image); |
| 177 } | 179 } |
| 178 | 180 |
| 179 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( | 181 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( |
| 180 const media::PictureBuffer& picture_buffer) { | 182 const media::PictureBuffer& picture_buffer) { |
| 181 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); | 183 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); |
| 182 | 184 |
| 183 // See if there is a media codec buffer still attached to this image. | 185 // See if there is a media codec buffer still attached to this image. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 shared_state_->SignalFrameAvailable(); | 230 shared_state_->SignalFrameAvailable(); |
| 229 } | 231 } |
| 230 | 232 |
| 231 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() { | 233 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() { |
| 232 // SurfaceView frames are always overlayable because that's the only way to | 234 // SurfaceView frames are always overlayable because that's the only way to |
| 233 // display them. | 235 // display them. |
| 234 return !surface_texture_; | 236 return !surface_texture_; |
| 235 } | 237 } |
| 236 | 238 |
| 237 } // namespace content | 239 } // namespace content |
| OLD | NEW |