| 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; |
| 109 } |
| 110 |
| 111 gfx::Size AndroidDeferredRenderingBackingStrategy::GetPictureBufferSize() |
| 112 const { |
| 113 // For SurfaceView, request a 1x1 2D texture to reduce memory during |
| 114 // initialization. For SurfaceTexture, allocate a picture buffer that is the |
| 115 // actual frame size. Note that it will be an external texture anyway, so it |
| 116 // doesn't allocate an image of that size. However, it's still important to |
| 117 // get the coded size right, so that VideoLayerImpl doesn't try to scale the |
| 118 // texture when building the quad for it. |
| 119 return surface_texture_ ? state_provider_->GetSize() : gfx::Size(1, 1); |
| 104 } | 120 } |
| 105 | 121 |
| 106 AVDACodecImage* AndroidDeferredRenderingBackingStrategy::GetImageForPicture( | 122 AVDACodecImage* AndroidDeferredRenderingBackingStrategy::GetImageForPicture( |
| 107 const media::PictureBuffer& picture_buffer) { | 123 const media::PictureBuffer& picture_buffer) { |
| 108 gpu::gles2::TextureRef* texture_ref = | 124 gpu::gles2::TextureRef* texture_ref = |
| 109 state_provider_->GetTextureForPicture(picture_buffer); | 125 state_provider_->GetTextureForPicture(picture_buffer); |
| 110 RETURN_NULL_IF_NULL(texture_ref); | 126 RETURN_NULL_IF_NULL(texture_ref); |
| 111 gl::GLImage* image = | 127 gl::GLImage* image = |
| 112 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); | 128 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); |
| 113 return static_cast<AVDACodecImage*>(image); | 129 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); | 187 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); |
| 172 RETURN_IF_NULL(avda_image); | 188 RETURN_IF_NULL(avda_image); |
| 173 DCHECK_EQ(avda_image->GetMediaCodecBufferIndex(), -1); | 189 DCHECK_EQ(avda_image->GetMediaCodecBufferIndex(), -1); |
| 174 // Note that this is not a race, since we do not re-use a PictureBuffer | 190 // Note that this is not a race, since we do not re-use a PictureBuffer |
| 175 // until after the CC is done drawing it. | 191 // until after the CC is done drawing it. |
| 176 avda_image->SetMediaCodecBufferIndex(codec_buf_index); | 192 avda_image->SetMediaCodecBufferIndex(codec_buf_index); |
| 177 avda_image->SetSize(state_provider_->GetSize()); | 193 avda_image->SetSize(state_provider_->GetSize()); |
| 178 } | 194 } |
| 179 | 195 |
| 180 void AndroidDeferredRenderingBackingStrategy::AssignOnePictureBuffer( | 196 void AndroidDeferredRenderingBackingStrategy::AssignOnePictureBuffer( |
| 181 const media::PictureBuffer& picture_buffer) { | 197 const media::PictureBuffer& picture_buffer, |
| 198 bool have_context) { |
| 182 // Attach a GLImage to each texture that will use the surface texture. | 199 // Attach a GLImage to each texture that will use the surface texture. |
| 183 // We use a refptr here in case SetImageForPicture fails. | 200 // We use a refptr here in case SetImageForPicture fails. |
| 184 scoped_refptr<gpu::gles2::GLStreamTextureImage> gl_image = | 201 scoped_refptr<gpu::gles2::GLStreamTextureImage> gl_image = |
| 185 new AVDACodecImage(shared_state_, media_codec_, | 202 new AVDACodecImage(shared_state_, media_codec_, |
| 186 state_provider_->GetGlDecoder(), surface_texture_); | 203 state_provider_->GetGlDecoder(), surface_texture_); |
| 187 SetImageForPicture(picture_buffer, gl_image); | 204 SetImageForPicture(picture_buffer, gl_image); |
| 205 |
| 206 if (!surface_texture_ && have_context) { |
| 207 // To make devtools work, we're using a 2D texture. Make it transparent, |
| 208 // so that it draws a hole for the SV to show through. This is only |
| 209 // because devtools draws and reads back, which skips overlay processing. |
| 210 // It's unclear why devtools renders twice -- once normally, and once |
| 211 // including a readback layer. The result is that the device screen |
| 212 // flashes as we alternately draw the overlay hole and this texture, |
| 213 // unless we make the texture transparent. |
| 214 static const uint8_t rgba[] = {0, 0, 0, 0}; |
| 215 const gfx::Size size(1, 1); |
| 216 glBindTexture(GL_TEXTURE_2D, picture_buffer.texture_id()); |
| 217 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, |
| 218 GL_RGBA, GL_UNSIGNED_BYTE, rgba); |
| 219 } |
| 188 } | 220 } |
| 189 | 221 |
| 190 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( | 222 void AndroidDeferredRenderingBackingStrategy::ReleaseCodecBufferForPicture( |
| 191 const media::PictureBuffer& picture_buffer) { | 223 const media::PictureBuffer& picture_buffer) { |
| 192 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); | 224 AVDACodecImage* avda_image = GetImageForPicture(picture_buffer); |
| 193 | 225 |
| 194 // See if there is a media codec buffer still attached to this image. | 226 // See if there is a media codec buffer still attached to this image. |
| 195 const int32_t codec_buffer = avda_image->GetMediaCodecBufferIndex(); | 227 const int32_t codec_buffer = avda_image->GetMediaCodecBufferIndex(); |
| 196 | 228 |
| 197 if (codec_buffer >= 0) { | 229 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())); | 393 base::ToLowerASCII(base::android::BuildInfo::GetInstance()->model())); |
| 362 if (model.find("a114") != std::string::npos) | 394 if (model.find("a114") != std::string::npos) |
| 363 surface_texture_detach_works = false; | 395 surface_texture_detach_works = false; |
| 364 } | 396 } |
| 365 } | 397 } |
| 366 | 398 |
| 367 return surface_texture_detach_works; | 399 return surface_texture_detach_works; |
| 368 } | 400 } |
| 369 | 401 |
| 370 } // namespace content | 402 } // namespace content |
| OLD | NEW |