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

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

Issue 2706653002: Added SurfaceTextureGLOwner to create / own GL objects. (Closed)
Patch Set: stopped including gl_initializer.h Created 3 years, 9 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_picture_buffer_manager.h ('k') | media/gpu/avda_shared_state.h » ('j') | 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_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"
(...skipping 24 matching lines...) Expand all
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. |*service_id| 45 // Creates a SurfaceTexture and attaches a new gl texture to it.
46 // is set to the new texture id. 46 scoped_refptr<SurfaceTextureGLOwner> CreateAttachedSurfaceTexture(
47 scoped_refptr<gl::SurfaceTexture> CreateAttachedSurfaceTexture( 47 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder) {
48 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder, 48 scoped_refptr<SurfaceTextureGLOwner> surface_texture =
49 GLuint* service_id) { 49 SurfaceTextureGLOwner::Create();
50 GLuint texture_id; 50 DCHECK(surface_texture);
51 glGenTextures(1, &texture_id);
52 51
53 glActiveTexture(GL_TEXTURE0); 52 glActiveTexture(GL_TEXTURE0);
54 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id); 53 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture->texture_id());
55 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 54 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
56 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 55 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
57 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 56 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
58 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 57 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
59 58
60 gl_decoder->RestoreTextureUnitBindings(0); 59 gl_decoder->RestoreTextureUnitBindings(0);
61 gl_decoder->RestoreActiveTexture(); 60 gl_decoder->RestoreActiveTexture();
62 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 61 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
63 62
64 *service_id = texture_id; 63 return surface_texture;
65 // Previously, to reduce context switching, we used to create an unattached
66 // SurfaceTexture and attach it lazily in the compositor's context. But that
67 // was flaky because SurfaceTexture#detachFromGLContext() is buggy on a lot of
68 // devices. Now we attach it to the current context, which means we might have
69 // to context switch later to call updateTexImage(). Fortunately, if virtual
70 // contexts are in use, we won't have to context switch.
71 return gl::SurfaceTexture::Create(texture_id);
72 } 64 }
73 65
74 } // namespace 66 } // namespace
75 67
76 AVDAPictureBufferManager::AVDAPictureBufferManager( 68 AVDAPictureBufferManager::AVDAPictureBufferManager(
77 AVDAStateProvider* state_provider) 69 AVDAStateProvider* state_provider)
78 : state_provider_(state_provider), media_codec_(nullptr) {} 70 : state_provider_(state_provider), media_codec_(nullptr) {}
79 71
80 AVDAPictureBufferManager::~AVDAPictureBufferManager() {} 72 AVDAPictureBufferManager::~AVDAPictureBufferManager() {}
81 73
82 gl::ScopedJavaSurface AVDAPictureBufferManager::Initialize(int surface_id) { 74 gl::ScopedJavaSurface AVDAPictureBufferManager::Initialize(int surface_id) {
83 shared_state_ = new AVDASharedState(); 75 shared_state_ = new AVDASharedState();
84 surface_texture_ = nullptr; 76 surface_texture_ = nullptr;
85 77
86 // Acquire the SurfaceView surface if given a valid id. 78 // Acquire the SurfaceView surface if given a valid id.
87 if (surface_id != SurfaceManager::kNoSurfaceID) 79 if (surface_id != SurfaceManager::kNoSurfaceID)
88 return gpu::GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(surface_id); 80 return gpu::GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(surface_id);
89 81
90 // Otherwise create a SurfaceTexture. 82 // Otherwise create a SurfaceTexture.
91 GLuint service_id; 83 surface_texture_ =
92 surface_texture_ = CreateAttachedSurfaceTexture( 84 CreateAttachedSurfaceTexture(state_provider_->GetGlDecoder());
93 state_provider_->GetGlDecoder(), &service_id); 85 shared_state_->SetSurfaceTexture(surface_texture_);
94 shared_state_->SetSurfaceTexture(surface_texture_, service_id);
95 return gl::ScopedJavaSurface(surface_texture_.get()); 86 return gl::ScopedJavaSurface(surface_texture_.get());
96 } 87 }
97 88
98 void AVDAPictureBufferManager::Destroy(const PictureBufferMap& buffers) { 89 void AVDAPictureBufferManager::Destroy(const PictureBufferMap& buffers) {
99 // Do nothing if Initialize() has not been called. 90 // Do nothing if Initialize() has not been called.
100 if (!shared_state_) 91 if (!shared_state_)
101 return; 92 return;
102 93
103 ReleaseCodecBuffers(buffers); 94 ReleaseCodecBuffers(buffers);
104 CodecChanged(nullptr); 95 CodecChanged(nullptr);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 275
285 bool AVDAPictureBufferManager::HasUnrenderedPictures() const { 276 bool AVDAPictureBufferManager::HasUnrenderedPictures() const {
286 for (int id : pictures_out_for_display_) { 277 for (int id : pictures_out_for_display_) {
287 if (GetImageForPicture(id)->is_unrendered()) 278 if (GetImageForPicture(id)->is_unrendered())
288 return true; 279 return true;
289 } 280 }
290 return false; 281 return false;
291 } 282 }
292 283
293 } // namespace media 284 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/avda_picture_buffer_manager.h ('k') | media/gpu/avda_shared_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698