Chromium Code Reviews| Index: gpu/ipc/service/image_transport_surface_overlay_mac.mm |
| diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.mm b/gpu/ipc/service/image_transport_surface_overlay_mac.mm |
| index 8f4e73002298232de83d01a6894e06c9d82fb39a..141184e173a77001a53b001c88cfa84407ccd4ba 100644 |
| --- a/gpu/ipc/service/image_transport_surface_overlay_mac.mm |
| +++ b/gpu/ipc/service/image_transport_surface_overlay_mac.mm |
| @@ -157,10 +157,30 @@ gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal( |
| const gfx::Rect& pixel_damage_rect) { |
| TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal"); |
| - // A glFlush is necessary to ensure correct content appears. A glFinish |
| - // appears empirically to be the best way to get maximum performance when |
| - // GPU bound. |
| - { |
| + // If supported, use GLFence to ensure that we haven't gotten more than one |
| + // frame ahead of GL. |
| + if (gl::GLFence::IsSupported()) { |
| + // If we have gotten more than one frame ahead of GL, wait for the previous |
| + // frame to complete. |
| + if (previous_frame_fence_) { |
| + TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::ClientWait"); |
| + previous_frame_fence_->ClientWait(); |
|
ccameron
2016/06/01 21:26:37
This will cause the CPU to spin up to 100% on Mac.
|
| + previous_frame_fence_ = nullptr; |
| + } |
| + |
| + // A glFlush is necessary to ensure correct content appears. |
| + { |
| + gl::ScopedSetGLToRealGLApi scoped_set_gl_api; |
| + CheckGLErrors("Before flush"); |
| + glFlush(); |
| + CheckGLErrors("After flush"); |
| + } |
| + |
| + // Create a new fence after flushing work from the current frame. |
| + previous_frame_fence_.reset(gl::GLFence::Create()); |
| + } else { |
| + // GLFence isn't supported - issue a glFinish on each frame to ensure |
| + // there is backpressure from GL. |
| gl::ScopedSetGLToRealGLApi scoped_set_gl_api; |
| TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFinish"); |
| CheckGLErrors("Before finish"); |