Chromium Code Reviews| Index: content/browser/compositor/gpu_browser_compositor_output_surface_mac.mm |
| diff --git a/content/browser/compositor/gpu_browser_compositor_output_surface_mac.mm b/content/browser/compositor/gpu_browser_compositor_output_surface_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..391f7bae48325ba36e916ef6b4048cb36defe710 |
| --- /dev/null |
| +++ b/content/browser/compositor/gpu_browser_compositor_output_surface_mac.mm |
| @@ -0,0 +1,116 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/compositor/gpu_browser_compositor_output_surface_mac.h" |
| + |
| +#include "base/command_line.h" |
| +#include "components/display_compositor/compositor_overlay_candidate_validator_mac.h" |
| +#include "content/browser/gpu/gpu_data_manager_impl.h" |
| +#include "content/browser/gpu/gpu_surface_tracker.h" |
| +#include "content/common/gpu/client/context_provider_command_buffer.h" |
| +#include "gpu/GLES2/gl2extchromium.h" |
| +#include "gpu/config/gpu_driver_bug_workaround_type.h" |
| +#include "gpu/ipc/client/gpu_process_hosted_ca_layer_tree_params.h" |
| +#include "ui/accelerated_widget_mac/accelerated_widget_mac.h" |
| +#include "ui/base/cocoa/remote_layer_api.h" |
| +#include "ui/base/ui_base_switches.h" |
| +#include "ui/gfx/mac/io_surface.h" |
| + |
| +namespace content { |
| +namespace { |
| +std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
| +CreateOverlayCandidateValidator() { |
| + // Overlays are only supported through the remote layer API. |
| + if (ui::RemoteLayerAPISupported()) { |
| + static bool overlays_disabled_at_command_line = |
| + base::CommandLine::ForCurrentProcess()->HasSwitch( |
|
danakj
2016/05/26 21:33:51
I think I'd rather GPTF did the command line check
ccameron
2016/05/26 22:46:16
Sounds fair -- I've moved this & friends back to G
|
| + switches::kDisableMacOverlays); |
| + const bool ca_layers_disabled = |
| + overlays_disabled_at_command_line || |
| + GpuDataManagerImpl::GetInstance()->IsDriverBugWorkaroundActive( |
| + gpu::DISABLE_OVERLAY_CA_LAYERS); |
| + return base::WrapUnique( |
| + new display_compositor::CompositorOverlayCandidateValidatorMac( |
| + ca_layers_disabled)); |
| + } |
| + return nullptr; |
| +} |
| +} // namespace |
| + |
| +GpuBrowserCompositorOutputSurfaceMac::GpuBrowserCompositorOutputSurfaceMac( |
| + scoped_refptr<ContextProviderCommandBuffer> context, |
| + gpu::SurfaceHandle surface_handle, |
| + scoped_refptr<ui::CompositorVSyncManager> vsync_manager, |
| + base::SingleThreadTaskRunner* task_runner, |
| + gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) |
| + : GpuSurfacelessBrowserCompositorOutputSurface( |
| + context, |
| + surface_handle, |
| + vsync_manager, |
| + task_runner, |
| + CreateOverlayCandidateValidator(), |
| + GL_TEXTURE_RECTANGLE_ARB, |
| + GL_RGBA, |
| + gpu_memory_buffer_manager) {} |
| + |
| +GpuBrowserCompositorOutputSurfaceMac::~GpuBrowserCompositorOutputSurfaceMac() {} |
| + |
| +void GpuBrowserCompositorOutputSurfaceMac::SwapBuffers( |
| + cc::CompositorFrame* frame) { |
| + GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(frame); |
| + |
| + if (should_show_frames_state_ == |
| + SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) { |
| + should_show_frames_state_ = SHOULD_SHOW_FRAMES; |
| + } |
| +} |
| + |
| +void GpuBrowserCompositorOutputSurfaceMac::OnGpuSwapBuffersCompleted( |
| + const std::vector<ui::LatencyInfo>& latency_info, |
| + gfx::SwapResult result, |
| + const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { |
| + if (should_show_frames_state_ == SHOULD_SHOW_FRAMES) { |
| + gfx::AcceleratedWidget native_widget = |
| + content::GpuSurfaceTracker::Get()->AcquireNativeWidget( |
| + params_mac->surface_handle); |
| + ui::AcceleratedWidgetMacGotFrame( |
| + native_widget, params_mac->ca_context_id, |
| + params_mac->fullscreen_low_power_ca_context_valid, |
| + params_mac->fullscreen_low_power_ca_context_id, params_mac->io_surface, |
| + params_mac->pixel_size, params_mac->scale_factor, nullptr, nullptr); |
| + } |
| + GpuSurfacelessBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( |
| + latency_info, result, params_mac); |
| +} |
| + |
| +void GpuBrowserCompositorOutputSurfaceMac::SetSurfaceSuspendedForRecycle( |
| + bool suspended) { |
| + if (suspended) { |
| + // It may be that there are frames in-flight from the GPU process back to |
| + // the browser. Make sure that these frames are not displayed by ignoring |
| + // them in GpuProcessHostUIShim, until the browser issues a SwapBuffers for |
| + // the new content. |
| + should_show_frames_state_ = SHOULD_NOT_SHOW_FRAMES_SUSPENDED; |
| + } else { |
| + // Discard the backbuffer before drawing the new frame. This is necessary |
| + // only when using a ImageTransportSurfaceFBO with a |
| + // CALayerStorageProvider. Discarding the backbuffer results in the next |
| + // frame using a new CALayer and CAContext, which guarantees that the |
| + // browser will not flash stale content when adding the remote CALayer to |
| + // the NSView hierarchy (it could flash stale content because the system |
| + // window server is not synchronized with any signals we control or |
| + // observe). |
| + if (should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED) { |
| + DiscardBackbuffer(); |
| + should_show_frames_state_ = |
| + SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED; |
| + } |
| + } |
| +} |
| + |
| +bool GpuBrowserCompositorOutputSurfaceMac::SurfaceIsSuspendForRecycle() const { |
| + return should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED; |
| +} |
| + |
| +} // namespace content |