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

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

Issue 2005103004: AVDACodecImages keep their backing SurfaceTexture alive (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@neverdetach
Patch Set: Minor fixes Created 4 years, 6 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
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
11 #include "gpu/command_buffer/service/context_group.h"
12 #include "gpu/command_buffer/service/context_state.h"
13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
14 #include "gpu/command_buffer/service/texture_manager.h" 12 #include "gpu/command_buffer/service/texture_manager.h"
13 #include "media/base/android/sdk_media_codec_bridge.h"
15 #include "media/gpu/avda_shared_state.h" 14 #include "media/gpu/avda_shared_state.h"
16 #include "ui/gl/android/surface_texture.h" 15 #include "ui/gl/android/surface_texture.h"
17 #include "ui/gl/gl_context.h" 16 #include "ui/gl/gl_context.h"
18 #include "ui/gl/scoped_make_current.h" 17 #include "ui/gl/scoped_make_current.h"
19 18
20 namespace media { 19 namespace media {
21 20
22 AVDACodecImage::AVDACodecImage( 21 AVDACodecImage::AVDACodecImage(
23 int picture_buffer_id, 22 int picture_buffer_id,
24 const scoped_refptr<AVDASharedState>& shared_state, 23 const scoped_refptr<AVDASharedState>& shared_state,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 61
63 bool AVDACodecImage::CopyTexImage(unsigned target) { 62 bool AVDACodecImage::CopyTexImage(unsigned target) {
64 if (!surface_texture_) 63 if (!surface_texture_)
65 return false; 64 return false;
66 65
67 if (target != GL_TEXTURE_EXTERNAL_OES) 66 if (target != GL_TEXTURE_EXTERNAL_OES)
68 return false; 67 return false;
69 68
70 GLint bound_service_id = 0; 69 GLint bound_service_id = 0;
71 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); 70 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id);
72 // We insist that the currently bound texture is the right one. We could 71 // We insist that the currently bound texture is the right one.
73 // make a new glimage from a 2D image. 72 if (bound_service_id !=
74 if (bound_service_id != shared_state_->surface_texture_service_id()) 73 static_cast<GLint>(shared_state_->surface_texture_service_id())) {
75 return false; 74 return false;
75 }
76 76
77 // Make sure that we have the right image in the front buffer. Note that the 77 // Make sure that we have the right image in the front buffer. Note that the
78 // bound_service_id is guaranteed to be equal to the surface texture's client 78 // bound_service_id is guaranteed to be equal to the surface texture's client
79 // texture id, so we can skip preserving it if the right context is current. 79 // texture id, so we can skip preserving it if the right context is current.
80 UpdateSurfaceInternal(UpdateMode::RENDER_TO_FRONT_BUFFER, 80 UpdateSurfaceInternal(UpdateMode::RENDER_TO_FRONT_BUFFER,
81 kDontRestoreBindings); 81 kDontRestoreBindings);
82 82
83 // By setting image state to UNBOUND instead of COPIED we ensure that 83 // By setting image state to UNBOUND instead of COPIED we ensure that
84 // CopyTexImage() is called each time the surface texture is used for drawing. 84 // CopyTexImage() is called each time the surface texture is used for drawing.
85 // It would be nice if we could do this via asking for the currently bound 85 // It would be nice if we could do this via asking for the currently bound
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // SurfaceViews are updated implicitly, so no further steps are necessary. 163 // SurfaceViews are updated implicitly, so no further steps are necessary.
164 if (!surface_texture_) { 164 if (!surface_texture_) {
165 DCHECK(update_mode != UpdateMode::RENDER_TO_BACK_BUFFER); 165 DCHECK(update_mode != UpdateMode::RENDER_TO_BACK_BUFFER);
166 return; 166 return;
167 } 167 }
168 168
169 // If front buffer rendering hasn't been requested, exit early. 169 // If front buffer rendering hasn't been requested, exit early.
170 if (update_mode != UpdateMode::RENDER_TO_FRONT_BUFFER) 170 if (update_mode != UpdateMode::RENDER_TO_FRONT_BUFFER)
171 return; 171 return;
172 172
173 DCHECK(shared_state_->surface_texture_is_attached());
174 UpdateSurfaceTexture(attached_bindings_mode); 173 UpdateSurfaceTexture(attached_bindings_mode);
175 } 174 }
176 175
177 void AVDACodecImage::ReleaseOutputBuffer(UpdateMode update_mode) { 176 void AVDACodecImage::ReleaseOutputBuffer(UpdateMode update_mode) {
178 DCHECK(IsCodecBufferOutstanding()); 177 DCHECK(IsCodecBufferOutstanding());
179 178
180 // In case of discard, simply discard and clear our codec buffer index. 179 // In case of discard, simply discard and clear our codec buffer index.
181 if (update_mode == UpdateMode::DISCARD_CODEC_BUFFER) { 180 if (update_mode == UpdateMode::DISCARD_CODEC_BUFFER) {
182 if (codec_buffer_index_ != kUpdateOnly) 181 if (codec_buffer_index_ != kUpdateOnly)
183 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, false); 182 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, false);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 234 }
236 235
237 bool AVDACodecImage::IsCodecBufferOutstanding() const { 236 bool AVDACodecImage::IsCodecBufferOutstanding() const {
238 static_assert(kUpdateOnly < 0 && kUpdateOnly > kRendered && 237 static_assert(kUpdateOnly < 0 && kUpdateOnly > kRendered &&
239 kRendered > kInvalidCodecBufferIndex, 238 kRendered > kInvalidCodecBufferIndex,
240 "Codec buffer index enum values are not ordered correctly."); 239 "Codec buffer index enum values are not ordered correctly.");
241 return codec_buffer_index_ > kRendered && media_codec_; 240 return codec_buffer_index_ > kRendered && media_codec_;
242 } 241 }
243 242
244 } // namespace media 243 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698