OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "gpu/command_buffer/service/stream_texture_manager_in_process_android.h
" | 5 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h
" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
9 #include "gpu/command_buffer/service/texture_manager.h" | 12 #include "gpu/command_buffer/service/texture_manager.h" |
10 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
11 #include "ui/gl/android/surface_texture.h" | 14 #include "ui/gl/android/surface_texture.h" |
12 #include "ui/gl/gl_bindings.h" | 15 #include "ui/gl/gl_bindings.h" |
13 #include "ui/gl/gl_image.h" | 16 #include "ui/gl/gl_image.h" |
14 | 17 |
15 namespace gpu { | 18 namespace gpu { |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 // Simply wraps a SurfaceTexture reference as a GLImage. | 22 // Simply wraps a SurfaceTexture reference as a GLImage. |
20 class GLImageImpl : public gl::GLImage { | 23 class GLImageImpl : public gl::GLImage { |
21 public: | 24 public: |
22 GLImageImpl(uint32 texture_id, | 25 GLImageImpl(uint32_t texture_id, |
23 gles2::TextureManager* texture_manager, | 26 gles2::TextureManager* texture_manager, |
24 const scoped_refptr<gfx::SurfaceTexture>& surface_texture, | 27 const scoped_refptr<gfx::SurfaceTexture>& surface_texture, |
25 const base::Closure& release_callback); | 28 const base::Closure& release_callback); |
26 | 29 |
27 // implement gl::GLImage | 30 // implement gl::GLImage |
28 void Destroy(bool have_context) override; | 31 void Destroy(bool have_context) override; |
29 gfx::Size GetSize() override; | 32 gfx::Size GetSize() override; |
30 unsigned GetInternalFormat() override; | 33 unsigned GetInternalFormat() override; |
31 bool BindTexImage(unsigned target) override; | 34 bool BindTexImage(unsigned target) override; |
32 void ReleaseTexImage(unsigned target) override; | 35 void ReleaseTexImage(unsigned target) override; |
33 bool CopyTexImage(unsigned target) override; | 36 bool CopyTexImage(unsigned target) override; |
34 bool CopyTexSubImage(unsigned target, | 37 bool CopyTexSubImage(unsigned target, |
35 const gfx::Point& offset, | 38 const gfx::Point& offset, |
36 const gfx::Rect& rect) override; | 39 const gfx::Rect& rect) override; |
37 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 40 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
38 int z_order, | 41 int z_order, |
39 gfx::OverlayTransform transform, | 42 gfx::OverlayTransform transform, |
40 const gfx::Rect& bounds_rect, | 43 const gfx::Rect& bounds_rect, |
41 const gfx::RectF& crop_rect) override; | 44 const gfx::RectF& crop_rect) override; |
42 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 45 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
43 uint64_t process_tracing_id, | 46 uint64_t process_tracing_id, |
44 const std::string& dump_name) override; | 47 const std::string& dump_name) override; |
45 | 48 |
46 private: | 49 private: |
47 ~GLImageImpl() override; | 50 ~GLImageImpl() override; |
48 | 51 |
49 uint32 texture_id_; | 52 uint32_t texture_id_; |
50 gles2::TextureManager* texture_manager_; | 53 gles2::TextureManager* texture_manager_; |
51 scoped_refptr<gfx::SurfaceTexture> surface_texture_; | 54 scoped_refptr<gfx::SurfaceTexture> surface_texture_; |
52 base::Closure release_callback_; | 55 base::Closure release_callback_; |
53 | 56 |
54 DISALLOW_COPY_AND_ASSIGN(GLImageImpl); | 57 DISALLOW_COPY_AND_ASSIGN(GLImageImpl); |
55 }; | 58 }; |
56 | 59 |
57 GLImageImpl::GLImageImpl( | 60 GLImageImpl::GLImageImpl( |
58 uint32 texture_id, | 61 uint32_t texture_id, |
59 gles2::TextureManager* texture_manager, | 62 gles2::TextureManager* texture_manager, |
60 const scoped_refptr<gfx::SurfaceTexture>& surface_texture, | 63 const scoped_refptr<gfx::SurfaceTexture>& surface_texture, |
61 const base::Closure& release_callback) | 64 const base::Closure& release_callback) |
62 : texture_id_(texture_id), | 65 : texture_id_(texture_id), |
63 texture_manager_(texture_manager), | 66 texture_manager_(texture_manager), |
64 surface_texture_(surface_texture), | 67 surface_texture_(surface_texture), |
65 release_callback_(release_callback) {} | 68 release_callback_(release_callback) {} |
66 | 69 |
67 GLImageImpl::~GLImageImpl() { | 70 GLImageImpl::~GLImageImpl() { |
68 release_callback_.Run(); | 71 release_callback_.Run(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 : next_id_(1), weak_factory_(this) {} | 146 : next_id_(1), weak_factory_(this) {} |
144 | 147 |
145 StreamTextureManagerInProcess::~StreamTextureManagerInProcess() { | 148 StreamTextureManagerInProcess::~StreamTextureManagerInProcess() { |
146 if (!textures_.empty()) { | 149 if (!textures_.empty()) { |
147 LOG(WARNING) << "Undestroyed surface textures while tearing down " | 150 LOG(WARNING) << "Undestroyed surface textures while tearing down " |
148 "StreamTextureManager."; | 151 "StreamTextureManager."; |
149 } | 152 } |
150 } | 153 } |
151 | 154 |
152 GLuint StreamTextureManagerInProcess::CreateStreamTexture( | 155 GLuint StreamTextureManagerInProcess::CreateStreamTexture( |
153 uint32 client_texture_id, | 156 uint32_t client_texture_id, |
154 gles2::TextureManager* texture_manager) { | 157 gles2::TextureManager* texture_manager) { |
155 CalledOnValidThread(); | 158 CalledOnValidThread(); |
156 | 159 |
157 gles2::TextureRef* texture = texture_manager->GetTexture(client_texture_id); | 160 gles2::TextureRef* texture = texture_manager->GetTexture(client_texture_id); |
158 | 161 |
159 if (!texture || (texture->texture()->target() && | 162 if (!texture || (texture->texture()->target() && |
160 texture->texture()->target() != GL_TEXTURE_EXTERNAL_OES)) { | 163 texture->texture()->target() != GL_TEXTURE_EXTERNAL_OES)) { |
161 return 0; | 164 return 0; |
162 } | 165 } |
163 | 166 |
164 scoped_refptr<gfx::SurfaceTexture> surface_texture( | 167 scoped_refptr<gfx::SurfaceTexture> surface_texture( |
165 gfx::SurfaceTexture::Create(texture->service_id())); | 168 gfx::SurfaceTexture::Create(texture->service_id())); |
166 | 169 |
167 uint32 stream_id = next_id_++; | 170 uint32_t stream_id = next_id_++; |
168 base::Closure release_callback = | 171 base::Closure release_callback = |
169 base::Bind(&StreamTextureManagerInProcess::OnReleaseStreamTexture, | 172 base::Bind(&StreamTextureManagerInProcess::OnReleaseStreamTexture, |
170 weak_factory_.GetWeakPtr(), stream_id); | 173 weak_factory_.GetWeakPtr(), stream_id); |
171 scoped_refptr<gl::GLImage> gl_image( | 174 scoped_refptr<gl::GLImage> gl_image( |
172 new GLImageImpl(texture->service_id(), texture_manager, surface_texture, | 175 new GLImageImpl(texture->service_id(), texture_manager, surface_texture, |
173 release_callback)); | 176 release_callback)); |
174 | 177 |
175 gfx::Size size = gl_image->GetSize(); | 178 gfx::Size size = gl_image->GetSize(); |
176 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); | 179 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); |
177 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, | 180 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, |
178 size.width(), size.height(), 1, 0, GL_RGBA, | 181 size.width(), size.height(), 1, 0, GL_RGBA, |
179 GL_UNSIGNED_BYTE, gfx::Rect(size)); | 182 GL_UNSIGNED_BYTE, gfx::Rect(size)); |
180 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0, | 183 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0, |
181 gl_image.get(), gles2::Texture::UNBOUND); | 184 gl_image.get(), gles2::Texture::UNBOUND); |
182 | 185 |
183 { | 186 { |
184 base::AutoLock lock(map_lock_); | 187 base::AutoLock lock(map_lock_); |
185 textures_[stream_id] = surface_texture; | 188 textures_[stream_id] = surface_texture; |
186 } | 189 } |
187 | 190 |
188 if (next_id_ == 0) | 191 if (next_id_ == 0) |
189 next_id_++; | 192 next_id_++; |
190 | 193 |
191 return stream_id; | 194 return stream_id; |
192 } | 195 } |
193 | 196 |
194 void StreamTextureManagerInProcess::OnReleaseStreamTexture(uint32 stream_id) { | 197 void StreamTextureManagerInProcess::OnReleaseStreamTexture(uint32_t stream_id) { |
195 CalledOnValidThread(); | 198 CalledOnValidThread(); |
196 base::AutoLock lock(map_lock_); | 199 base::AutoLock lock(map_lock_); |
197 textures_.erase(stream_id); | 200 textures_.erase(stream_id); |
198 } | 201 } |
199 | 202 |
200 // This can get called from any thread. | 203 // This can get called from any thread. |
201 scoped_refptr<gfx::SurfaceTexture> | 204 scoped_refptr<gfx::SurfaceTexture> |
202 StreamTextureManagerInProcess::GetSurfaceTexture(uint32 stream_id) { | 205 StreamTextureManagerInProcess::GetSurfaceTexture(uint32_t stream_id) { |
203 base::AutoLock lock(map_lock_); | 206 base::AutoLock lock(map_lock_); |
204 TextureMap::const_iterator it = textures_.find(stream_id); | 207 TextureMap::const_iterator it = textures_.find(stream_id); |
205 if (it != textures_.end()) | 208 if (it != textures_.end()) |
206 return it->second; | 209 return it->second; |
207 | 210 |
208 return NULL; | 211 return NULL; |
209 } | 212 } |
210 | 213 |
211 } // namespace gpu | 214 } // namespace gpu |
OLD | NEW |