| 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 <EGL/egl.h> | 5 #include <EGL/egl.h> |
| 6 #include <EGL/eglext.h> | 6 #include <EGL/eglext.h> |
| 7 | 7 |
| 8 #include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h
" | 8 #include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h
" |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 return GL_TEXTURE_EXTERNAL_OES; |
| 104 } | 104 } |
| 105 | 105 |
| 106 gpu::gles2::TextureRef* | |
| 107 AndroidDeferredRenderingBackingStrategy::GetTextureForPicture( | |
| 108 const media::PictureBuffer& picture_buffer) { | |
| 109 RETURN_NULL_IF_NULL(state_provider_->GetGlDecoder()); | |
| 110 gpu::gles2::TextureManager* texture_manager = | |
| 111 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); | |
| 112 RETURN_NULL_IF_NULL(texture_manager); | |
| 113 gpu::gles2::TextureRef* texture_ref = | |
| 114 texture_manager->GetTexture(picture_buffer.internal_texture_id()); | |
| 115 RETURN_NULL_IF_NULL(texture_ref); | |
| 116 | |
| 117 return texture_ref; | |
| 118 } | |
| 119 | |
| 120 AVDACodecImage* AndroidDeferredRenderingBackingStrategy::GetImageForPicture( | 106 AVDACodecImage* AndroidDeferredRenderingBackingStrategy::GetImageForPicture( |
| 121 const media::PictureBuffer& picture_buffer) { | 107 const media::PictureBuffer& picture_buffer) { |
| 122 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); | 108 gpu::gles2::TextureRef* texture_ref = |
| 109 state_provider_->GetTextureForPicture(picture_buffer); |
| 123 RETURN_NULL_IF_NULL(texture_ref); | 110 RETURN_NULL_IF_NULL(texture_ref); |
| 124 gl::GLImage* image = | 111 gl::GLImage* image = |
| 125 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); | 112 texture_ref->texture()->GetLevelImage(GetTextureTarget(), 0); |
| 126 return static_cast<AVDACodecImage*>(image); | 113 return static_cast<AVDACodecImage*>(image); |
| 127 } | 114 } |
| 128 | 115 |
| 129 void AndroidDeferredRenderingBackingStrategy::SetImageForPicture( | 116 void AndroidDeferredRenderingBackingStrategy::SetImageForPicture( |
| 130 const media::PictureBuffer& picture_buffer, | 117 const media::PictureBuffer& picture_buffer, |
| 131 const scoped_refptr<gpu::gles2::GLStreamTextureImage>& image) { | 118 const scoped_refptr<gpu::gles2::GLStreamTextureImage>& image) { |
| 132 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(picture_buffer); | 119 gpu::gles2::TextureRef* texture_ref = |
| 120 state_provider_->GetTextureForPicture(picture_buffer); |
| 133 RETURN_IF_NULL(texture_ref); | 121 RETURN_IF_NULL(texture_ref); |
| 134 | 122 |
| 135 gpu::gles2::TextureManager* texture_manager = | 123 gpu::gles2::TextureManager* texture_manager = |
| 136 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); | 124 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); |
| 137 RETURN_IF_NULL(texture_manager); | 125 RETURN_IF_NULL(texture_manager); |
| 138 | 126 |
| 139 if (image) { | 127 if (image) { |
| 140 // Also set the parameters for the level if we're not clearing | 128 // Also set the parameters for the level if we're not clearing |
| 141 // the image. | 129 // the image. |
| 142 const gfx::Size size = state_provider_->GetSize(); | 130 const gfx::Size size = state_provider_->GetSize(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 void AndroidDeferredRenderingBackingStrategy::OnFrameAvailable() { | 238 void AndroidDeferredRenderingBackingStrategy::OnFrameAvailable() { |
| 251 shared_state_->SignalFrameAvailable(); | 239 shared_state_->SignalFrameAvailable(); |
| 252 } | 240 } |
| 253 | 241 |
| 254 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() { | 242 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() { |
| 255 // SurfaceView frames are always overlayable because that's the only way to | 243 // SurfaceView frames are always overlayable because that's the only way to |
| 256 // display them. | 244 // display them. |
| 257 return !surface_texture_; | 245 return !surface_texture_; |
| 258 } | 246 } |
| 259 | 247 |
| 248 void AndroidDeferredRenderingBackingStrategy::UpdatePictureBufferSize( |
| 249 media::PictureBuffer* picture_buffer, |
| 250 const gfx::Size& new_size) { |
| 251 // This strategy uses OES textures which do not have a notion of size. We |
| 252 // simply update the PictureBuffer meta-data and leave the texture as-is. |
| 253 picture_buffer->set_size(new_size); |
| 254 } |
| 255 |
| 260 void AndroidDeferredRenderingBackingStrategy::CopySurfaceTextureToPictures( | 256 void AndroidDeferredRenderingBackingStrategy::CopySurfaceTextureToPictures( |
| 261 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { | 257 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { |
| 262 DVLOG(3) << __FUNCTION__; | 258 DVLOG(3) << __FUNCTION__; |
| 263 | 259 |
| 264 // Don't try to copy if the SurfaceTexture was never attached because that | 260 // Don't try to copy if the SurfaceTexture was never attached because that |
| 265 // means it was never updated. | 261 // means it was never updated. |
| 266 if (!shared_state_->surface_texture_is_attached()) | 262 if (!shared_state_->surface_texture_is_attached()) |
| 267 return; | 263 return; |
| 268 | 264 |
| 269 gpu::gles2::GLES2Decoder* gl_decoder = state_provider_->GetGlDecoder().get(); | 265 gpu::gles2::GLES2Decoder* gl_decoder = state_provider_->GetGlDecoder().get(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 309 |
| 314 glDeleteTextures(1, &tmp_texture_id); | 310 glDeleteTextures(1, &tmp_texture_id); |
| 315 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 311 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 316 | 312 |
| 317 if (egl_image == EGL_NO_IMAGE_KHR) { | 313 if (egl_image == EGL_NO_IMAGE_KHR) { |
| 318 DLOG(ERROR) << "Failed creating EGLImage: " << ui::GetLastEGLErrorString(); | 314 DLOG(ERROR) << "Failed creating EGLImage: " << ui::GetLastEGLErrorString(); |
| 319 return; | 315 return; |
| 320 } | 316 } |
| 321 | 317 |
| 322 for (const std::pair<int, media::PictureBuffer>& entry : buffers) { | 318 for (const std::pair<int, media::PictureBuffer>& entry : buffers) { |
| 323 gpu::gles2::TextureRef* texture_ref = GetTextureForPicture(entry.second); | 319 gpu::gles2::TextureRef* texture_ref = |
| 320 state_provider_->GetTextureForPicture(entry.second); |
| 324 gfx::ScopedTextureBinder texture_binder( | 321 gfx::ScopedTextureBinder texture_binder( |
| 325 GL_TEXTURE_EXTERNAL_OES, texture_ref->texture()->service_id()); | 322 GL_TEXTURE_EXTERNAL_OES, texture_ref->texture()->service_id()); |
| 326 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); | 323 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); |
| 327 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 324 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 328 } | 325 } |
| 329 | 326 |
| 330 EGLBoolean result = | 327 EGLBoolean result = |
| 331 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), egl_image); | 328 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), egl_image); |
| 332 if (result == EGL_FALSE) { | 329 if (result == EGL_FALSE) { |
| 333 DLOG(ERROR) << "Error destroying EGLImage: " | 330 DLOG(ERROR) << "Error destroying EGLImage: " |
| 334 << ui::GetLastEGLErrorString(); | 331 << ui::GetLastEGLErrorString(); |
| 335 } | 332 } |
| 336 } | 333 } |
| 337 | 334 |
| 338 } // namespace content | 335 } // namespace content |
| OLD | NEW |