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

Side by Side Diff: gpu/command_buffer/service/stream_texture_manager_in_process_android.cc

Issue 1844843002: android: Remove in-process video path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove commented out code + rebase again Created 4 years, 8 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h "
6
7 #include <stdint.h>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "gpu/command_buffer/service/texture_manager.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/gl/android/surface_texture.h"
15 #include "ui/gl/gl_bindings.h"
16 #include "ui/gl/gl_image.h"
17
18 namespace gpu {
19
20 namespace {
21
22 // Simply wraps a SurfaceTexture reference as a GLImage.
23 class GLImageImpl : public gl::GLImage {
24 public:
25 GLImageImpl(uint32_t texture_id,
26 gles2::TextureManager* texture_manager,
27 const scoped_refptr<gfx::SurfaceTexture>& surface_texture,
28 const base::Closure& release_callback);
29
30 // implement gl::GLImage
31 void Destroy(bool have_context) override;
32 gfx::Size GetSize() override;
33 unsigned GetInternalFormat() override;
34 bool BindTexImage(unsigned target) override;
35 void ReleaseTexImage(unsigned target) override;
36 bool CopyTexImage(unsigned target) override;
37 bool CopyTexSubImage(unsigned target,
38 const gfx::Point& offset,
39 const gfx::Rect& rect) override;
40 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
41 int z_order,
42 gfx::OverlayTransform transform,
43 const gfx::Rect& bounds_rect,
44 const gfx::RectF& crop_rect) override;
45 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
46 uint64_t process_tracing_id,
47 const std::string& dump_name) override;
48
49 private:
50 ~GLImageImpl() override;
51
52 uint32_t texture_id_;
53 gles2::TextureManager* texture_manager_;
54 scoped_refptr<gfx::SurfaceTexture> surface_texture_;
55 base::Closure release_callback_;
56
57 DISALLOW_COPY_AND_ASSIGN(GLImageImpl);
58 };
59
60 GLImageImpl::GLImageImpl(
61 uint32_t texture_id,
62 gles2::TextureManager* texture_manager,
63 const scoped_refptr<gfx::SurfaceTexture>& surface_texture,
64 const base::Closure& release_callback)
65 : texture_id_(texture_id),
66 texture_manager_(texture_manager),
67 surface_texture_(surface_texture),
68 release_callback_(release_callback) {}
69
70 GLImageImpl::~GLImageImpl() {
71 release_callback_.Run();
72 }
73
74 void GLImageImpl::Destroy(bool have_context) {
75 NOTREACHED();
76 }
77
78 gfx::Size GLImageImpl::GetSize() {
79 return gfx::Size();
80 }
81
82 unsigned GLImageImpl::GetInternalFormat() {
83 return GL_RGBA;
84 }
85
86 bool GLImageImpl::BindTexImage(unsigned target) {
87 NOTREACHED();
88 return false;
89 }
90
91 void GLImageImpl::ReleaseTexImage(unsigned target) {
92 NOTREACHED();
93 }
94
95 bool GLImageImpl::CopyTexImage(unsigned target) {
96 if (target != GL_TEXTURE_EXTERNAL_OES)
97 return false;
98
99 GLint texture_id;
100 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
101 DCHECK(texture_id);
102
103 // The following code only works if we're being asked to copy into
104 // |texture_id_|. Copying into a different texture is not supported.
105 if (static_cast<unsigned>(texture_id) != texture_id_)
106 return false;
107
108 surface_texture_->UpdateTexImage();
109
110 gles2::Texture* texture =
111 texture_manager_->GetTextureForServiceId(texture_id_);
112 if (texture) {
113 // By setting image state to UNBOUND instead of COPIED we ensure that
114 // CopyTexImage() is called each time the surface texture is used for
115 // drawing.
116 texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this,
117 gles2::Texture::UNBOUND);
118 }
119 return true;
120 }
121
122 bool GLImageImpl::CopyTexSubImage(unsigned target,
123 const gfx::Point& offset,
124 const gfx::Rect& rect) {
125 return false;
126 }
127
128 bool GLImageImpl::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
129 int z_order,
130 gfx::OverlayTransform transform,
131 const gfx::Rect& bounds_rect,
132 const gfx::RectF& crop_rect) {
133 NOTREACHED();
134 return false;
135 }
136
137 void GLImageImpl::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
138 uint64_t process_tracing_id,
139 const std::string& dump_name) {
140 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914
141 }
142
143 } // anonymous namespace
144
145 StreamTextureManagerInProcess::StreamTextureManagerInProcess()
146 : next_id_(1), weak_factory_(this) {}
147
148 StreamTextureManagerInProcess::~StreamTextureManagerInProcess() {
149 if (!textures_.empty()) {
150 LOG(WARNING) << "Undestroyed surface textures while tearing down "
151 "StreamTextureManager.";
152 }
153 }
154
155 GLuint StreamTextureManagerInProcess::CreateStreamTexture(
156 uint32_t client_texture_id,
157 gles2::TextureManager* texture_manager) {
158 CalledOnValidThread();
159
160 gles2::TextureRef* texture = texture_manager->GetTexture(client_texture_id);
161
162 if (!texture || (texture->texture()->target() &&
163 texture->texture()->target() != GL_TEXTURE_EXTERNAL_OES)) {
164 return 0;
165 }
166
167 scoped_refptr<gfx::SurfaceTexture> surface_texture(
168 gfx::SurfaceTexture::Create(texture->service_id()));
169
170 uint32_t stream_id = next_id_++;
171 base::Closure release_callback =
172 base::Bind(&StreamTextureManagerInProcess::OnReleaseStreamTexture,
173 weak_factory_.GetWeakPtr(), stream_id);
174 scoped_refptr<gl::GLImage> gl_image(
175 new GLImageImpl(texture->service_id(), texture_manager, surface_texture,
176 release_callback));
177
178 gfx::Size size = gl_image->GetSize();
179 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES);
180 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA,
181 size.width(), size.height(), 1, 0, GL_RGBA,
182 GL_UNSIGNED_BYTE, gfx::Rect(size));
183 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0,
184 gl_image.get(), gles2::Texture::UNBOUND);
185
186 {
187 base::AutoLock lock(map_lock_);
188 textures_[stream_id] = surface_texture;
189 }
190
191 if (next_id_ == 0)
192 next_id_++;
193
194 return stream_id;
195 }
196
197 void StreamTextureManagerInProcess::OnReleaseStreamTexture(uint32_t stream_id) {
198 CalledOnValidThread();
199 base::AutoLock lock(map_lock_);
200 textures_.erase(stream_id);
201 }
202
203 // This can get called from any thread.
204 scoped_refptr<gfx::SurfaceTexture>
205 StreamTextureManagerInProcess::GetSurfaceTexture(uint32_t stream_id) {
206 base::AutoLock lock(map_lock_);
207 TextureMap::const_iterator it = textures_.find(stream_id);
208 if (it != textures_.end())
209 return it->second;
210
211 return NULL;
212 }
213
214 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/stream_texture_manager_in_process_android.h ('k') | gpu/command_buffer_service.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698