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/gl_stream_texture_image.h" |
16 #include "gpu/command_buffer/service/texture_manager.h" | 17 #include "gpu/command_buffer/service/texture_manager.h" |
17 #include "ui/gl/android/surface_texture.h" | 18 #include "ui/gl/android/surface_texture.h" |
18 #include "ui/gl/gl_bindings.h" | 19 #include "ui/gl/gl_bindings.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 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 const media::PictureBuffer& picture_buffer) { | 99 const media::PictureBuffer& picture_buffer) { |
99 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); | 100 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); |
100 RETURN_NULL_IF_NULL(texture_ref); | 101 RETURN_NULL_IF_NULL(texture_ref); |
101 gl::GLImage* image = | 102 gl::GLImage* image = |
102 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); | 103 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); |
103 return static_cast<AVDACodecImage*>(image); | 104 return static_cast<AVDACodecImage*>(image); |
104 } | 105 } |
105 | 106 |
106 void AndroidDeferredRenderingBackingStrategy::SetImageForPicture( | 107 void AndroidDeferredRenderingBackingStrategy::SetImageForPicture( |
107 const media::PictureBuffer& picture_buffer, | 108 const media::PictureBuffer& picture_buffer, |
108 const scoped_refptr<gl::GLImage>& image) { | 109 const scoped_refptr<gpu::gles2::GLStreamTextureImage>& image) { |
109 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); | 110 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); |
110 RETURN_IF_NULL(texture_ref); | 111 RETURN_IF_NULL(texture_ref); |
111 | 112 |
112 gpu::gles2::TextureManager* texture_manager = | 113 gpu::gles2::TextureManager* texture_manager = |
113 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); | 114 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); |
114 RETURN_IF_NULL(texture_manager); | 115 RETURN_IF_NULL(texture_manager); |
115 | 116 |
116 if (image) { | 117 if (image) { |
117 // Also set the parameters for the level if we're not clearing | 118 // Also set the parameters for the level if we're not clearing |
118 // the image. | 119 // the image. |
(...skipping 19 matching lines...) Expand all Loading... |
138 // For SurfaceTexture we set the image to UNBOUND so that the implementation | 139 // For SurfaceTexture we set the image to UNBOUND so that the implementation |
139 // will call CopyTexImage, which is where AVDACodecImage updates the | 140 // will call CopyTexImage, which is where AVDACodecImage updates the |
140 // SurfaceTexture to the right frame. | 141 // SurfaceTexture to the right frame. |
141 // For SurfaceView we set the image to be BOUND because ScheduleOverlayPlane | 142 // 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, | 143 // 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 | 144 // 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. | 145 // matter. The only way to use this texture is to schedule it as an overlay. |
145 const gpu::gles2::Texture::ImageState image_state = | 146 const gpu::gles2::Texture::ImageState image_state = |
146 surface_texture_ ? gpu::gles2::Texture::UNBOUND | 147 surface_texture_ ? gpu::gles2::Texture::UNBOUND |
147 : gpu::gles2::Texture::BOUND; | 148 : gpu::gles2::Texture::BOUND; |
148 texture_manager->SetLevelImage(texture_ref, GetTextureTarget(), 0, | 149 texture_manager->SetLevelStreamTextureImage(texture_ref, GetTextureTarget(), |
149 image.get(), image_state); | 150 0, image.get(), image_state); |
150 } | 151 } |
151 | 152 |
152 void AndroidDeferredRenderingBackingStrategy::UseCodecBufferForPictureBuffer( | 153 void AndroidDeferredRenderingBackingStrategy::UseCodecBufferForPictureBuffer( |
153 int32_t codec_buf_index, | 154 int32_t codec_buf_index, |
154 const media::PictureBuffer& picture_buffer) { | 155 const media::PictureBuffer& picture_buffer) { |
155 // Make sure that the decoder is available. | 156 // Make sure that the decoder is available. |
156 RETURN_IF_NULL(state_provider_->GetGlDecoder()); | 157 RETURN_IF_NULL(state_provider_->GetGlDecoder()); |
157 | 158 |
158 // Notify the AVDACodecImage for picture_buffer that it should use the | 159 // Notify the AVDACodecImage for picture_buffer that it should use the |
159 // decoded buffer codec_buf_index to render this frame. | 160 // decoded buffer codec_buf_index to render this frame. |
160 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); | 161 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); |
161 RETURN_IF_NULL(avda_image); | 162 RETURN_IF_NULL(avda_image); |
162 DCHECK_EQ(avda_image->GetMediaCodecBufferIndex(), -1); | 163 DCHECK_EQ(avda_image->GetMediaCodecBufferIndex(), -1); |
163 // Note that this is not a race, since we do not re-use a PictureBuffer | 164 // Note that this is not a race, since we do not re-use a PictureBuffer |
164 // until after the CC is done drawing it. | 165 // until after the CC is done drawing it. |
165 avda_image->SetMediaCodecBufferIndex(codec_buf_index); | 166 avda_image->SetMediaCodecBufferIndex(codec_buf_index); |
166 avda_image->SetSize(state_provider_->GetSize()); | 167 avda_image->SetSize(state_provider_->GetSize()); |
167 } | 168 } |
168 | 169 |
169 void AndroidDeferredRenderingBackingStrategy::AssignOnePictureBuffer( | 170 void AndroidDeferredRenderingBackingStrategy::AssignOnePictureBuffer( |
170 const media::PictureBuffer& picture_buffer) { | 171 const media::PictureBuffer& picture_buffer) { |
171 // Attach a GLImage to each texture that will use the surface texture. | 172 // Attach a GLImage to each texture that will use the surface texture. |
172 // We use a refptr here in case SetImageForPicture fails. | 173 // We use a refptr here in case SetImageForPicture fails. |
173 scoped_refptr<gl::GLImage> gl_image = | 174 scoped_refptr<gpu::gles2::GLStreamTextureImage> gl_image = |
174 new AVDACodecImage(shared_state_, media_codec_, | 175 new AVDACodecImage(shared_state_, media_codec_, |
175 state_provider_->GetGlDecoder(), surface_texture_); | 176 state_provider_->GetGlDecoder(), surface_texture_); |
176 SetImageForPicture(picture_buffer, gl_image); | 177 SetImageForPicture(picture_buffer, gl_image); |
177 } | 178 } |
178 | 179 |
179 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( | 180 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( |
180 const media::PictureBuffer& picture_buffer) { | 181 const media::PictureBuffer& picture_buffer) { |
181 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); | 182 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); |
182 | 183 |
183 // See if there is a media codec buffer still attached to this image. | 184 // 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(); | 229 shared_state_->SignalFrameAvailable(); |
229 } | 230 } |
230 | 231 |
231 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() { | 232 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() { |
232 // SurfaceView frames are always overlayable because that's the only way to | 233 // SurfaceView frames are always overlayable because that's the only way to |
233 // display them. | 234 // display them. |
234 return !surface_texture_; | 235 return !surface_texture_; |
235 } | 236 } |
236 | 237 |
237 } // namespace content | 238 } // namespace content |
OLD | NEW |