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 "content/common/gpu/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 "content/common/gpu/gpu_channel.h" | |
12 #include "gpu/command_buffer/service/context_group.h" | 11 #include "gpu/command_buffer/service/context_group.h" |
13 #include "gpu/command_buffer/service/context_state.h" | 12 #include "gpu/command_buffer/service/context_state.h" |
14 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
15 #include "gpu/command_buffer/service/texture_manager.h" | 14 #include "gpu/command_buffer/service/texture_manager.h" |
16 #include "gpu/ipc/common/android/surface_texture_peer.h" | 15 #include "gpu/ipc/common/android/surface_texture_peer.h" |
17 #include "gpu/ipc/common/gpu_messages.h" | 16 #include "gpu/ipc/common/gpu_messages.h" |
| 17 #include "gpu/ipc/service/gpu_channel.h" |
18 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
19 #include "ui/gl/gl_context.h" | 19 #include "ui/gl/gl_context.h" |
20 #include "ui/gl/gl_helper.h" | 20 #include "ui/gl/gl_helper.h" |
21 #include "ui/gl/scoped_binders.h" | 21 #include "ui/gl/scoped_binders.h" |
22 #include "ui/gl/scoped_make_current.h" | 22 #include "ui/gl/scoped_make_current.h" |
23 | 23 |
24 namespace content { | 24 namespace gpu { |
25 | 25 |
26 using gpu::gles2::ContextGroup; | 26 using gles2::ContextGroup; |
27 using gpu::gles2::GLES2Decoder; | 27 using gles2::GLES2Decoder; |
28 using gpu::gles2::TextureManager; | 28 using gles2::TextureManager; |
29 using gpu::gles2::TextureRef; | 29 using gles2::TextureRef; |
30 | 30 |
31 // static | 31 // static |
32 bool StreamTexture::Create(GpuCommandBufferStub* owner_stub, | 32 bool StreamTexture::Create(GpuCommandBufferStub* owner_stub, |
33 uint32_t client_texture_id, | 33 uint32_t client_texture_id, |
34 int stream_id) { | 34 int stream_id) { |
35 GLES2Decoder* decoder = owner_stub->decoder(); | 35 GLES2Decoder* decoder = owner_stub->decoder(); |
36 TextureManager* texture_manager = | 36 TextureManager* texture_manager = |
37 decoder->GetContextGroup()->texture_manager(); | 37 decoder->GetContextGroup()->texture_manager(); |
38 TextureRef* texture = texture_manager->GetTexture(client_texture_id); | 38 TextureRef* texture = texture_manager->GetTexture(client_texture_id); |
39 | 39 |
40 if (texture && (!texture->texture()->target() || | 40 if (texture && (!texture->texture()->target() || |
41 texture->texture()->target() == GL_TEXTURE_EXTERNAL_OES)) { | 41 texture->texture()->target() == GL_TEXTURE_EXTERNAL_OES)) { |
42 | 42 |
43 // TODO: Ideally a valid image id was returned to the client so that | 43 // TODO: Ideally a valid image id was returned to the client so that |
44 // it could then call glBindTexImage2D() for doing the following. | 44 // it could then call glBindTexImage2D() for doing the following. |
45 scoped_refptr<gl::GLImage> gl_image( | 45 scoped_refptr<gl::GLImage> gl_image( |
46 new StreamTexture(owner_stub, stream_id, texture->service_id())); | 46 new StreamTexture(owner_stub, stream_id, texture->service_id())); |
47 gfx::Size size = gl_image->GetSize(); | 47 gfx::Size size = gl_image->GetSize(); |
48 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); | 48 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); |
49 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, | 49 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, |
50 size.width(), size.height(), 1, 0, GL_RGBA, | 50 size.width(), size.height(), 1, 0, GL_RGBA, |
51 GL_UNSIGNED_BYTE, gfx::Rect(size)); | 51 GL_UNSIGNED_BYTE, gfx::Rect(size)); |
52 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0, | 52 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0, |
53 gl_image.get(), | 53 gl_image.get(), |
54 gpu::gles2::Texture::UNBOUND); | 54 gles2::Texture::UNBOUND); |
55 return true; | 55 return true; |
56 } | 56 } |
57 | 57 |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, | 61 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, |
62 int32_t route_id, | 62 int32_t route_id, |
63 uint32_t texture_id) | 63 uint32_t texture_id) |
64 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), | 64 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 owner_stub_->channel()->Send( | 157 owner_stub_->channel()->Send( |
158 new GpuStreamTextureMsg_MatrixChanged(route_id_, params)); | 158 new GpuStreamTextureMsg_MatrixChanged(route_id_, params)); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 if (scoped_make_current.get()) { | 162 if (scoped_make_current.get()) { |
163 // UpdateTexImage() implies glBindTexture(). | 163 // UpdateTexImage() implies glBindTexture(). |
164 // The cmd decoder takes care of restoring the binding for this GLImage as | 164 // The cmd decoder takes care of restoring the binding for this GLImage as |
165 // far as the current context is concerned, but if we temporarily change | 165 // far as the current context is concerned, but if we temporarily change |
166 // it, we have to keep the state intact in *that* context also. | 166 // it, we have to keep the state intact in *that* context also. |
167 const gpu::gles2::ContextState* state = | 167 const gles2::ContextState* state = |
168 owner_stub_->decoder()->GetContextState(); | 168 owner_stub_->decoder()->GetContextState(); |
169 const gpu::gles2::TextureUnit& active_unit = | 169 const gles2::TextureUnit& active_unit = |
170 state->texture_units[state->active_texture_unit]; | 170 state->texture_units[state->active_texture_unit]; |
171 glBindTexture(GL_TEXTURE_EXTERNAL_OES, | 171 glBindTexture(GL_TEXTURE_EXTERNAL_OES, |
172 active_unit.bound_texture_external_oes.get() | 172 active_unit.bound_texture_external_oes.get() |
173 ? active_unit.bound_texture_external_oes->service_id() | 173 ? active_unit.bound_texture_external_oes->service_id() |
174 : 0); | 174 : 0); |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 bool StreamTexture::CopyTexImage(unsigned target) { | 178 bool StreamTexture::CopyTexImage(unsigned target) { |
179 if (target == GL_TEXTURE_2D) { | 179 if (target == GL_TEXTURE_2D) { |
(...skipping 16 matching lines...) Expand all Loading... |
196 // On some devices GL_TEXTURE_BINDING_EXTERNAL_OES is not supported as | 196 // On some devices GL_TEXTURE_BINDING_EXTERNAL_OES is not supported as |
197 // glGetIntegerv() parameter. In this case the value of |texture_id| will be | 197 // glGetIntegerv() parameter. In this case the value of |texture_id| will be |
198 // zero and we assume that it is properly bound to |texture_id_|. | 198 // zero and we assume that it is properly bound to |texture_id_|. |
199 if (texture_id > 0 && static_cast<unsigned>(texture_id) != texture_id_) | 199 if (texture_id > 0 && static_cast<unsigned>(texture_id) != texture_id_) |
200 return false; | 200 return false; |
201 | 201 |
202 UpdateTexImage(); | 202 UpdateTexImage(); |
203 | 203 |
204 TextureManager* texture_manager = | 204 TextureManager* texture_manager = |
205 owner_stub_->decoder()->GetContextGroup()->texture_manager(); | 205 owner_stub_->decoder()->GetContextGroup()->texture_manager(); |
206 gpu::gles2::Texture* texture = | 206 gles2::Texture* texture = |
207 texture_manager->GetTextureForServiceId(texture_id_); | 207 texture_manager->GetTextureForServiceId(texture_id_); |
208 if (texture) { | 208 if (texture) { |
209 // By setting image state to UNBOUND instead of COPIED we ensure that | 209 // By setting image state to UNBOUND instead of COPIED we ensure that |
210 // CopyTexImage() is called each time the surface texture is used for | 210 // CopyTexImage() is called each time the surface texture is used for |
211 // drawing. | 211 // drawing. |
212 texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, | 212 texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, |
213 gpu::gles2::Texture::UNBOUND); | 213 gles2::Texture::UNBOUND); |
214 } | 214 } |
215 | 215 |
216 return true; | 216 return true; |
217 } | 217 } |
218 | 218 |
219 void StreamTexture::OnFrameAvailable() { | 219 void StreamTexture::OnFrameAvailable() { |
220 has_pending_frame_ = true; | 220 has_pending_frame_ = true; |
221 if (has_listener_ && owner_stub_) { | 221 if (has_listener_ && owner_stub_) { |
222 owner_stub_->channel()->Send( | 222 owner_stub_->channel()->Send( |
223 new GpuStreamTextureMsg_FrameAvailable(route_id_)); | 223 new GpuStreamTextureMsg_FrameAvailable(route_id_)); |
(...skipping 25 matching lines...) Expand all Loading... |
249 DCHECK(!has_listener_); | 249 DCHECK(!has_listener_); |
250 has_listener_ = true; | 250 has_listener_ = true; |
251 } | 251 } |
252 | 252 |
253 void StreamTexture::OnEstablishPeer(int32_t primary_id, int32_t secondary_id) { | 253 void StreamTexture::OnEstablishPeer(int32_t primary_id, int32_t secondary_id) { |
254 if (!owner_stub_) | 254 if (!owner_stub_) |
255 return; | 255 return; |
256 | 256 |
257 base::ProcessHandle process = owner_stub_->channel()->GetClientPID(); | 257 base::ProcessHandle process = owner_stub_->channel()->GetClientPID(); |
258 | 258 |
259 gpu::SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( | 259 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( |
260 process, surface_texture_, primary_id, secondary_id); | 260 process, surface_texture_, primary_id, secondary_id); |
261 } | 261 } |
262 | 262 |
263 bool StreamTexture::BindTexImage(unsigned target) { | 263 bool StreamTexture::BindTexImage(unsigned target) { |
264 NOTREACHED(); | 264 NOTREACHED(); |
265 return false; | 265 return false; |
266 } | 266 } |
267 | 267 |
268 void StreamTexture::ReleaseTexImage(unsigned target) { | 268 void StreamTexture::ReleaseTexImage(unsigned target) { |
269 NOTREACHED(); | 269 NOTREACHED(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 NOTREACHED(); | 370 NOTREACHED(); |
371 return false; | 371 return false; |
372 } | 372 } |
373 | 373 |
374 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 374 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
375 uint64_t process_tracing_id, | 375 uint64_t process_tracing_id, |
376 const std::string& dump_name) { | 376 const std::string& dump_name) { |
377 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 | 377 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 |
378 } | 378 } |
379 | 379 |
380 } // namespace content | 380 } // namespace gpu |
OLD | NEW |