| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/compositor/gpu_browser_compositor_output_surface.h" | 5 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/output_surface_client.h" | 11 #include "cc/output/output_surface_client.h" |
| 12 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" | 12 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" |
| 13 #include "content/browser/compositor/reflector_impl.h" | 13 #include "content/browser/compositor/reflector_impl.h" |
| 14 #include "content/browser/compositor/reflector_texture.h" | 14 #include "content/browser/compositor/reflector_texture.h" |
| 15 #include "content/browser/renderer_host/render_widget_host_impl.h" | 15 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 16 #include "content/common/gpu/client/context_provider_command_buffer.h" | 16 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 17 #include "gpu/command_buffer/client/context_support.h" | 17 #include "gpu/command_buffer/client/context_support.h" |
| 18 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 18 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 19 | 19 |
| 20 #if defined(OS_MACOSX) | |
| 21 #include "content/browser/gpu/gpu_surface_tracker.h" | |
| 22 #include "gpu/ipc/client/gpu_process_hosted_ca_layer_tree_params.h" | |
| 23 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" | |
| 24 #endif | |
| 25 | |
| 26 namespace content { | 20 namespace content { |
| 27 | 21 |
| 28 GpuBrowserCompositorOutputSurface::GpuBrowserCompositorOutputSurface( | 22 GpuBrowserCompositorOutputSurface::GpuBrowserCompositorOutputSurface( |
| 29 scoped_refptr<ContextProviderCommandBuffer> context, | 23 scoped_refptr<ContextProviderCommandBuffer> context, |
| 30 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, | 24 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, |
| 31 base::SingleThreadTaskRunner* task_runner, | 25 base::SingleThreadTaskRunner* task_runner, |
| 32 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 26 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
| 33 overlay_candidate_validator) | 27 overlay_candidate_validator) |
| 34 : BrowserCompositorOutputSurface(std::move(context), | 28 : BrowserCompositorOutputSurface(std::move(context), |
| 35 std::move(vsync_manager), | 29 std::move(vsync_manager), |
| 36 task_runner, | 30 task_runner, |
| 37 std::move(overlay_candidate_validator)), | 31 std::move(overlay_candidate_validator)), |
| 38 #if defined(OS_MACOSX) | |
| 39 should_show_frames_state_(SHOULD_SHOW_FRAMES), | |
| 40 #endif | |
| 41 swap_buffers_completion_callback_(base::Bind( | 32 swap_buffers_completion_callback_(base::Bind( |
| 42 &GpuBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted, | 33 &GpuBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted, |
| 43 base::Unretained(this))), | 34 base::Unretained(this))), |
| 44 update_vsync_parameters_callback_(base::Bind( | 35 update_vsync_parameters_callback_(base::Bind( |
| 45 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu, | 36 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu, |
| 46 base::Unretained(this))) { | 37 base::Unretained(this))) { |
| 47 } | 38 } |
| 48 | 39 |
| 49 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() {} | 40 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() {} |
| 50 | 41 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 95 |
| 105 if (frame->gl_frame_data->sub_buffer_rect == | 96 if (frame->gl_frame_data->sub_buffer_rect == |
| 106 gfx::Rect(frame->gl_frame_data->size)) { | 97 gfx::Rect(frame->gl_frame_data->size)) { |
| 107 context_provider_->ContextSupport()->Swap(); | 98 context_provider_->ContextSupport()->Swap(); |
| 108 } else { | 99 } else { |
| 109 context_provider_->ContextSupport()->PartialSwapBuffers( | 100 context_provider_->ContextSupport()->PartialSwapBuffers( |
| 110 frame->gl_frame_data->sub_buffer_rect); | 101 frame->gl_frame_data->sub_buffer_rect); |
| 111 } | 102 } |
| 112 | 103 |
| 113 client_->DidSwapBuffers(); | 104 client_->DidSwapBuffers(); |
| 114 | |
| 115 #if defined(OS_MACOSX) | |
| 116 if (should_show_frames_state_ == | |
| 117 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) { | |
| 118 should_show_frames_state_ = SHOULD_SHOW_FRAMES; | |
| 119 } | |
| 120 #endif | |
| 121 } | 105 } |
| 122 | 106 |
| 123 void GpuBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( | 107 void GpuBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( |
| 124 const std::vector<ui::LatencyInfo>& latency_info, | 108 const std::vector<ui::LatencyInfo>& latency_info, |
| 125 gfx::SwapResult result, | 109 gfx::SwapResult result, |
| 126 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { | 110 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { |
| 127 #if defined(OS_MACOSX) | |
| 128 if (should_show_frames_state_ == SHOULD_SHOW_FRAMES) { | |
| 129 gfx::AcceleratedWidget native_widget = | |
| 130 content::GpuSurfaceTracker::Get()->AcquireNativeWidget( | |
| 131 params_mac->surface_handle); | |
| 132 ui::AcceleratedWidgetMacGotFrame( | |
| 133 native_widget, params_mac->ca_context_id, | |
| 134 params_mac->fullscreen_low_power_ca_context_valid, | |
| 135 params_mac->fullscreen_low_power_ca_context_id, params_mac->io_surface, | |
| 136 params_mac->pixel_size, params_mac->scale_factor, nullptr, nullptr); | |
| 137 } | |
| 138 #endif | |
| 139 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | 111 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); |
| 140 OnSwapBuffersComplete(); | 112 OnSwapBuffersComplete(); |
| 141 } | 113 } |
| 142 | 114 |
| 143 #if defined(OS_MACOSX) | 115 #if defined(OS_MACOSX) |
| 144 void GpuBrowserCompositorOutputSurface::SetSurfaceSuspendedForRecycle( | 116 void GpuBrowserCompositorOutputSurface::SetSurfaceSuspendedForRecycle( |
| 145 bool suspended) { | 117 bool suspended) {} |
| 146 if (suspended) { | |
| 147 // It may be that there are frames in-flight from the GPU process back to | |
| 148 // the browser. Make sure that these frames are not displayed by ignoring | |
| 149 // them in GpuProcessHostUIShim, until the browser issues a SwapBuffers for | |
| 150 // the new content. | |
| 151 should_show_frames_state_ = SHOULD_NOT_SHOW_FRAMES_SUSPENDED; | |
| 152 } else { | |
| 153 // Discard the backbuffer before drawing the new frame. This is necessary | |
| 154 // only when using a ImageTransportSurfaceFBO with a | |
| 155 // CALayerStorageProvider. Discarding the backbuffer results in the next | |
| 156 // frame using a new CALayer and CAContext, which guarantees that the | |
| 157 // browser will not flash stale content when adding the remote CALayer to | |
| 158 // the NSView hierarchy (it could flash stale content because the system | |
| 159 // window server is not synchronized with any signals we control or | |
| 160 // observe). | |
| 161 if (should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED) { | |
| 162 DiscardBackbuffer(); | |
| 163 should_show_frames_state_ = | |
| 164 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED; | |
| 165 } | |
| 166 } | |
| 167 } | |
| 168 #endif | 118 #endif |
| 169 | 119 |
| 170 bool GpuBrowserCompositorOutputSurface::SurfaceIsSuspendForRecycle() const { | |
| 171 #if defined(OS_MACOSX) | |
| 172 return should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED; | |
| 173 #else | |
| 174 return false; | |
| 175 #endif | |
| 176 } | |
| 177 | |
| 178 } // namespace content | 120 } // namespace content |
| OLD | NEW |