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<gpu::gles2::GLStreamTextureImage> gl_image( | 45 scoped_refptr<gpu::gles2::GLStreamTextureImage> 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->SetLevelStreamTextureImage( | 52 texture_manager->SetLevelStreamTextureImage( |
53 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get(), | 53 texture, GL_TEXTURE_EXTERNAL_OES, 0, 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 surface_texture_->UpdateTexImage(); | 148 surface_texture_->UpdateTexImage(); |
149 | 149 |
150 has_pending_frame_ = false; | 150 has_pending_frame_ = false; |
151 | 151 |
152 if (scoped_make_current.get()) { | 152 if (scoped_make_current.get()) { |
153 // UpdateTexImage() implies glBindTexture(). | 153 // UpdateTexImage() implies glBindTexture(). |
154 // The cmd decoder takes care of restoring the binding for this GLImage as | 154 // The cmd decoder takes care of restoring the binding for this GLImage as |
155 // far as the current context is concerned, but if we temporarily change | 155 // far as the current context is concerned, but if we temporarily change |
156 // it, we have to keep the state intact in *that* context also. | 156 // it, we have to keep the state intact in *that* context also. |
157 const gpu::gles2::ContextState* state = | 157 const gles2::ContextState* state = |
158 owner_stub_->decoder()->GetContextState(); | 158 owner_stub_->decoder()->GetContextState(); |
159 const gpu::gles2::TextureUnit& active_unit = | 159 const gles2::TextureUnit& active_unit = |
160 state->texture_units[state->active_texture_unit]; | 160 state->texture_units[state->active_texture_unit]; |
161 glBindTexture(GL_TEXTURE_EXTERNAL_OES, | 161 glBindTexture(GL_TEXTURE_EXTERNAL_OES, |
162 active_unit.bound_texture_external_oes.get() | 162 active_unit.bound_texture_external_oes.get() |
163 ? active_unit.bound_texture_external_oes->service_id() | 163 ? active_unit.bound_texture_external_oes->service_id() |
164 : 0); | 164 : 0); |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 bool StreamTexture::CopyTexImage(unsigned target) { | 168 bool StreamTexture::CopyTexImage(unsigned target) { |
169 if (target != GL_TEXTURE_EXTERNAL_OES) | 169 if (target != GL_TEXTURE_EXTERNAL_OES) |
(...skipping 10 matching lines...) Expand all Loading... |
180 // On some devices GL_TEXTURE_BINDING_EXTERNAL_OES is not supported as | 180 // On some devices GL_TEXTURE_BINDING_EXTERNAL_OES is not supported as |
181 // glGetIntegerv() parameter. In this case the value of |texture_id| will be | 181 // glGetIntegerv() parameter. In this case the value of |texture_id| will be |
182 // zero and we assume that it is properly bound to |texture_id_|. | 182 // zero and we assume that it is properly bound to |texture_id_|. |
183 if (texture_id > 0 && static_cast<unsigned>(texture_id) != texture_id_) | 183 if (texture_id > 0 && static_cast<unsigned>(texture_id) != texture_id_) |
184 return false; | 184 return false; |
185 | 185 |
186 UpdateTexImage(); | 186 UpdateTexImage(); |
187 | 187 |
188 TextureManager* texture_manager = | 188 TextureManager* texture_manager = |
189 owner_stub_->decoder()->GetContextGroup()->texture_manager(); | 189 owner_stub_->decoder()->GetContextGroup()->texture_manager(); |
190 gpu::gles2::Texture* texture = | 190 gles2::Texture* texture = |
191 texture_manager->GetTextureForServiceId(texture_id_); | 191 texture_manager->GetTextureForServiceId(texture_id_); |
192 if (texture) { | 192 if (texture) { |
193 // By setting image state to UNBOUND instead of COPIED we ensure that | 193 // By setting image state to UNBOUND instead of COPIED we ensure that |
194 // CopyTexImage() is called each time the surface texture is used for | 194 // CopyTexImage() is called each time the surface texture is used for |
195 // drawing. | 195 // drawing. |
196 texture->SetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, 0, this, | 196 texture->SetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, 0, this, |
197 gpu::gles2::Texture::UNBOUND); | 197 gles2::Texture::UNBOUND); |
198 } | 198 } |
199 | 199 |
200 return true; | 200 return true; |
201 } | 201 } |
202 | 202 |
203 void StreamTexture::OnFrameAvailable() { | 203 void StreamTexture::OnFrameAvailable() { |
204 has_pending_frame_ = true; | 204 has_pending_frame_ = true; |
205 if (has_listener_ && owner_stub_) { | 205 if (has_listener_ && owner_stub_) { |
206 owner_stub_->channel()->Send( | 206 owner_stub_->channel()->Send( |
207 new GpuStreamTextureMsg_FrameAvailable(route_id_)); | 207 new GpuStreamTextureMsg_FrameAvailable(route_id_)); |
(...skipping 25 matching lines...) Expand all Loading... |
233 DCHECK(!has_listener_); | 233 DCHECK(!has_listener_); |
234 has_listener_ = true; | 234 has_listener_ = true; |
235 } | 235 } |
236 | 236 |
237 void StreamTexture::OnEstablishPeer(int32_t primary_id, int32_t secondary_id) { | 237 void StreamTexture::OnEstablishPeer(int32_t primary_id, int32_t secondary_id) { |
238 if (!owner_stub_) | 238 if (!owner_stub_) |
239 return; | 239 return; |
240 | 240 |
241 base::ProcessHandle process = owner_stub_->channel()->GetClientPID(); | 241 base::ProcessHandle process = owner_stub_->channel()->GetClientPID(); |
242 | 242 |
243 gpu::SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( | 243 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( |
244 process, surface_texture_, primary_id, secondary_id); | 244 process, surface_texture_, primary_id, secondary_id); |
245 } | 245 } |
246 | 246 |
247 bool StreamTexture::BindTexImage(unsigned target) { | 247 bool StreamTexture::BindTexImage(unsigned target) { |
248 NOTREACHED(); | 248 NOTREACHED(); |
249 return false; | 249 return false; |
250 } | 250 } |
251 | 251 |
252 void StreamTexture::ReleaseTexImage(unsigned target) { | 252 void StreamTexture::ReleaseTexImage(unsigned target) { |
253 NOTREACHED(); | 253 NOTREACHED(); |
(...skipping 13 matching lines...) Expand all Loading... |
267 NOTREACHED(); | 267 NOTREACHED(); |
268 return false; | 268 return false; |
269 } | 269 } |
270 | 270 |
271 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 271 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
272 uint64_t process_tracing_id, | 272 uint64_t process_tracing_id, |
273 const std::string& dump_name) { | 273 const std::string& dump_name) { |
274 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 | 274 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 |
275 } | 275 } |
276 | 276 |
277 } // namespace content | 277 } // namespace gpu |
OLD | NEW |