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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 } | 209 } |
210 | 210 |
211 void ImageTransportHelper::SetLatencyInfo( | 211 void ImageTransportHelper::SetLatencyInfo( |
212 const std::vector<ui::LatencyInfo>& latency_info) { | 212 const std::vector<ui::LatencyInfo>& latency_info) { |
213 surface_->SetLatencyInfo(latency_info); | 213 surface_->SetLatencyInfo(latency_info); |
214 } | 214 } |
215 | 215 |
216 PassThroughImageTransportSurface::PassThroughImageTransportSurface( | 216 PassThroughImageTransportSurface::PassThroughImageTransportSurface( |
217 GpuChannelManager* manager, | 217 GpuChannelManager* manager, |
218 GpuCommandBufferStub* stub, | 218 GpuCommandBufferStub* stub, |
219 gfx::GLSurface* surface, | 219 gfx::GLSurface* surface) |
220 bool transport) | |
221 : GLSurfaceAdapter(surface), | 220 : GLSurfaceAdapter(surface), |
222 transport_(transport), | 221 did_set_swap_interval_(false) { |
223 did_set_swap_interval_(false), | |
224 did_unschedule_(false), | |
225 is_swap_buffers_pending_(false) { | |
226 helper_.reset(new ImageTransportHelper(this, | 222 helper_.reset(new ImageTransportHelper(this, |
227 manager, | 223 manager, |
228 stub, | 224 stub, |
229 gfx::kNullPluginWindow)); | 225 gfx::kNullPluginWindow)); |
230 } | 226 } |
231 | 227 |
232 bool PassThroughImageTransportSurface::Initialize() { | 228 bool PassThroughImageTransportSurface::Initialize() { |
233 // The surface is assumed to have already been initialized. | 229 // The surface is assumed to have already been initialized. |
234 return helper_->Initialize(); | 230 return helper_->Initialize(); |
235 } | 231 } |
236 | 232 |
237 void PassThroughImageTransportSurface::Destroy() { | 233 void PassThroughImageTransportSurface::Destroy() { |
238 helper_->Destroy(); | 234 helper_->Destroy(); |
239 GLSurfaceAdapter::Destroy(); | 235 GLSurfaceAdapter::Destroy(); |
240 } | 236 } |
241 | 237 |
242 bool PassThroughImageTransportSurface::DeferDraws() { | |
243 if (is_swap_buffers_pending_) { | |
244 DCHECK(!did_unschedule_); | |
245 did_unschedule_ = true; | |
246 helper_->SetScheduled(false); | |
247 return true; | |
248 } | |
249 return false; | |
250 } | |
251 | |
252 void PassThroughImageTransportSurface::SetLatencyInfo( | 238 void PassThroughImageTransportSurface::SetLatencyInfo( |
253 const std::vector<ui::LatencyInfo>& latency_info) { | 239 const std::vector<ui::LatencyInfo>& latency_info) { |
254 for (size_t i = 0; i < latency_info.size(); i++) | 240 for (size_t i = 0; i < latency_info.size(); i++) |
255 latency_info_.push_back(latency_info[i]); | 241 latency_info_.push_back(latency_info[i]); |
256 } | 242 } |
257 | 243 |
258 bool PassThroughImageTransportSurface::SwapBuffers() { | 244 bool PassThroughImageTransportSurface::SwapBuffers() { |
259 // GetVsyncValues before SwapBuffers to work around Mali driver bug: | 245 // GetVsyncValues before SwapBuffers to work around Mali driver bug: |
260 // crbug.com/223558. | 246 // crbug.com/223558. |
261 SendVSyncUpdateIfAvailable(); | 247 SendVSyncUpdateIfAvailable(); |
262 bool result = gfx::GLSurfaceAdapter::SwapBuffers(); | 248 bool result = gfx::GLSurfaceAdapter::SwapBuffers(); |
263 for (size_t i = 0; i < latency_info_.size(); i++) { | 249 for (size_t i = 0; i < latency_info_.size(); i++) { |
264 latency_info_[i].AddLatencyNumber( | 250 latency_info_[i].AddLatencyNumber( |
265 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); | 251 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); |
266 } | 252 } |
267 | 253 |
268 if (transport_) { | 254 helper_->SendLatencyInfo(latency_info_); |
269 DCHECK(!is_swap_buffers_pending_); | |
270 is_swap_buffers_pending_ = true; | |
271 | |
272 // Round trip to the browser UI thread, for throttling, by sending a dummy | |
273 // SwapBuffers message. | |
274 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
275 params.surface_handle = 0; | |
276 params.latency_info.swap(latency_info_); | |
277 params.size = surface()->GetSize(); | |
278 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | |
279 } else { | |
280 helper_->SendLatencyInfo(latency_info_); | |
281 } | |
282 latency_info_.clear(); | 255 latency_info_.clear(); |
283 return result; | 256 return result; |
284 } | 257 } |
285 | 258 |
286 bool PassThroughImageTransportSurface::PostSubBuffer( | 259 bool PassThroughImageTransportSurface::PostSubBuffer( |
287 int x, int y, int width, int height) { | 260 int x, int y, int width, int height) { |
288 SendVSyncUpdateIfAvailable(); | 261 SendVSyncUpdateIfAvailable(); |
289 bool result = gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height); | 262 bool result = gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height); |
290 for (size_t i = 0; i < latency_info_.size(); i++) { | 263 for (size_t i = 0; i < latency_info_.size(); i++) { |
291 latency_info_[i].AddLatencyNumber( | 264 latency_info_[i].AddLatencyNumber( |
292 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); | 265 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); |
293 } | 266 } |
294 | 267 |
295 if (transport_) { | 268 helper_->SendLatencyInfo(latency_info_); |
296 DCHECK(!is_swap_buffers_pending_); | |
297 is_swap_buffers_pending_ = true; | |
298 | |
299 // Round trip to the browser UI thread, for throttling, by sending a dummy | |
300 // PostSubBuffer message. | |
301 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; | |
302 params.surface_handle = 0; | |
303 params.latency_info.swap(latency_info_); | |
304 params.surface_size = surface()->GetSize(); | |
305 params.x = x; | |
306 params.y = y; | |
307 params.width = width; | |
308 params.height = height; | |
309 helper_->SendAcceleratedSurfacePostSubBuffer(params); | |
310 | |
311 helper_->SetScheduled(false); | |
312 } else { | |
313 helper_->SendLatencyInfo(latency_info_); | |
314 } | |
315 latency_info_.clear(); | 269 latency_info_.clear(); |
316 return result; | 270 return result; |
317 } | 271 } |
318 | 272 |
319 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 273 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
320 if (!did_set_swap_interval_) { | 274 if (!did_set_swap_interval_) { |
321 ImageTransportHelper::SetSwapInterval(context); | 275 ImageTransportHelper::SetSwapInterval(context); |
322 did_set_swap_interval_ = true; | 276 did_set_swap_interval_ = true; |
323 } | 277 } |
324 return true; | 278 return true; |
325 } | 279 } |
326 | 280 |
327 void PassThroughImageTransportSurface::OnBufferPresented( | 281 void PassThroughImageTransportSurface::OnBufferPresented( |
328 const AcceleratedSurfaceMsg_BufferPresented_Params& /* params */) { | 282 const AcceleratedSurfaceMsg_BufferPresented_Params& /* params */) { |
329 DCHECK(transport_); | 283 NOTREACHED(); |
330 DCHECK(is_swap_buffers_pending_); | |
331 is_swap_buffers_pending_ = false; | |
332 if (did_unschedule_) { | |
333 did_unschedule_ = false; | |
334 helper_->SetScheduled(true); | |
335 } | |
336 } | 284 } |
337 | 285 |
338 void PassThroughImageTransportSurface::OnResizeViewACK() { | 286 void PassThroughImageTransportSurface::OnResizeViewACK() { |
339 DCHECK(transport_); | 287 NOTREACHED(); |
340 Resize(new_size_); | |
341 | |
342 TRACE_EVENT_ASYNC_END0("gpu", "OnResize", this); | |
343 helper_->SetScheduled(true); | |
344 } | 288 } |
345 | 289 |
346 void PassThroughImageTransportSurface::OnResize(gfx::Size size, | 290 void PassThroughImageTransportSurface::OnResize(gfx::Size size, |
347 float scale_factor) { | 291 float scale_factor) { |
348 new_size_ = size; | 292 Resize(size); |
349 | |
350 if (transport_) { | |
351 helper_->SendResizeView(size); | |
no sievers
2014/04/25 17:51:00
ImageTransportHelper::SendResizeView(), GpuHostMsg
| |
352 helper_->SetScheduled(false); | |
353 TRACE_EVENT_ASYNC_BEGIN2("gpu", "OnResize", this, | |
354 "width", size.width(), "height", size.height()); | |
355 } else { | |
356 Resize(new_size_); | |
357 } | |
358 } | 293 } |
359 | 294 |
360 gfx::Size PassThroughImageTransportSurface::GetSize() { | 295 gfx::Size PassThroughImageTransportSurface::GetSize() { |
361 return GLSurfaceAdapter::GetSize(); | 296 return GLSurfaceAdapter::GetSize(); |
362 } | 297 } |
363 | 298 |
364 void PassThroughImageTransportSurface::WakeUpGpu() { | 299 void PassThroughImageTransportSurface::WakeUpGpu() { |
365 NOTIMPLEMENTED(); | 300 NOTIMPLEMENTED(); |
366 } | 301 } |
367 | 302 |
368 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} | 303 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} |
369 | 304 |
370 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 305 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
371 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 306 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
372 if (vsync_provider) { | 307 if (vsync_provider) { |
373 vsync_provider->GetVSyncParameters( | 308 vsync_provider->GetVSyncParameters( |
374 base::Bind(&ImageTransportHelper::SendUpdateVSyncParameters, | 309 base::Bind(&ImageTransportHelper::SendUpdateVSyncParameters, |
375 helper_->AsWeakPtr())); | 310 helper_->AsWeakPtr())); |
376 } | 311 } |
377 } | 312 } |
378 | 313 |
379 } // namespace content | 314 } // namespace content |
OLD | NEW |