Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: content/renderer/gpu/transport_texture_host.cc

Issue 8554001: base::Bind: Convert content/renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test fix. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <GLES2/gl2.h> 5 #include <GLES2/gl2.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "content/renderer/gpu/transport_texture_host.h" 9 #include "content/renderer/gpu/transport_texture_host.h"
10 10
11 // On Mac gl2.h clashes with gpu_messages.h and this problem hasn't been 11 // On Mac gl2.h clashes with gpu_messages.h and this problem hasn't been
12 // solved yet so exclude building on Mac. 12 // solved yet so exclude building on Mac.
13 #if !defined(OS_MACOSX) 13 #if !defined(OS_MACOSX)
14 14
15 #include "base/bind.h"
15 #include "base/message_loop.h" 16 #include "base/message_loop.h"
16 #include "content/common/gpu/gpu_messages.h" 17 #include "content/common/gpu/gpu_messages.h"
17 #include "content/renderer/gpu/renderer_gl_context.h" 18 #include "content/renderer/gpu/renderer_gl_context.h"
18 #include "content/renderer/gpu/transport_texture_service.h" 19 #include "content/renderer/gpu/transport_texture_service.h"
19 20
20 TransportTextureHost::TransportTextureHost(MessageLoop* io_message_loop, 21 TransportTextureHost::TransportTextureHost(MessageLoop* io_message_loop,
21 MessageLoop* render_message_loop, 22 MessageLoop* render_message_loop,
22 TransportTextureService* service, 23 TransportTextureService* service,
23 IPC::Message::Sender* sender, 24 IPC::Message::Sender* sender,
24 RendererGLContext* context, 25 RendererGLContext* context,
25 int32 context_route_id, 26 int32 context_route_id,
26 int32 host_id) 27 int32 host_id)
27 : io_message_loop_(io_message_loop), 28 : io_message_loop_(io_message_loop),
28 render_message_loop_(render_message_loop), 29 render_message_loop_(render_message_loop),
29 service_(service), 30 service_(service),
30 sender_(sender), 31 sender_(sender),
31 context_(context), 32 context_(context),
32 context_route_id_(context_route_id), 33 context_route_id_(context_route_id),
33 host_id_(host_id), 34 host_id_(host_id),
34 peer_id_(0) { 35 peer_id_(0) {
35 } 36 }
36 37
37 TransportTextureHost::~TransportTextureHost() { 38 TransportTextureHost::~TransportTextureHost() {
38 } 39 }
39 40
40 void TransportTextureHost::Init(Task* done_task) { 41 void TransportTextureHost::Init(Task* done_task) {
41 if (MessageLoop::current() != io_message_loop_) { 42 if (MessageLoop::current() != io_message_loop_) {
42 io_message_loop_->PostTask( 43 io_message_loop_->PostTask(
43 FROM_HERE, 44 FROM_HERE,
44 NewRunnableMethod(this, &TransportTextureHost::Init, done_task)); 45 base::Bind(&TransportTextureHost::Init, this, done_task));
45 return; 46 return;
46 } 47 }
47 48
48 init_task_.reset(done_task); 49 init_task_.reset(done_task);
49 50
50 // Send the message. 51 // Send the message.
51 bool ret = sender_->Send( 52 bool ret = sender_->Send(
52 new GpuChannelMsg_CreateTransportTexture(context_route_id_, host_id_)); 53 new GpuChannelMsg_CreateTransportTexture(context_route_id_, host_id_));
53 if (!ret) { 54 if (!ret) {
54 LOG(ERROR) << "GpuChannelMsg_CreateTransportTexture failed"; 55 LOG(ERROR) << "GpuChannelMsg_CreateTransportTexture failed";
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 IPC_MESSAGE_UNHANDLED(handled = false) 96 IPC_MESSAGE_UNHANDLED(handled = false)
96 IPC_END_MESSAGE_MAP() 97 IPC_END_MESSAGE_MAP()
97 DCHECK(handled); 98 DCHECK(handled);
98 return handled; 99 return handled;
99 } 100 }
100 101
101 void TransportTextureHost::ReleaseTexturesInternal() { 102 void TransportTextureHost::ReleaseTexturesInternal() {
102 if (MessageLoop::current() != render_message_loop_) { 103 if (MessageLoop::current() != render_message_loop_) {
103 render_message_loop_->PostTask( 104 render_message_loop_->PostTask(
104 FROM_HERE, 105 FROM_HERE,
105 NewRunnableMethod(this, 106 base::Bind(&TransportTextureHost::ReleaseTexturesInternal, this));
106 &TransportTextureHost::ReleaseTexturesInternal));
107 return; 107 return;
108 } 108 }
109 109
110 scoped_array<GLuint> textures(new GLuint[textures_.size()]); 110 scoped_array<GLuint> textures(new GLuint[textures_.size()]);
111 for (size_t i = 0; i < textures_.size(); ++i) 111 for (size_t i = 0; i < textures_.size(); ++i)
112 textures[i] = textures_[i]; 112 textures[i] = textures_[i];
113 glDeleteTextures(textures_.size(), textures.get()); 113 glDeleteTextures(textures_.size(), textures.get());
114 } 114 }
115 115
116 void TransportTextureHost::SendTexturesInternal( 116 void TransportTextureHost::SendTexturesInternal(
117 const std::vector<int>& textures) { 117 const std::vector<int>& textures) {
118 if (MessageLoop::current() != io_message_loop_) { 118 if (MessageLoop::current() != io_message_loop_) {
119 io_message_loop_->PostTask( 119 io_message_loop_->PostTask(
120 FROM_HERE, 120 FROM_HERE,
121 NewRunnableMethod(this, &TransportTextureHost::SendTexturesInternal, 121 base::Bind(&TransportTextureHost::SendTexturesInternal, this,
122 textures)); 122 textures));
123 return; 123 return;
124 } 124 }
125 125
126 bool ret = sender_->Send( 126 bool ret = sender_->Send(
127 new GpuTransportTextureMsg_TexturesCreated(peer_id_, textures)); 127 new GpuTransportTextureMsg_TexturesCreated(peer_id_, textures));
128 if (!ret) { 128 if (!ret) {
129 LOG(ERROR) << "GpuTransportTextureMsg_TexturesCreated failed"; 129 LOG(ERROR) << "GpuTransportTextureMsg_TexturesCreated failed";
130 } 130 }
131 } 131 }
132 132
133 void TransportTextureHost::SendDestroyInternal() { 133 void TransportTextureHost::SendDestroyInternal() {
134 if (MessageLoop::current() != io_message_loop_) { 134 if (MessageLoop::current() != io_message_loop_) {
135 io_message_loop_->PostTask( 135 io_message_loop_->PostTask(
136 FROM_HERE, 136 FROM_HERE,
137 NewRunnableMethod(this, &TransportTextureHost::SendDestroyInternal)); 137 base::Bind(&TransportTextureHost::SendDestroyInternal, this));
138 return; 138 return;
139 } 139 }
140 140
141 bool ret = sender_->Send(new GpuTransportTextureMsg_Destroy(peer_id_)); 141 bool ret = sender_->Send(new GpuTransportTextureMsg_Destroy(peer_id_));
142 if (!ret) { 142 if (!ret) {
143 LOG(ERROR) << "GpuTransportTextureMsg_Destroy failed"; 143 LOG(ERROR) << "GpuTransportTextureMsg_Destroy failed";
144 } 144 }
145 } 145 }
146 146
147 void TransportTextureHost::OnTransportTextureCreated(int32 peer_id) { 147 void TransportTextureHost::OnTransportTextureCreated(int32 peer_id) {
148 DCHECK_EQ(io_message_loop_, MessageLoop::current()); 148 DCHECK_EQ(io_message_loop_, MessageLoop::current());
149 149
150 peer_id_ = peer_id; 150 peer_id_ = peer_id;
151 init_task_->Run(); 151 init_task_->Run();
152 init_task_.reset(); 152 init_task_.reset();
153 } 153 }
154 154
155 void TransportTextureHost::OnCreateTextures(int32 n, uint32 width, 155 void TransportTextureHost::OnCreateTextures(int32 n, uint32 width,
156 uint32 height, int32 format) { 156 uint32 height, int32 format) {
157 if (MessageLoop::current() != render_message_loop_) { 157 if (MessageLoop::current() != render_message_loop_) {
158 render_message_loop_->PostTask( 158 render_message_loop_->PostTask(
159 FROM_HERE, 159 FROM_HERE,
160 NewRunnableMethod(this, &TransportTextureHost::OnCreateTextures, 160 base::Bind(&TransportTextureHost::OnCreateTextures, this, n, width,
161 n, width, height, format)); 161 height, format));
162 return; 162 return;
163 } 163 }
164 164
165 // In this method we need to make the ggl context current and then generate 165 // In this method we need to make the ggl context current and then generate
166 // textures for each video frame. We also need to allocate memory for each 166 // textures for each video frame. We also need to allocate memory for each
167 // texture generated. 167 // texture generated.
168 bool ret = RendererGLContext::MakeCurrent(context_); 168 bool ret = RendererGLContext::MakeCurrent(context_);
169 CHECK(ret) << "Failed to switch context"; 169 CHECK(ret) << "Failed to switch context";
170 170
171 // TODO(hclam): Should do this through TextureManager instead of generating 171 // TODO(hclam): Should do this through TextureManager instead of generating
(...skipping 13 matching lines...) Expand all
185 // This method will switch thread properly so just call it directly. 185 // This method will switch thread properly so just call it directly.
186 ReleaseTexturesInternal(); 186 ReleaseTexturesInternal();
187 } 187 }
188 188
189 void TransportTextureHost::OnTextureUpdated(int texture_id) { 189 void TransportTextureHost::OnTextureUpdated(int texture_id) {
190 if (update_callback_.get()) 190 if (update_callback_.get())
191 update_callback_->Run(texture_id); 191 update_callback_->Run(texture_id);
192 } 192 }
193 193
194 #endif 194 #endif
OLDNEW
« no previous file with comments | « content/renderer/gpu/transport_texture_host.h ('k') | content/renderer/gpu/transport_texture_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698