| 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_copying_backing_strategy.h" | 5 #include "content/common/gpu/media/android_copying_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/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "content/common/gpu/media/avda_return_on_failure.h" | 10 #include "content/common/gpu/media/avda_return_on_failure.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 void AndroidCopyingBackingStrategy::SetStateProvider( | 36 void AndroidCopyingBackingStrategy::SetStateProvider( |
| 37 AndroidVideoDecodeAcceleratorStateProvider* state_provider) { | 37 AndroidVideoDecodeAcceleratorStateProvider* state_provider) { |
| 38 state_provider_ = state_provider; | 38 state_provider_ = state_provider; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void AndroidCopyingBackingStrategy::Cleanup() { | 41 void AndroidCopyingBackingStrategy::Cleanup() { |
| 42 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread()); | 42 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread()); |
| 43 if (copier_) | 43 if (copier_) |
| 44 copier_->Destroy(); | 44 copier_->Destroy(); |
| 45 |
| 46 if (surface_texture_id_) |
| 47 glDeleteTextures(1, &surface_texture_id_); |
| 45 } | 48 } |
| 46 | 49 |
| 47 uint32 AndroidCopyingBackingStrategy::GetNumPictureBuffers() const { | 50 uint32 AndroidCopyingBackingStrategy::GetNumPictureBuffers() const { |
| 48 return kNumPictureBuffers; | 51 return kNumPictureBuffers; |
| 49 } | 52 } |
| 50 | 53 |
| 51 uint32 AndroidCopyingBackingStrategy::GetTextureTarget() const { | 54 uint32 AndroidCopyingBackingStrategy::GetTextureTarget() const { |
| 52 return GL_TEXTURE_2D; | 55 return GL_TEXTURE_2D; |
| 53 } | 56 } |
| 54 | 57 |
| 55 void AndroidCopyingBackingStrategy::AssignCurrentSurfaceToPictureBuffer( | 58 scoped_refptr<gfx::SurfaceTexture> |
| 59 AndroidCopyingBackingStrategy::CreateSurfaceTexture() { |
| 60 glGenTextures(1, &surface_texture_id_); |
| 61 glActiveTexture(GL_TEXTURE0); |
| 62 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_); |
| 63 |
| 64 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 65 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 66 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 67 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 68 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0); |
| 69 state_provider_->GetGlDecoder()->RestoreActiveTexture(); |
| 70 |
| 71 surface_texture_ = gfx::SurfaceTexture::Create(surface_texture_id_); |
| 72 |
| 73 return surface_texture_; |
| 74 } |
| 75 |
| 76 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer( |
| 56 int32 codec_buf_index, | 77 int32 codec_buf_index, |
| 57 const media::PictureBuffer& picture_buffer) { | 78 const media::PictureBuffer& picture_buffer) { |
| 58 // Make sure that the decoder is available. | 79 // Make sure that the decoder is available. |
| 59 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder(), | 80 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder(), |
| 60 "Failed to get gles2 decoder instance.", ILLEGAL_STATE); | 81 "Failed to get gles2 decoder instance.", ILLEGAL_STATE); |
| 61 | 82 |
| 62 // Render the codec buffer into |surface_texture_|, and switch it to be | 83 // Render the codec buffer into |surface_texture_|, and switch it to be |
| 63 // the front buffer. | 84 // the front buffer. |
| 64 // This ignores the emitted ByteBuffer and instead relies on rendering to | 85 // This ignores the emitted ByteBuffer and instead relies on rendering to |
| 65 // the codec's SurfaceTexture and then copying from that texture to the | 86 // the codec's SurfaceTexture and then copying from that texture to the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 // 2) The ByteBuffer is likely to contain the pixels in a vendor-specific, | 97 // 2) The ByteBuffer is likely to contain the pixels in a vendor-specific, |
| 77 // opaque/non-standard format. It's not possible to negotiate the | 98 // opaque/non-standard format. It's not possible to negotiate the |
| 78 // decoder to emit a specific colorspace, even using HW CSC. b/10706245 | 99 // decoder to emit a specific colorspace, even using HW CSC. b/10706245 |
| 79 // So, we live with these two extra copies per picture :( | 100 // So, we live with these two extra copies per picture :( |
| 80 { | 101 { |
| 81 TRACE_EVENT0("media", "AVDA::ReleaseOutputBuffer"); | 102 TRACE_EVENT0("media", "AVDA::ReleaseOutputBuffer"); |
| 82 state_provider_->GetMediaCodec()->ReleaseOutputBuffer(codec_buf_index, | 103 state_provider_->GetMediaCodec()->ReleaseOutputBuffer(codec_buf_index, |
| 83 true); | 104 true); |
| 84 } | 105 } |
| 85 | 106 |
| 86 gfx::SurfaceTexture* surface_texture = state_provider_->GetSurfaceTexture(); | |
| 87 { | 107 { |
| 88 TRACE_EVENT0("media", "AVDA::UpdateTexImage"); | 108 TRACE_EVENT0("media", "AVDA::UpdateTexImage"); |
| 89 surface_texture->UpdateTexImage(); | 109 surface_texture_->UpdateTexImage(); |
| 90 } | 110 } |
| 91 | 111 |
| 92 float transfrom_matrix[16]; | 112 float transfrom_matrix[16]; |
| 93 surface_texture->GetTransformMatrix(transfrom_matrix); | 113 surface_texture_->GetTransformMatrix(transfrom_matrix); |
| 94 | 114 |
| 95 uint32 picture_buffer_texture_id = picture_buffer.texture_id(); | 115 uint32 picture_buffer_texture_id = picture_buffer.texture_id(); |
| 96 | 116 |
| 97 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is | 117 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 98 // needed because it takes 10s of milliseconds to initialize. | 118 // needed because it takes 10s of milliseconds to initialize. |
| 99 if (!copier_) { | 119 if (!copier_) { |
| 100 copier_.reset(new gpu::CopyTextureCHROMIUMResourceManager()); | 120 copier_.reset(new gpu::CopyTextureCHROMIUMResourceManager()); |
| 101 copier_->Initialize(state_provider_->GetGlDecoder()); | 121 copier_->Initialize(state_provider_->GetGlDecoder()); |
| 102 } | 122 } |
| 103 | 123 |
| 104 // Here, we copy |surface_texture_id_| to the picture buffer instead of | 124 // Here, we copy |surface_texture_id_| to the picture buffer instead of |
| 105 // setting new texture to |surface_texture_| by calling attachToGLContext() | 125 // setting new texture to |surface_texture_| by calling attachToGLContext() |
| 106 // because: | 126 // because: |
| 107 // 1. Once we call detachFrameGLContext(), it deletes the texture previous | 127 // 1. Once we call detachFrameGLContext(), it deletes the texture previous |
| 108 // attached. | 128 // attached. |
| 109 // 2. SurfaceTexture requires us to apply a transform matrix when we show | 129 // 2. SurfaceTexture requires us to apply a transform matrix when we show |
| 110 // the texture. | 130 // the texture. |
| 111 // TODO(hkuang): get the StreamTexture transform matrix in GPU process | 131 // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
| 112 // instead of using default matrix crbug.com/226218. | 132 // instead of using default matrix crbug.com/226218. |
| 113 copier_->DoCopyTextureWithTransform( | 133 copier_->DoCopyTextureWithTransform( |
| 114 state_provider_->GetGlDecoder(), GL_TEXTURE_EXTERNAL_OES, | 134 state_provider_->GetGlDecoder(), GL_TEXTURE_EXTERNAL_OES, |
| 115 state_provider_->GetSurfaceTextureId(), picture_buffer_texture_id, | 135 surface_texture_id_, picture_buffer_texture_id, |
| 116 state_provider_->GetSize().width(), state_provider_->GetSize().height(), | 136 state_provider_->GetSize().width(), state_provider_->GetSize().height(), |
| 117 false, false, false, kIdentityMatrix); | 137 false, false, false, kIdentityMatrix); |
| 118 } | 138 } |
| 119 | 139 |
| 120 } // namespace content | 140 } // namespace content |
| OLD | NEW |