| 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/texture_manager.h" | 14 #include "gpu/command_buffer/service/texture_manager.h" |
| 15 #include "gpu/ipc/common/android/surface_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 { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 owner_stub_(owner_stub), | 68 owner_stub_(owner_stub), |
| 68 route_id_(route_id), | 69 route_id_(route_id), |
| 69 has_listener_(false), | 70 has_listener_(false), |
| 70 texture_id_(texture_id), | 71 texture_id_(texture_id), |
| 71 framebuffer_(0), | 72 framebuffer_(0), |
| 72 vertex_shader_(0), | 73 vertex_shader_(0), |
| 73 fragment_shader_(0), | 74 fragment_shader_(0), |
| 74 program_(0), | 75 program_(0), |
| 75 vertex_buffer_(0), | 76 vertex_buffer_(0), |
| 76 u_xform_location_(-1), | 77 u_xform_location_(-1), |
| 78 registered_surface_texture_id(0), |
| 77 weak_factory_(this) { | 79 weak_factory_(this) { |
| 78 owner_stub->AddDestructionObserver(this); | 80 owner_stub->AddDestructionObserver(this); |
| 79 memset(current_matrix_, 0, sizeof(current_matrix_)); | 81 memset(current_matrix_, 0, sizeof(current_matrix_)); |
| 80 owner_stub->channel()->AddRoute(route_id, owner_stub->stream_id(), this); | 82 owner_stub->channel()->AddRoute(route_id, owner_stub->stream_id(), this); |
| 81 surface_texture_->SetFrameAvailableCallback(base::Bind( | 83 surface_texture_->SetFrameAvailableCallback(base::Bind( |
| 82 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); | 84 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); |
| 83 } | 85 } |
| 84 | 86 |
| 85 StreamTexture::~StreamTexture() { | 87 StreamTexture::~StreamTexture() { |
| 86 if (owner_stub_) { | 88 if (owner_stub_) { |
| 87 owner_stub_->RemoveDestructionObserver(this); | 89 owner_stub_->RemoveDestructionObserver(this); |
| 88 owner_stub_->channel()->RemoveRoute(route_id_); | 90 owner_stub_->channel()->RemoveRoute(route_id_); |
| 89 } | 91 } |
| 92 |
| 93 if (registered_surface_texture_id) { |
| 94 SurfaceTextureManager::GetInstance()->UnregisterBrowserSurfaceTexture( |
| 95 registered_surface_texture_id); |
| 96 } |
| 90 } | 97 } |
| 91 | 98 |
| 92 // gpu::gles2::GLStreamTextureMatrix implementation | 99 // gpu::gles2::GLStreamTextureMatrix implementation |
| 93 void StreamTexture::GetTextureMatrix(float xform[16]) { | 100 void StreamTexture::GetTextureMatrix(float xform[16]) { |
| 94 if (surface_texture_) { | 101 if (surface_texture_) { |
| 95 UpdateTexImage(); | 102 UpdateTexImage(); |
| 96 surface_texture_->GetTransformMatrix(current_matrix_); | 103 surface_texture_->GetTransformMatrix(current_matrix_); |
| 97 } | 104 } |
| 98 memcpy(xform, current_matrix_, sizeof(current_matrix_)); | 105 memcpy(xform, current_matrix_, sizeof(current_matrix_)); |
| 99 YInvertMatrix(xform); | 106 YInvertMatrix(xform); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 225 } |
| 219 | 226 |
| 220 unsigned StreamTexture::GetInternalFormat() { | 227 unsigned StreamTexture::GetInternalFormat() { |
| 221 return GL_RGBA; | 228 return GL_RGBA; |
| 222 } | 229 } |
| 223 | 230 |
| 224 bool StreamTexture::OnMessageReceived(const IPC::Message& message) { | 231 bool StreamTexture::OnMessageReceived(const IPC::Message& message) { |
| 225 bool handled = true; | 232 bool handled = true; |
| 226 IPC_BEGIN_MESSAGE_MAP(StreamTexture, message) | 233 IPC_BEGIN_MESSAGE_MAP(StreamTexture, message) |
| 227 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_StartListening, OnStartListening) | 234 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_StartListening, OnStartListening) |
| 235 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_RegisterStreamTexture, |
| 236 OnRegisterStreamTexture) |
| 228 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_EstablishPeer, OnEstablishPeer) | 237 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_EstablishPeer, OnEstablishPeer) |
| 229 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_SetSize, OnSetSize) | 238 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_SetSize, OnSetSize) |
| 230 IPC_MESSAGE_UNHANDLED(handled = false) | 239 IPC_MESSAGE_UNHANDLED(handled = false) |
| 231 IPC_END_MESSAGE_MAP() | 240 IPC_END_MESSAGE_MAP() |
| 232 | 241 |
| 233 DCHECK(handled); | 242 DCHECK(handled); |
| 234 return handled; | 243 return handled; |
| 235 } | 244 } |
| 236 | 245 |
| 237 void StreamTexture::OnStartListening() { | 246 void StreamTexture::OnStartListening() { |
| 238 DCHECK(!has_listener_); | 247 DCHECK(!has_listener_); |
| 239 has_listener_ = true; | 248 has_listener_ = true; |
| 240 } | 249 } |
| 241 | 250 |
| 242 void StreamTexture::OnEstablishPeer(int32_t primary_id, int32_t secondary_id) { | 251 void StreamTexture::OnEstablishPeer(int32_t primary_id, int32_t secondary_id) { |
| 243 if (!owner_stub_) | 252 if (!owner_stub_) |
| 244 return; | 253 return; |
| 245 | 254 |
| 246 base::ProcessHandle process = owner_stub_->channel()->GetClientPID(); | 255 base::ProcessHandle process = owner_stub_->channel()->GetClientPID(); |
| 247 | 256 |
| 248 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( | 257 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( |
| 249 process, surface_texture_, primary_id, secondary_id); | 258 process, surface_texture_, primary_id, secondary_id); |
| 250 } | 259 } |
| 251 | 260 |
| 261 void StreamTexture::OnRegisterStreamTexture(int32_t surface_texture_id) { |
| 262 if (!owner_stub_) |
| 263 return; |
| 264 |
| 265 DCHECK(!registered_surface_texture_id); |
| 266 registered_surface_texture_id = surface_texture_id; |
| 267 |
| 268 SurfaceTextureManager::GetInstance()->RegisterBrowserSurfaceTexture( |
| 269 surface_texture_id, surface_texture_.get()); |
| 270 } |
| 271 |
| 252 bool StreamTexture::BindTexImage(unsigned target) { | 272 bool StreamTexture::BindTexImage(unsigned target) { |
| 253 NOTREACHED(); | 273 NOTREACHED(); |
| 254 return false; | 274 return false; |
| 255 } | 275 } |
| 256 | 276 |
| 257 void StreamTexture::ReleaseTexImage(unsigned target) { | 277 void StreamTexture::ReleaseTexImage(unsigned target) { |
| 258 NOTREACHED(); | 278 NOTREACHED(); |
| 259 } | 279 } |
| 260 | 280 |
| 261 bool StreamTexture::CopyTexSubImage(unsigned target, | 281 bool StreamTexture::CopyTexSubImage(unsigned target, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 273 return false; | 293 return false; |
| 274 } | 294 } |
| 275 | 295 |
| 276 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 296 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
| 277 uint64_t process_tracing_id, | 297 uint64_t process_tracing_id, |
| 278 const std::string& dump_name) { | 298 const std::string& dump_name) { |
| 279 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 | 299 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 |
| 280 } | 300 } |
| 281 | 301 |
| 282 } // namespace gpu | 302 } // namespace gpu |
| OLD | NEW |