OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/ipc/service/stream_texture_android.h" | 5 #include "gpu/ipc/service/stream_texture_android.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/stringize_macros.h" | 10 #include "base/strings/stringize_macros.h" |
11 #include "gpu/command_buffer/service/context_group.h" | 11 #include "gpu/command_buffer/service/context_group.h" |
12 #include "gpu/command_buffer/service/context_state.h" | 12 #include "gpu/command_buffer/service/context_state.h" |
13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 14 #include "gpu/command_buffer/service/image_manager.h" |
14 #include "gpu/command_buffer/service/texture_manager.h" | 15 #include "gpu/command_buffer/service/texture_manager.h" |
15 #include "gpu/ipc/common/android/surface_texture_peer.h" | 16 #include "gpu/ipc/common/android/surface_texture_peer.h" |
16 #include "gpu/ipc/common/gpu_messages.h" | 17 #include "gpu/ipc/common/gpu_messages.h" |
17 #include "gpu/ipc/service/gpu_channel.h" | 18 #include "gpu/ipc/service/gpu_channel.h" |
18 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
19 #include "ui/gl/gl_context.h" | 20 #include "ui/gl/gl_context.h" |
20 #include "ui/gl/gl_helper.h" | 21 #include "ui/gl/gl_helper.h" |
21 #include "ui/gl/scoped_binders.h" | 22 #include "ui/gl/scoped_binders.h" |
22 #include "ui/gl/scoped_make_current.h" | 23 #include "ui/gl/scoped_make_current.h" |
23 | 24 |
24 namespace gpu { | 25 namespace gpu { |
25 | 26 |
26 using gles2::ContextGroup; | 27 using gles2::ContextGroup; |
27 using gles2::GLES2Decoder; | 28 using gles2::GLES2Decoder; |
| 29 using gpu::gles2::ImageManager; |
28 using gles2::TextureManager; | 30 using gles2::TextureManager; |
29 using gles2::TextureRef; | 31 using gles2::TextureRef; |
30 | 32 |
31 // static | 33 // static |
32 bool StreamTexture::Create(GpuCommandBufferStub* owner_stub, | 34 bool StreamTexture::Create(GpuCommandBufferStub* owner_stub, |
33 uint32_t client_texture_id, | 35 int32_t image_id, |
34 int stream_id) { | 36 int stream_id) { |
| 37 DCHECK(owner_stub); |
35 GLES2Decoder* decoder = owner_stub->decoder(); | 38 GLES2Decoder* decoder = owner_stub->decoder(); |
36 TextureManager* texture_manager = | 39 DCHECK(decoder); |
37 decoder->GetContextGroup()->texture_manager(); | 40 ImageManager* image_manager = decoder->GetImageManager(); |
38 TextureRef* texture = texture_manager->GetTexture(client_texture_id); | 41 DCHECK(image_manager); |
39 | 42 scoped_refptr<StreamTexture> image( |
40 if (texture && (!texture->texture()->target() || | 43 new StreamTexture(owner_stub, stream_id, 0)); |
41 texture->texture()->target() == GL_TEXTURE_EXTERNAL_OES)) { | 44 image_manager->AddImage(image.get(), image_id); |
42 | 45 return true; |
43 // TODO: Ideally a valid image id was returned to the client so that | |
44 // it could then call glBindTexImage2D() for doing the following. | |
45 scoped_refptr<gpu::gles2::GLStreamTextureImage> gl_image( | |
46 new StreamTexture(owner_stub, stream_id, texture->service_id())); | |
47 gfx::Size size = gl_image->GetSize(); | |
48 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); | |
49 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, | |
50 size.width(), size.height(), 1, 0, GL_RGBA, | |
51 GL_UNSIGNED_BYTE, gfx::Rect(size)); | |
52 texture_manager->SetLevelStreamTextureImage( | |
53 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get(), | |
54 gles2::Texture::UNBOUND, 0); | |
55 return true; | |
56 } | |
57 | |
58 return false; | |
59 } | 46 } |
60 | 47 |
61 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, | 48 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, |
62 int32_t route_id, | 49 int32_t route_id, |
63 uint32_t texture_id) | 50 int32_t texture_id) |
64 : surface_texture_(gl::SurfaceTexture::Create(texture_id)), | 51 : surface_texture_(gl::SurfaceTexture::Create(texture_id)), |
65 size_(0, 0), | 52 size_(0, 0), |
66 has_pending_frame_(false), | 53 has_pending_frame_(false), |
67 owner_stub_(owner_stub), | 54 owner_stub_(owner_stub), |
68 route_id_(route_id), | 55 route_id_(route_id), |
69 has_listener_(false), | 56 has_listener_(false), |
70 texture_id_(texture_id), | 57 texture_id_(texture_id), |
71 framebuffer_(0), | 58 framebuffer_(0), |
72 vertex_shader_(0), | 59 vertex_shader_(0), |
73 fragment_shader_(0), | 60 fragment_shader_(0), |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return true; | 164 return true; |
178 | 165 |
179 GLint texture_id; | 166 GLint texture_id; |
180 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); | 167 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); |
181 | 168 |
182 // The following code only works if we're being asked to copy into | 169 // The following code only works if we're being asked to copy into |
183 // |texture_id_|. Copying into a different texture is not supported. | 170 // |texture_id_|. Copying into a different texture is not supported. |
184 // On some devices GL_TEXTURE_BINDING_EXTERNAL_OES is not supported as | 171 // On some devices GL_TEXTURE_BINDING_EXTERNAL_OES is not supported as |
185 // glGetIntegerv() parameter. In this case the value of |texture_id| will be | 172 // glGetIntegerv() parameter. In this case the value of |texture_id| will be |
186 // zero and we assume that it is properly bound to |texture_id_|. | 173 // zero and we assume that it is properly bound to |texture_id_|. |
187 if (texture_id > 0 && static_cast<unsigned>(texture_id) != texture_id_) | 174 if (texture_id > 0 && texture_id != texture_id_) |
188 return false; | 175 return false; |
189 | 176 |
190 UpdateTexImage(); | 177 UpdateTexImage(); |
191 | 178 |
192 TextureManager* texture_manager = | 179 TextureManager* texture_manager = |
193 owner_stub_->decoder()->GetContextGroup()->texture_manager(); | 180 owner_stub_->decoder()->GetContextGroup()->texture_manager(); |
194 gles2::Texture* texture = | 181 gles2::Texture* texture = |
195 texture_manager->GetTextureForServiceId(texture_id_); | 182 texture_manager->GetTextureForServiceId(texture_id_); |
196 if (texture) { | 183 if (texture) { |
197 // By setting image state to UNBOUND instead of COPIED we ensure that | 184 // By setting image state to UNBOUND instead of COPIED we ensure that |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if (!owner_stub_) | 229 if (!owner_stub_) |
243 return; | 230 return; |
244 | 231 |
245 base::ProcessHandle process = owner_stub_->channel()->GetClientPID(); | 232 base::ProcessHandle process = owner_stub_->channel()->GetClientPID(); |
246 | 233 |
247 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( | 234 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( |
248 process, surface_texture_, primary_id, secondary_id); | 235 process, surface_texture_, primary_id, secondary_id); |
249 } | 236 } |
250 | 237 |
251 bool StreamTexture::BindTexImage(unsigned target) { | 238 bool StreamTexture::BindTexImage(unsigned target) { |
252 NOTREACHED(); | 239 TRACE_EVENT0("gpu", "StreamTexture::BindTexImage"); |
253 return false; | 240 DCHECK(surface_texture_.get()); |
| 241 if (!owner_stub_ || !surface_texture_.get()) |
| 242 return false; |
| 243 |
| 244 if (target != GL_TEXTURE_EXTERNAL_OES) { |
| 245 LOG(ERROR) |
| 246 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target"; |
| 247 return false; |
| 248 } |
| 249 |
| 250 GLint texture_id; |
| 251 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); |
| 252 DCHECK(texture_id); |
| 253 |
| 254 if (texture_id_ && texture_id_ != texture_id) { |
| 255 LOG(ERROR) << "Surface texture can only be bound to one texture ID"; |
| 256 return false; |
| 257 } |
| 258 |
| 259 DCHECK(surface_texture_.get()); |
| 260 if (texture_id != texture_id_) { |
| 261 // Note: Surface textures used as gpu memory buffers are created with an |
| 262 // initial dummy texture id of 0. We need to call DetachFromGLContext() here |
| 263 // to detach from the dummy texture before we can attach to a real texture |
| 264 // id. DetachFromGLContext() will delete the texture for the current |
| 265 // attachment point so it's important that this is never called when |
| 266 // attached to a real texture id. Detaching from the dummy texture id should |
| 267 // not cause any problems as the GL should silently ignore 0 when passed to |
| 268 // glDeleteTextures. |
| 269 DCHECK_EQ(0, texture_id_); |
| 270 surface_texture_->DetachFromGLContext(); |
| 271 |
| 272 // This will attach the surface texture to the texture currently bound to |
| 273 // GL_TEXTURE_EXTERNAL_OES target. |
| 274 surface_texture_->AttachToGLContext(); |
| 275 texture_id_ = texture_id; |
| 276 } |
| 277 |
| 278 surface_texture_->UpdateTexImage(); |
| 279 return true; |
254 } | 280 } |
255 | 281 |
256 void StreamTexture::ReleaseTexImage(unsigned target) { | 282 void StreamTexture::ReleaseTexImage(unsigned target) { |
257 NOTREACHED(); | 283 NOTREACHED(); |
258 } | 284 } |
259 | 285 |
260 bool StreamTexture::CopyTexSubImage(unsigned target, | 286 bool StreamTexture::CopyTexSubImage(unsigned target, |
261 const gfx::Point& offset, | 287 const gfx::Point& offset, |
262 const gfx::Rect& rect) { | 288 const gfx::Rect& rect) { |
263 return false; | 289 return false; |
264 } | 290 } |
265 | 291 |
266 bool StreamTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 292 bool StreamTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
267 int z_order, | 293 int z_order, |
268 gfx::OverlayTransform transform, | 294 gfx::OverlayTransform transform, |
269 const gfx::Rect& bounds_rect, | 295 const gfx::Rect& bounds_rect, |
270 const gfx::RectF& crop_rect) { | 296 const gfx::RectF& crop_rect) { |
271 NOTREACHED(); | 297 NOTREACHED(); |
272 return false; | 298 return false; |
273 } | 299 } |
274 | 300 |
275 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 301 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
276 uint64_t process_tracing_id, | 302 uint64_t process_tracing_id, |
277 const std::string& dump_name) { | 303 const std::string& dump_name) { |
278 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 | 304 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 |
279 } | 305 } |
280 | 306 |
281 } // namespace gpu | 307 } // namespace gpu |
OLD | NEW |