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" | |
11 #include "gpu/command_buffer/service/context_group.h" | 10 #include "gpu/command_buffer/service/context_group.h" |
12 #include "gpu/command_buffer/service/context_state.h" | 11 #include "gpu/command_buffer/service/context_state.h" |
13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
14 #include "gpu/command_buffer/service/texture_manager.h" | 13 #include "gpu/command_buffer/service/texture_manager.h" |
15 #include "gpu/ipc/common/android/surface_texture_peer.h" | 14 #include "gpu/ipc/common/android/surface_texture_peer.h" |
16 #include "gpu/ipc/common/gpu_messages.h" | 15 #include "gpu/ipc/common/gpu_messages.h" |
17 #include "gpu/ipc/service/gpu_channel.h" | 16 #include "gpu/ipc/service/gpu_channel.h" |
18 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
19 #include "ui/gl/gl_context.h" | 18 #include "ui/gl/gl_context.h" |
20 #include "ui/gl/gl_helper.h" | |
21 #include "ui/gl/scoped_binders.h" | |
22 #include "ui/gl/scoped_make_current.h" | 19 #include "ui/gl/scoped_make_current.h" |
23 | 20 |
24 namespace gpu { | 21 namespace gpu { |
25 | 22 |
26 using gles2::ContextGroup; | 23 using gles2::ContextGroup; |
27 using gles2::GLES2Decoder; | 24 using gles2::GLES2Decoder; |
28 using gles2::TextureManager; | 25 using gles2::TextureManager; |
29 using gles2::TextureRef; | 26 using gles2::TextureRef; |
30 | 27 |
31 // static | 28 // static |
(...skipping 29 matching lines...) Expand all Loading... |
61 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, | 58 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, |
62 int32_t route_id, | 59 int32_t route_id, |
63 uint32_t texture_id) | 60 uint32_t texture_id) |
64 : surface_texture_(gl::SurfaceTexture::Create(texture_id)), | 61 : surface_texture_(gl::SurfaceTexture::Create(texture_id)), |
65 size_(0, 0), | 62 size_(0, 0), |
66 has_pending_frame_(false), | 63 has_pending_frame_(false), |
67 owner_stub_(owner_stub), | 64 owner_stub_(owner_stub), |
68 route_id_(route_id), | 65 route_id_(route_id), |
69 has_listener_(false), | 66 has_listener_(false), |
70 texture_id_(texture_id), | 67 texture_id_(texture_id), |
71 framebuffer_(0), | |
72 vertex_shader_(0), | |
73 fragment_shader_(0), | |
74 program_(0), | |
75 vertex_buffer_(0), | |
76 u_xform_location_(-1), | |
77 weak_factory_(this) { | 68 weak_factory_(this) { |
78 owner_stub->AddDestructionObserver(this); | 69 owner_stub->AddDestructionObserver(this); |
79 memset(current_matrix_, 0, sizeof(current_matrix_)); | 70 memset(current_matrix_, 0, sizeof(current_matrix_)); |
80 owner_stub->channel()->AddRoute(route_id, owner_stub->stream_id(), this); | 71 owner_stub->channel()->AddRoute(route_id, owner_stub->stream_id(), this); |
81 surface_texture_->SetFrameAvailableCallback(base::Bind( | 72 surface_texture_->SetFrameAvailableCallback(base::Bind( |
82 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); | 73 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); |
83 } | 74 } |
84 | 75 |
85 StreamTexture::~StreamTexture() { | 76 StreamTexture::~StreamTexture() { |
86 if (owner_stub_) { | 77 if (owner_stub_) { |
87 owner_stub_->RemoveDestructionObserver(this); | 78 owner_stub_->RemoveDestructionObserver(this); |
88 owner_stub_->channel()->RemoveRoute(route_id_); | 79 owner_stub_->channel()->RemoveRoute(route_id_); |
89 } | 80 } |
90 } | 81 } |
91 | 82 |
92 // gpu::gles2::GLStreamTextureMatrix implementation | 83 // gpu::gles2::GLStreamTextureMatrix implementation |
93 void StreamTexture::GetTextureMatrix(float xform[16]) { | 84 void StreamTexture::GetTextureMatrix(float xform[16]) { |
94 if (surface_texture_) { | 85 if (surface_texture_) { |
95 UpdateTexImage(); | 86 UpdateTexImage(); |
96 surface_texture_->GetTransformMatrix(current_matrix_); | 87 surface_texture_->GetTransformMatrix(current_matrix_); |
97 } | 88 } |
98 memcpy(xform, current_matrix_, sizeof(current_matrix_)); | 89 memcpy(xform, current_matrix_, sizeof(current_matrix_)); |
99 YInvertMatrix(xform); | 90 YInvertMatrix(xform); |
100 } | 91 } |
101 | 92 |
102 void StreamTexture::OnWillDestroyStub() { | 93 void StreamTexture::OnWillDestroyStub() { |
103 owner_stub_->RemoveDestructionObserver(this); | 94 owner_stub_->RemoveDestructionObserver(this); |
104 owner_stub_->channel()->RemoveRoute(route_id_); | 95 owner_stub_->channel()->RemoveRoute(route_id_); |
105 | 96 |
106 if (framebuffer_) { | |
107 std::unique_ptr<ui::ScopedMakeCurrent> scoped_make_current( | |
108 MakeStubCurrent()); | |
109 | |
110 glDeleteProgram(program_); | |
111 glDeleteShader(vertex_shader_); | |
112 glDeleteShader(fragment_shader_); | |
113 glDeleteBuffersARB(1, &vertex_buffer_); | |
114 glDeleteFramebuffersEXT(1, &framebuffer_); | |
115 program_ = 0; | |
116 vertex_shader_ = 0; | |
117 fragment_shader_ = 0; | |
118 vertex_buffer_ = 0; | |
119 framebuffer_ = 0; | |
120 u_xform_location_ = -1; | |
121 } | |
122 | |
123 owner_stub_ = NULL; | 97 owner_stub_ = NULL; |
124 | 98 |
125 // If the owner goes away, there is no need to keep the SurfaceTexture around. | 99 // If the owner goes away, there is no need to keep the SurfaceTexture around. |
126 // The GL texture will keep working regardless with the currently bound frame. | 100 // The GL texture will keep working regardless with the currently bound frame. |
127 surface_texture_ = NULL; | 101 surface_texture_ = NULL; |
128 } | 102 } |
129 | 103 |
130 void StreamTexture::Destroy(bool have_context) { | 104 void StreamTexture::Destroy(bool have_context) { |
131 NOTREACHED(); | 105 NOTREACHED(); |
132 } | 106 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 return false; | 247 return false; |
274 } | 248 } |
275 | 249 |
276 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 250 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
277 uint64_t process_tracing_id, | 251 uint64_t process_tracing_id, |
278 const std::string& dump_name) { | 252 const std::string& dump_name) { |
279 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 | 253 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 |
280 } | 254 } |
281 | 255 |
282 } // namespace gpu | 256 } // namespace gpu |
OLD | NEW |