OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/image_transport_surface.h" | 5 #include "content/common/gpu/image_transport_surface.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 void ImageTransportHelper::SetLatencyInfo( | 180 void ImageTransportHelper::SetLatencyInfo( |
181 const std::vector<ui::LatencyInfo>& latency_info) { | 181 const std::vector<ui::LatencyInfo>& latency_info) { |
182 surface_->SetLatencyInfo(latency_info); | 182 surface_->SetLatencyInfo(latency_info); |
183 } | 183 } |
184 | 184 |
185 PassThroughImageTransportSurface::PassThroughImageTransportSurface( | 185 PassThroughImageTransportSurface::PassThroughImageTransportSurface( |
186 GpuChannelManager* manager, | 186 GpuChannelManager* manager, |
187 GpuCommandBufferStub* stub, | 187 GpuCommandBufferStub* stub, |
188 gfx::GLSurface* surface) | 188 gfx::GLSurface* surface) |
189 : GLSurfaceAdapter(surface), | 189 : GLSurfaceAdapter(surface), |
190 did_set_swap_interval_(false) { | 190 did_set_swap_interval_(false), |
| 191 weak_ptr_factory_(this) { |
191 helper_.reset(new ImageTransportHelper(this, | 192 helper_.reset(new ImageTransportHelper(this, |
192 manager, | 193 manager, |
193 stub, | 194 stub, |
194 gfx::kNullPluginWindow)); | 195 gfx::kNullPluginWindow)); |
195 } | 196 } |
196 | 197 |
197 bool PassThroughImageTransportSurface::Initialize() { | 198 bool PassThroughImageTransportSurface::Initialize() { |
198 // The surface is assumed to have already been initialized. | 199 // The surface is assumed to have already been initialized. |
199 return helper_->Initialize(); | 200 return helper_->Initialize(); |
200 } | 201 } |
201 | 202 |
202 void PassThroughImageTransportSurface::Destroy() { | 203 void PassThroughImageTransportSurface::Destroy() { |
203 GLSurfaceAdapter::Destroy(); | 204 GLSurfaceAdapter::Destroy(); |
204 } | 205 } |
205 | 206 |
206 void PassThroughImageTransportSurface::SetLatencyInfo( | 207 void PassThroughImageTransportSurface::SetLatencyInfo( |
207 const std::vector<ui::LatencyInfo>& latency_info) { | 208 const std::vector<ui::LatencyInfo>& latency_info) { |
208 for (size_t i = 0; i < latency_info.size(); i++) | 209 for (size_t i = 0; i < latency_info.size(); i++) |
209 latency_info_.push_back(latency_info[i]); | 210 latency_info_.push_back(latency_info[i]); |
210 } | 211 } |
211 | 212 |
212 bool PassThroughImageTransportSurface::SwapBuffers() { | 213 bool PassThroughImageTransportSurface::SwapBuffers() { |
213 // GetVsyncValues before SwapBuffers to work around Mali driver bug: | 214 // GetVsyncValues before SwapBuffers to work around Mali driver bug: |
214 // crbug.com/223558. | 215 // crbug.com/223558. |
215 SendVSyncUpdateIfAvailable(); | 216 SendVSyncUpdateIfAvailable(); |
216 bool result = gfx::GLSurfaceAdapter::SwapBuffers(); | 217 // We use WeakPtr here to avoid manual management of life time of an instance |
217 for (size_t i = 0; i < latency_info_.size(); i++) { | 218 // of this class. Callback will not be called once the instance of this class |
218 latency_info_[i].AddLatencyNumber( | 219 // is destroyed. However, this also means that the callback can be run on |
219 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); | 220 // the calling thread only. |
220 } | 221 return gfx::GLSurfaceAdapter::SwapBuffersAsync( |
221 | 222 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, |
222 helper_->SwapBuffersCompleted(latency_info_); | 223 weak_ptr_factory_.GetWeakPtr())); |
223 latency_info_.clear(); | |
224 return result; | |
225 } | 224 } |
226 | 225 |
227 bool PassThroughImageTransportSurface::PostSubBuffer( | 226 bool PassThroughImageTransportSurface::PostSubBuffer( |
228 int x, int y, int width, int height) { | 227 int x, int y, int width, int height) { |
229 SendVSyncUpdateIfAvailable(); | 228 SendVSyncUpdateIfAvailable(); |
230 bool result = gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height); | 229 // We use WeakPtr here to avoid manual management of life time of an instance |
| 230 // of this class. Callback will not be called once the instance of this class |
| 231 // is destroyed. However, this also means that the callback can be run on |
| 232 // the calling thread only. |
| 233 return gfx::GLSurfaceAdapter::PostSubBufferAsync(x, y, width, height, |
| 234 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, |
| 235 weak_ptr_factory_.GetWeakPtr())); |
| 236 } |
| 237 |
| 238 void PassThroughImageTransportSurface::SwapBuffersCallBack() { |
231 for (size_t i = 0; i < latency_info_.size(); i++) { | 239 for (size_t i = 0; i < latency_info_.size(); i++) { |
232 latency_info_[i].AddLatencyNumber( | 240 latency_info_[i].AddLatencyNumber( |
233 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); | 241 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); |
234 } | 242 } |
235 | 243 |
236 helper_->SwapBuffersCompleted(latency_info_); | 244 helper_->SwapBuffersCompleted(latency_info_); |
237 latency_info_.clear(); | 245 latency_info_.clear(); |
238 return result; | |
239 } | 246 } |
240 | 247 |
241 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 248 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
242 if (!did_set_swap_interval_) { | 249 if (!did_set_swap_interval_) { |
243 ImageTransportHelper::SetSwapInterval(context); | 250 ImageTransportHelper::SetSwapInterval(context); |
244 did_set_swap_interval_ = true; | 251 did_set_swap_interval_ = true; |
245 } | 252 } |
246 return true; | 253 return true; |
247 } | 254 } |
248 | 255 |
(...skipping 22 matching lines...) Expand all Loading... |
271 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 278 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
272 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 279 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
273 if (vsync_provider) { | 280 if (vsync_provider) { |
274 vsync_provider->GetVSyncParameters( | 281 vsync_provider->GetVSyncParameters( |
275 base::Bind(&ImageTransportHelper::SendUpdateVSyncParameters, | 282 base::Bind(&ImageTransportHelper::SendUpdateVSyncParameters, |
276 helper_->AsWeakPtr())); | 283 helper_->AsWeakPtr())); |
277 } | 284 } |
278 } | 285 } |
279 | 286 |
280 } // namespace content | 287 } // namespace content |
OLD | NEW |