| 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 "media/gpu/avda_picture_buffer_manager.h" | 5 #include "media/gpu/avda_picture_buffer_manager.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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "gpu/command_buffer/service/context_group.h" | 15 #include "gpu/command_buffer/service/context_group.h" |
| 16 #include "gpu/command_buffer/service/gl_stream_texture_image.h" | 16 #include "gpu/command_buffer/service/gl_stream_texture_image.h" |
| 17 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 17 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
| 18 #include "gpu/command_buffer/service/texture_manager.h" | 18 #include "gpu/command_buffer/service/texture_manager.h" |
| 19 #include "gpu/ipc/common/gpu_surface_lookup.h" | |
| 20 #include "gpu/ipc/service/gpu_channel.h" | 19 #include "gpu/ipc/service/gpu_channel.h" |
| 21 #include "media/base/android/media_codec_bridge_impl.h" | 20 #include "media/base/android/media_codec_bridge_impl.h" |
| 22 #include "media/gpu/avda_codec_image.h" | 21 #include "media/gpu/avda_codec_image.h" |
| 23 #include "media/gpu/avda_shared_state.h" | 22 #include "media/gpu/avda_shared_state.h" |
| 23 #include "ui/gl/android/scoped_java_surface.h" |
| 24 #include "ui/gl/android/surface_texture.h" | 24 #include "ui/gl/android/surface_texture.h" |
| 25 #include "ui/gl/egl_util.h" | 25 #include "ui/gl/egl_util.h" |
| 26 #include "ui/gl/gl_bindings.h" | 26 #include "ui/gl/gl_bindings.h" |
| 27 #include "ui/gl/gl_surface_egl.h" | 27 #include "ui/gl/gl_surface_egl.h" |
| 28 #include "ui/gl/scoped_binders.h" | 28 #include "ui/gl/scoped_binders.h" |
| 29 #include "ui/gl/scoped_make_current.h" | 29 #include "ui/gl/scoped_make_current.h" |
| 30 | 30 |
| 31 // If !|ptr|, log a message, notify |state_provider_| of the error, and | 31 // If !|ptr|, log a message, notify |state_provider_| of the error, and |
| 32 // return an optional value. | 32 // return an optional value. |
| 33 #define RETURN_IF_NULL(ptr, ...) \ | 33 #define RETURN_IF_NULL(ptr, ...) \ |
| 34 do { \ | 34 do { \ |
| 35 if (!(ptr)) { \ | 35 if (!(ptr)) { \ |
| 36 DLOG(ERROR) << "Got null for " << #ptr; \ | 36 DLOG(ERROR) << "Got null for " << #ptr; \ |
| 37 state_provider_->NotifyError(VideoDecodeAccelerator::ILLEGAL_STATE); \ | 37 state_provider_->NotifyError(VideoDecodeAccelerator::ILLEGAL_STATE); \ |
| 38 return __VA_ARGS__; \ | 38 return __VA_ARGS__; \ |
| 39 } \ | 39 } \ |
| 40 } while (0) | 40 } while (0) |
| 41 | 41 |
| 42 namespace media { | 42 namespace media { |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 // Creates a SurfaceTexture and attaches a new gl texture to it. | 45 // Creates a SurfaceTexture and attaches a new gl texture to it. |
| 46 scoped_refptr<SurfaceTextureGLOwner> CreateAttachedSurfaceTexture( | 46 scoped_refptr<SurfaceTextureGLOwner> CreateAttachedSurfaceTexture( |
| 47 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder) { | 47 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder) { |
| 48 scoped_refptr<SurfaceTextureGLOwner> surface_texture = | 48 scoped_refptr<SurfaceTextureGLOwner> surface_texture = |
| 49 SurfaceTextureGLOwner::Create(); | 49 SurfaceTextureGLOwner::Create(); |
| 50 DCHECK(surface_texture); | 50 if (!surface_texture) |
| 51 return nullptr; |
| 51 | 52 |
| 52 glActiveTexture(GL_TEXTURE0); | 53 glActiveTexture(GL_TEXTURE0); |
| 53 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture->texture_id()); | 54 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture->texture_id()); |
| 54 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 55 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 55 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 56 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 56 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 57 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 57 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 58 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 58 | 59 |
| 59 gl_decoder->RestoreTextureUnitBindings(0); | 60 gl_decoder->RestoreTextureUnitBindings(0); |
| 60 gl_decoder->RestoreActiveTexture(); | 61 gl_decoder->RestoreActiveTexture(); |
| 61 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 62 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 62 | 63 |
| 63 return surface_texture; | 64 return surface_texture; |
| 64 } | 65 } |
| 65 | 66 |
| 66 } // namespace | 67 } // namespace |
| 67 | 68 |
| 68 AVDAPictureBufferManager::AVDAPictureBufferManager( | 69 AVDAPictureBufferManager::AVDAPictureBufferManager( |
| 69 AVDAStateProvider* state_provider) | 70 AVDAStateProvider* state_provider) |
| 70 : state_provider_(state_provider), media_codec_(nullptr) {} | 71 : state_provider_(state_provider), media_codec_(nullptr) {} |
| 71 | 72 |
| 72 AVDAPictureBufferManager::~AVDAPictureBufferManager() {} | 73 AVDAPictureBufferManager::~AVDAPictureBufferManager() {} |
| 73 | 74 |
| 74 gl::ScopedJavaSurface AVDAPictureBufferManager::Initialize(int surface_id) { | 75 void AVDAPictureBufferManager::InitializeForOverlay() { |
| 76 shared_state_ = new AVDASharedState(); |
| 77 surface_texture_ = nullptr; |
| 78 } |
| 79 |
| 80 gl::ScopedJavaSurface AVDAPictureBufferManager::InitializeForSurfaceTexture() { |
| 75 shared_state_ = new AVDASharedState(); | 81 shared_state_ = new AVDASharedState(); |
| 76 surface_texture_ = nullptr; | 82 surface_texture_ = nullptr; |
| 77 | 83 |
| 78 // Acquire the SurfaceView surface if given a valid id. | 84 // Create a SurfaceTexture. |
| 79 if (surface_id != SurfaceManager::kNoSurfaceID) | |
| 80 return gpu::GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(surface_id); | |
| 81 | |
| 82 // Otherwise create a SurfaceTexture. | |
| 83 surface_texture_ = | 85 surface_texture_ = |
| 84 CreateAttachedSurfaceTexture(state_provider_->GetGlDecoder()); | 86 CreateAttachedSurfaceTexture(state_provider_->GetGlDecoder()); |
| 87 if (!surface_texture_) |
| 88 return gl::ScopedJavaSurface(); |
| 89 |
| 85 shared_state_->SetSurfaceTexture(surface_texture_); | 90 shared_state_->SetSurfaceTexture(surface_texture_); |
| 86 return gl::ScopedJavaSurface(surface_texture_.get()); | 91 return gl::ScopedJavaSurface(surface_texture_.get()); |
| 87 } | 92 } |
| 88 | 93 |
| 89 void AVDAPictureBufferManager::Destroy(const PictureBufferMap& buffers) { | 94 void AVDAPictureBufferManager::Destroy(const PictureBufferMap& buffers) { |
| 90 // Do nothing if Initialize() has not been called. | 95 // Do nothing if Initialize() has not been called. |
| 91 if (!shared_state_) | 96 if (!shared_state_) |
| 92 return; | 97 return; |
| 93 | 98 |
| 94 ReleaseCodecBuffers(buffers); | 99 ReleaseCodecBuffers(buffers); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 280 |
| 276 bool AVDAPictureBufferManager::HasUnrenderedPictures() const { | 281 bool AVDAPictureBufferManager::HasUnrenderedPictures() const { |
| 277 for (int id : pictures_out_for_display_) { | 282 for (int id : pictures_out_for_display_) { |
| 278 if (GetImageForPicture(id)->is_unrendered()) | 283 if (GetImageForPicture(id)->is_unrendered()) |
| 279 return true; | 284 return true; |
| 280 } | 285 } |
| 281 return false; | 286 return false; |
| 282 } | 287 } |
| 283 | 288 |
| 284 } // namespace media | 289 } // namespace media |
| OLD | NEW |