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/android_copying_backing_strategy.h" | 5 #include "media/gpu/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 "gpu/command_buffer/service/context_group.h" | 10 #include "gpu/command_buffer/service/context_group.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy( | 21 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy( |
22 AVDAStateProvider* state_provider) | 22 AVDAStateProvider* state_provider) |
23 : state_provider_(state_provider), | 23 : state_provider_(state_provider), |
24 surface_texture_id_(0), | 24 surface_texture_id_(0), |
25 media_codec_(nullptr) {} | 25 media_codec_(nullptr) {} |
26 | 26 |
27 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {} | 27 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {} |
28 | 28 |
29 gl::ScopedJavaSurface AndroidCopyingBackingStrategy::Initialize( | 29 gl::ScopedJavaSurface AndroidCopyingBackingStrategy::Initialize( |
30 int surface_view_id) { | 30 int surface_view_id) { |
31 if (surface_view_id != media::VideoDecodeAccelerator::Config::kNoSurfaceID) { | 31 if (surface_view_id != VideoDecodeAccelerator::Config::kNoSurfaceID) { |
32 LOG(ERROR) << "The copying strategy should not be initialized with a " | 32 LOG(ERROR) << "The copying strategy should not be initialized with a " |
33 "surface id."; | 33 "surface id."; |
34 return gl::ScopedJavaSurface(); | 34 return gl::ScopedJavaSurface(); |
35 } | 35 } |
36 | 36 |
37 surface_texture_ = | 37 surface_texture_ = |
38 state_provider_->CreateAttachedSurfaceTexture(&surface_texture_id_); | 38 state_provider_->CreateAttachedSurfaceTexture(&surface_texture_id_); |
39 return gl::ScopedJavaSurface(surface_texture_.get()); | 39 return gl::ScopedJavaSurface(surface_texture_.get()); |
40 } | 40 } |
41 | 41 |
(...skipping 17 matching lines...) Expand all Loading... |
59 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const { | 59 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const { |
60 return GL_TEXTURE_2D; | 60 return GL_TEXTURE_2D; |
61 } | 61 } |
62 | 62 |
63 gfx::Size AndroidCopyingBackingStrategy::GetPictureBufferSize() const { | 63 gfx::Size AndroidCopyingBackingStrategy::GetPictureBufferSize() const { |
64 return state_provider_->GetSize(); | 64 return state_provider_->GetSize(); |
65 } | 65 } |
66 | 66 |
67 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer( | 67 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer( |
68 int32_t codec_buf_index, | 68 int32_t codec_buf_index, |
69 const media::PictureBuffer& picture_buffer) { | 69 const PictureBuffer& picture_buffer) { |
70 // Make sure that the decoder is available. | 70 // Make sure that the decoder is available. |
71 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder().get(), | 71 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder().get(), |
72 "Failed to get gles2 decoder instance.", ILLEGAL_STATE); | 72 "Failed to get gles2 decoder instance.", ILLEGAL_STATE); |
73 | 73 |
74 // Render the codec buffer into |surface_texture_|, and switch it to be | 74 // Render the codec buffer into |surface_texture_|, and switch it to be |
75 // the front buffer. | 75 // the front buffer. |
76 // This ignores the emitted ByteBuffer and instead relies on rendering to | 76 // This ignores the emitted ByteBuffer and instead relies on rendering to |
77 // the codec's SurfaceTexture and then copying from that texture to the | 77 // the codec's SurfaceTexture and then copying from that texture to the |
78 // client's PictureBuffer's texture. This means that each picture's data | 78 // client's PictureBuffer's texture. This means that each picture's data |
79 // is written three times: once to the ByteBuffer, once to the | 79 // is written three times: once to the ByteBuffer, once to the |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // attached. | 123 // attached. |
124 // 2. SurfaceTexture requires us to apply a transform matrix when we show | 124 // 2. SurfaceTexture requires us to apply a transform matrix when we show |
125 // the texture. | 125 // the texture. |
126 copier_->DoCopyTextureWithTransform( | 126 copier_->DoCopyTextureWithTransform( |
127 state_provider_->GetGlDecoder().get(), GL_TEXTURE_EXTERNAL_OES, | 127 state_provider_->GetGlDecoder().get(), GL_TEXTURE_EXTERNAL_OES, |
128 surface_texture_id_, GL_TEXTURE_2D, picture_buffer_texture_id, | 128 surface_texture_id_, GL_TEXTURE_2D, picture_buffer_texture_id, |
129 state_provider_->GetSize().width(), state_provider_->GetSize().height(), | 129 state_provider_->GetSize().width(), state_provider_->GetSize().height(), |
130 true, false, false, transform_matrix); | 130 true, false, false, transform_matrix); |
131 } | 131 } |
132 | 132 |
133 void AndroidCopyingBackingStrategy::CodecChanged( | 133 void AndroidCopyingBackingStrategy::CodecChanged(VideoCodecBridge* codec) { |
134 media::VideoCodecBridge* codec) { | |
135 media_codec_ = codec; | 134 media_codec_ = codec; |
136 } | 135 } |
137 | 136 |
138 void AndroidCopyingBackingStrategy::OnFrameAvailable() { | 137 void AndroidCopyingBackingStrategy::OnFrameAvailable() { |
139 // TODO(liberato): crbug.com/574948 . The OnFrameAvailable logic can be | 138 // TODO(liberato): crbug.com/574948 . The OnFrameAvailable logic can be |
140 // moved into AVDA, and we should wait for it before doing the copy. | 139 // moved into AVDA, and we should wait for it before doing the copy. |
141 // Because there were some test failures, we don't do this now but | 140 // Because there were some test failures, we don't do this now but |
142 // instead preserve the old behavior. | 141 // instead preserve the old behavior. |
143 } | 142 } |
144 | 143 |
145 bool AndroidCopyingBackingStrategy::ArePicturesOverlayable() { | 144 bool AndroidCopyingBackingStrategy::ArePicturesOverlayable() { |
146 return false; | 145 return false; |
147 } | 146 } |
148 | 147 |
149 void AndroidCopyingBackingStrategy::UpdatePictureBufferSize( | 148 void AndroidCopyingBackingStrategy::UpdatePictureBufferSize( |
150 media::PictureBuffer* picture_buffer, | 149 PictureBuffer* picture_buffer, |
151 const gfx::Size& new_size) { | 150 const gfx::Size& new_size) { |
152 // This strategy uses 2D textures who's allocated memory is dependent on the | 151 // This strategy uses 2D textures who's allocated memory is dependent on the |
153 // size. To update size in all places, we must: | 152 // size. To update size in all places, we must: |
154 // 1) Update the PictureBuffer meta-data | 153 // 1) Update the PictureBuffer meta-data |
155 picture_buffer->set_size(new_size); | 154 picture_buffer->set_size(new_size); |
156 | 155 |
157 // 2) Update the GL texture via glTexImage2D. This step assumes the caller | 156 // 2) Update the GL texture via glTexImage2D. This step assumes the caller |
158 // has made our GL context current. | 157 // has made our GL context current. |
159 DCHECK_LE(1u, picture_buffer->texture_ids().size()); | 158 DCHECK_LE(1u, picture_buffer->texture_ids().size()); |
160 glBindTexture(GL_TEXTURE_2D, picture_buffer->texture_ids()[0]); | 159 glBindTexture(GL_TEXTURE_2D, picture_buffer->texture_ids()[0]); |
161 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, new_size.width(), new_size.height(), | 160 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, new_size.width(), new_size.height(), |
162 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | 161 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
163 state_provider_->GetGlDecoder()->RestoreActiveTextureUnitBinding( | 162 state_provider_->GetGlDecoder()->RestoreActiveTextureUnitBinding( |
164 GL_TEXTURE_2D); | 163 GL_TEXTURE_2D); |
165 | 164 |
166 // 3) Update the CHROMIUM Texture's size. | 165 // 3) Update the CHROMIUM Texture's size. |
167 gpu::gles2::TextureRef* texture_ref = | 166 gpu::gles2::TextureRef* texture_ref = |
168 state_provider_->GetTextureForPicture(*picture_buffer); | 167 state_provider_->GetTextureForPicture(*picture_buffer); |
169 RETURN_IF_NULL(texture_ref); | 168 RETURN_IF_NULL(texture_ref); |
170 gpu::gles2::TextureManager* texture_manager = | 169 gpu::gles2::TextureManager* texture_manager = |
171 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); | 170 state_provider_->GetGlDecoder()->GetContextGroup()->texture_manager(); |
172 RETURN_IF_NULL(texture_manager); | 171 RETURN_IF_NULL(texture_manager); |
173 texture_manager->SetLevelInfo(texture_ref, GetTextureTarget(), 0, GL_RGBA, | 172 texture_manager->SetLevelInfo(texture_ref, GetTextureTarget(), 0, GL_RGBA, |
174 new_size.width(), new_size.height(), 1, 0, | 173 new_size.width(), new_size.height(), 1, 0, |
175 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(new_size)); | 174 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(new_size)); |
176 } | 175 } |
177 | 176 |
178 } // namespace media | 177 } // namespace media |
OLD | NEW |