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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 if (service_id > 0 && have_context) | 93 if (service_id > 0 && have_context) |
94 glDeleteTextures(1, &service_id); | 94 glDeleteTextures(1, &service_id); |
95 } | 95 } |
96 | 96 |
97 scoped_refptr<gfx::SurfaceTexture> | 97 scoped_refptr<gfx::SurfaceTexture> |
98 AndroidDeferredRenderingBackingStrategy::GetSurfaceTexture() const { | 98 AndroidDeferredRenderingBackingStrategy::GetSurfaceTexture() const { |
99 return surface_texture_; | 99 return surface_texture_; |
100 } | 100 } |
101 | 101 |
102 uint32_t AndroidDeferredRenderingBackingStrategy::GetTextureTarget() const { | 102 uint32_t AndroidDeferredRenderingBackingStrategy::GetTextureTarget() const { |
103 return GL_TEXTURE_EXTERNAL_OES; | 103 // If we're using a surface texture, then we need an external texture target |
104 // to sample from it. If not, then we'll use 2D transparent textures to draw | |
105 // a transparent hole through which to see the SurfaceView. This is normally | |
106 // needed only for the devtools inspector, since the overlay mechanism handles | |
107 // it otherwise. | |
108 return (surface_texture_ ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D); | |
DaleCurtis
2016/03/28 18:02:02
No unnecessary parens.
liberato (no reviews please)
2016/03/28 20:58:17
Done.
| |
104 } | 109 } |
105 | 110 |
106 AVDACodecImage* AndroidDeferredRenderingBackingStrategy::GetImageForPicture( | 111 AVDACodecImage* AndroidDeferredRenderingBackingStrategy::GetImageForPicture( |
107 const media::PictureBuffer& picture_buffer) { | 112 const media::PictureBuffer& picture_buffer) { |
108 gpu::gles2::TextureRef* texture_ref = | 113 gpu::gles2::TextureRef* texture_ref = |
109 state_provider_->GetTextureForPicture(picture_buffer); | 114 state_provider_->GetTextureForPicture(picture_buffer); |
110 RETURN_NULL_IF_NULL(texture_ref); | 115 RETURN_NULL_IF_NULL(texture_ref); |
111 gl::GLImage* image = | 116 gl::GLImage* image = |
112 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); | 117 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); |
113 return static_cast<AVDACodecImage*>(image); | 118 return static_cast<AVDACodecImage*>(image); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); | 176 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); |
172 RETURN_IF_NULL(avda_image); | 177 RETURN_IF_NULL(avda_image); |
173 DCHECK_EQ(avda_image->GetMediaCodecBufferIndex(), -1); | 178 DCHECK_EQ(avda_image->GetMediaCodecBufferIndex(), -1); |
174 // Note that this is not a race, since we do not re-use a PictureBuffer | 179 // Note that this is not a race, since we do not re-use a PictureBuffer |
175 // until after the CC is done drawing it. | 180 // until after the CC is done drawing it. |
176 avda_image->SetMediaCodecBufferIndex(codec_buf_index); | 181 avda_image->SetMediaCodecBufferIndex(codec_buf_index); |
177 avda_image->SetSize(state_provider_->GetSize()); | 182 avda_image->SetSize(state_provider_->GetSize()); |
178 } | 183 } |
179 | 184 |
180 void AndroidDeferredRenderingBackingStrategy::AssignOnePictureBuffer( | 185 void AndroidDeferredRenderingBackingStrategy::AssignOnePictureBuffer( |
181 const media::PictureBuffer& picture_buffer) { | 186 const media::PictureBuffer& picture_buffer, |
187 bool have_context) { | |
182 // Attach a GLImage to each texture that will use the surface texture. | 188 // Attach a GLImage to each texture that will use the surface texture. |
183 // We use a refptr here in case SetImageForPicture fails. | 189 // We use a refptr here in case SetImageForPicture fails. |
184 scoped_refptr<gpu::gles2::GLStreamTextureImage> gl_image = | 190 scoped_refptr<gpu::gles2::GLStreamTextureImage> gl_image = |
185 new AVDACodecImage(shared_state_, media_codec_, | 191 new AVDACodecImage(shared_state_, media_codec_, |
186 state_provider_->GetGlDecoder(), surface_texture_); | 192 state_provider_->GetGlDecoder(), surface_texture_); |
187 SetImageForPicture(picture_buffer, gl_image); | 193 SetImageForPicture(picture_buffer, gl_image); |
194 | |
195 if (!surface_texture_ && have_context) { | |
196 // To make devtools work, we're using a 2D texture. Make it transparent, | |
197 // so that it draws a hole for the SV to show through. This is only | |
198 // because devtools draws and reads back, which skips overlay processing. | |
199 // It's unclear why devtools renders twice -- once normally, and once | |
200 // including a readback layer. The result is that the device screen | |
201 // flashes as we alternately draw the overlay hole and this texture, | |
202 // unless we make the texture transparent. | |
203 unsigned char rgba[] = {0, 0, 0, 0}; | |
DaleCurtis
2016/03/28 18:02:02
static const, does uint8_t work?
liberato (no reviews please)
2016/03/28 20:58:17
Done.
| |
204 const gfx::Size size(1, 1); | |
DaleCurtis
2016/03/28 18:02:02
I'd just inline each value, but up to you.
liberato (no reviews please)
2016/03/28 20:58:17
i think that it's clearer than glTexImage2D(..., 1
| |
205 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, | |
206 GL_RGBA, GL_UNSIGNED_BYTE, rgba); | |
207 } | |
188 } | 208 } |
189 | 209 |
190 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( | 210 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( |
191 const media::PictureBuffer& picture_buffer) { | 211 const media::PictureBuffer& picture_buffer) { |
192 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); | 212 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); |
193 | 213 |
194 // See if there is a media codec buffer still attached to this image. | 214 // See if there is a media codec buffer still attached to this image. |
195 const int32_t codec_buffer = avda_image->GetMediaCodecBufferIndex(); | 215 const int32_t codec_buffer = avda_image->GetMediaCodecBufferIndex(); |
196 | 216 |
197 if (codec_buffer >= 0) { | 217 if (codec_buffer >= 0) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 base::ToLowerASCII(base::android::BuildInfo::GetInstance()->model())); | 381 base::ToLowerASCII(base::android::BuildInfo::GetInstance()->model())); |
362 if (model.find("a114") != std::string::npos) | 382 if (model.find("a114") != std::string::npos) |
363 surface_texture_detach_works = false; | 383 surface_texture_detach_works = false; |
364 } | 384 } |
365 } | 385 } |
366 | 386 |
367 return surface_texture_detach_works; | 387 return surface_texture_detach_works; |
368 } | 388 } |
369 | 389 |
370 } // namespace content | 390 } // namespace content |
OLD | NEW |