Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: media/gpu/avda_codec_image.cc

Issue 1939943002: Increase cases where back/front buffering early rendering occur. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fast_release
Patch Set: Fix front index calculation. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/gpu/avda_codec_image.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_codec_image.h" 5 #include "media/gpu/avda_codec_image.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return true; 118 return true;
119 } 119 }
120 120
121 void AVDACodecImage::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 121 void AVDACodecImage::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
122 uint64_t process_tracing_id, 122 uint64_t process_tracing_id,
123 const std::string& dump_name) {} 123 const std::string& dump_name) {}
124 124
125 void AVDACodecImage::UpdateSurfaceTexture(RestoreBindingsMode mode) { 125 void AVDACodecImage::UpdateSurfaceTexture(RestoreBindingsMode mode) {
126 DCHECK(surface_texture_); 126 DCHECK(surface_texture_);
127 DCHECK_EQ(codec_buffer_index_, kUpdateOnly); 127 DCHECK_EQ(codec_buffer_index_, kUpdateOnly);
128 codec_buffer_index_ = kInvalidCodecBufferIndex; 128 codec_buffer_index_ = kRendered;
129 129
130 // Swap the rendered image to the front. 130 // Swap the rendered image to the front.
131 std::unique_ptr<ui::ScopedMakeCurrent> scoped_make_current = 131 std::unique_ptr<ui::ScopedMakeCurrent> scoped_make_current =
132 MakeCurrentIfNeeded(); 132 MakeCurrentIfNeeded();
133 133
134 // If we changed contexts, then we always want to restore it, since the caller 134 // If we changed contexts, then we always want to restore it, since the caller
135 // doesn't know that we're switching contexts. 135 // doesn't know that we're switching contexts.
136 if (scoped_make_current) 136 if (scoped_make_current)
137 mode = kDoRestoreBindings; 137 mode = kDoRestoreBindings;
138 138
139 // Save the current binding if requested. 139 // Save the current binding if requested.
140 GLint bound_service_id = 0; 140 GLint bound_service_id = 0;
141 if (mode == kDoRestoreBindings) 141 if (mode == kDoRestoreBindings)
142 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); 142 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id);
143 143
144 surface_texture_->UpdateTexImage(); 144 surface_texture_->UpdateTexImage();
145 if (mode == kDoRestoreBindings) 145 if (mode == kDoRestoreBindings)
146 glBindTexture(GL_TEXTURE_EXTERNAL_OES, bound_service_id); 146 glBindTexture(GL_TEXTURE_EXTERNAL_OES, bound_service_id);
147 147
148 // Helpfully, this is already column major. 148 // Helpfully, this is already column major.
149 surface_texture_->GetTransformMatrix(gl_matrix_); 149 surface_texture_->GetTransformMatrix(gl_matrix_);
150 } 150 }
151 151
152 void AVDACodecImage::SetMediaCodecBufferIndex(int buffer_index) {
153 codec_buffer_index_ = buffer_index;
154 }
155
156 void AVDACodecImage::SetSize(const gfx::Size& size) {
157 size_ = size;
158 }
159
160 void AVDACodecImage::UpdateSurface(UpdateMode update_mode) { 152 void AVDACodecImage::UpdateSurface(UpdateMode update_mode) {
161 UpdateSurfaceInternal(update_mode, kDoRestoreBindings); 153 UpdateSurfaceInternal(update_mode, kDoRestoreBindings);
162 } 154 }
163 155
164 void AVDACodecImage::CodecChanged(media::MediaCodecBridge* codec) { 156 void AVDACodecImage::CodecChanged(media::MediaCodecBridge* codec) {
165 media_codec_ = codec; 157 media_codec_ = codec;
166 codec_buffer_index_ = kInvalidCodecBufferIndex; 158 codec_buffer_index_ = kInvalidCodecBufferIndex;
167 } 159 }
168 160
169 void AVDACodecImage::SetTexture(gpu::gles2::Texture* texture) {
170 texture_ = texture;
171 }
172
173 void AVDACodecImage::UpdateSurfaceInternal( 161 void AVDACodecImage::UpdateSurfaceInternal(
174 UpdateMode update_mode, 162 UpdateMode update_mode,
175 RestoreBindingsMode attached_bindings_mode) { 163 RestoreBindingsMode attached_bindings_mode) {
176 if (!IsCodecBufferOutstanding()) 164 if (!IsCodecBufferOutstanding())
177 return; 165 return;
178 166
179 ReleaseOutputBuffer(update_mode); 167 ReleaseOutputBuffer(update_mode);
180 168
181 // SurfaceViews are updated implicitly, so no further steps are necessary. 169 // SurfaceViews are updated implicitly, so no further steps are necessary.
182 if (!surface_texture_) { 170 if (!surface_texture_) {
(...skipping 27 matching lines...) Expand all
210 glBindTexture(GL_TEXTURE_EXTERNAL_OES, bound_service_id); 198 glBindTexture(GL_TEXTURE_EXTERNAL_OES, bound_service_id);
211 } 199 }
212 200
213 void AVDACodecImage::ReleaseOutputBuffer(UpdateMode update_mode) { 201 void AVDACodecImage::ReleaseOutputBuffer(UpdateMode update_mode) {
214 DCHECK(IsCodecBufferOutstanding()); 202 DCHECK(IsCodecBufferOutstanding());
215 203
216 // In case of discard, simply discard and clear our codec buffer index. 204 // In case of discard, simply discard and clear our codec buffer index.
217 if (update_mode == UpdateMode::DISCARD_CODEC_BUFFER) { 205 if (update_mode == UpdateMode::DISCARD_CODEC_BUFFER) {
218 if (codec_buffer_index_ != kUpdateOnly) 206 if (codec_buffer_index_ != kUpdateOnly)
219 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, false); 207 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, false);
208
209 // Note: No need to wait for the frame to be available in the kUpdateOnly
210 // case since it will be or has been waited on by another release call.
220 codec_buffer_index_ = kInvalidCodecBufferIndex; 211 codec_buffer_index_ = kInvalidCodecBufferIndex;
221 return; 212 return;
222 } 213 }
223 214
224 DCHECK(update_mode == UpdateMode::RENDER_TO_BACK_BUFFER || 215 DCHECK(update_mode == UpdateMode::RENDER_TO_BACK_BUFFER ||
225 update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER); 216 update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER);
226 217
227 if (!surface_texture_) { 218 if (!surface_texture_) {
228 DCHECK(update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER); 219 DCHECK(update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER);
229 DCHECK_GE(codec_buffer_index_, 0); 220 DCHECK_GE(codec_buffer_index_, 0);
230 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, true); 221 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, true);
231 codec_buffer_index_ = kInvalidCodecBufferIndex; 222 codec_buffer_index_ = kRendered;
232 return; 223 return;
233 } 224 }
234 225
235 // If we've already released to the back buffer, there's nothing left to do, 226 // If we've already released to the back buffer, there's nothing left to do,
236 // but wait for the previously released buffer if necessary. 227 // but wait for the previously released buffer if necessary.
237 if (codec_buffer_index_ != kUpdateOnly) { 228 if (codec_buffer_index_ != kUpdateOnly) {
238 DCHECK(surface_texture_); 229 DCHECK(surface_texture_);
239 DCHECK_GE(codec_buffer_index_, 0); 230 DCHECK_GE(codec_buffer_index_, 0);
240 shared_state_->RenderCodecBufferToSurfaceTexture(media_codec_, 231 shared_state_->RenderCodecBufferToSurfaceTexture(media_codec_,
241 codec_buffer_index_); 232 codec_buffer_index_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 269 }
279 270
280 void AVDACodecImage::GetTextureMatrix(float matrix[16]) { 271 void AVDACodecImage::GetTextureMatrix(float matrix[16]) {
281 // Our current matrix may be stale. Update it if possible. 272 // Our current matrix may be stale. Update it if possible.
282 if (surface_texture_) 273 if (surface_texture_)
283 UpdateSurface(UpdateMode::RENDER_TO_FRONT_BUFFER); 274 UpdateSurface(UpdateMode::RENDER_TO_FRONT_BUFFER);
284 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); 275 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_));
285 } 276 }
286 277
287 bool AVDACodecImage::IsCodecBufferOutstanding() const { 278 bool AVDACodecImage::IsCodecBufferOutstanding() const {
288 return codec_buffer_index_ != kInvalidCodecBufferIndex && media_codec_; 279 static_assert(kUpdateOnly < 0 && kUpdateOnly > kRendered &&
280 kRendered > kInvalidCodecBufferIndex,
281 "Codec buffer index enum values are not ordered correctly.");
282 return codec_buffer_index_ > kRendered && media_codec_;
289 } 283 }
290 284
291 } // namespace media 285 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/avda_codec_image.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698