Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/compositor/gpu_browser_compositor_output_surface_mac.h " | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "components/display_compositor/compositor_overlay_candidate_validator_m ac.h" | |
| 9 #include "content/browser/gpu/gpu_data_manager_impl.h" | |
| 10 #include "content/browser/gpu/gpu_surface_tracker.h" | |
| 11 #include "content/common/gpu/client/context_provider_command_buffer.h" | |
| 12 #include "gpu/GLES2/gl2extchromium.h" | |
| 13 #include "gpu/config/gpu_driver_bug_workaround_type.h" | |
| 14 #include "gpu/ipc/client/gpu_process_hosted_ca_layer_tree_params.h" | |
| 15 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" | |
| 16 #include "ui/base/cocoa/remote_layer_api.h" | |
| 17 #include "ui/base/ui_base_switches.h" | |
| 18 #include "ui/gfx/mac/io_surface.h" | |
| 19 | |
| 20 namespace content { | |
| 21 namespace { | |
| 22 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | |
| 23 CreateOverlayCandidateValidator() { | |
| 24 // Overlays are only supported through the remote layer API. | |
| 25 if (ui::RemoteLayerAPISupported()) { | |
| 26 static bool overlays_disabled_at_command_line = | |
| 27 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
| |
| 28 switches::kDisableMacOverlays); | |
| 29 const bool ca_layers_disabled = | |
| 30 overlays_disabled_at_command_line || | |
| 31 GpuDataManagerImpl::GetInstance()->IsDriverBugWorkaroundActive( | |
| 32 gpu::DISABLE_OVERLAY_CA_LAYERS); | |
| 33 return base::WrapUnique( | |
| 34 new display_compositor::CompositorOverlayCandidateValidatorMac( | |
| 35 ca_layers_disabled)); | |
| 36 } | |
| 37 return nullptr; | |
| 38 } | |
| 39 } // namespace | |
| 40 | |
| 41 GpuBrowserCompositorOutputSurfaceMac::GpuBrowserCompositorOutputSurfaceMac( | |
| 42 scoped_refptr<ContextProviderCommandBuffer> context, | |
| 43 gpu::SurfaceHandle surface_handle, | |
| 44 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, | |
| 45 base::SingleThreadTaskRunner* task_runner, | |
| 46 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) | |
| 47 : GpuSurfacelessBrowserCompositorOutputSurface( | |
| 48 context, | |
| 49 surface_handle, | |
| 50 vsync_manager, | |
| 51 task_runner, | |
| 52 CreateOverlayCandidateValidator(), | |
| 53 GL_TEXTURE_RECTANGLE_ARB, | |
| 54 GL_RGBA, | |
| 55 gpu_memory_buffer_manager) {} | |
| 56 | |
| 57 GpuBrowserCompositorOutputSurfaceMac::~GpuBrowserCompositorOutputSurfaceMac() {} | |
| 58 | |
| 59 void GpuBrowserCompositorOutputSurfaceMac::SwapBuffers( | |
| 60 cc::CompositorFrame* frame) { | |
| 61 GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(frame); | |
| 62 | |
| 63 if (should_show_frames_state_ == | |
| 64 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) { | |
| 65 should_show_frames_state_ = SHOULD_SHOW_FRAMES; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void GpuBrowserCompositorOutputSurfaceMac::OnGpuSwapBuffersCompleted( | |
| 70 const std::vector<ui::LatencyInfo>& latency_info, | |
| 71 gfx::SwapResult result, | |
| 72 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { | |
| 73 if (should_show_frames_state_ == SHOULD_SHOW_FRAMES) { | |
| 74 gfx::AcceleratedWidget native_widget = | |
| 75 content::GpuSurfaceTracker::Get()->AcquireNativeWidget( | |
| 76 params_mac->surface_handle); | |
| 77 ui::AcceleratedWidgetMacGotFrame( | |
| 78 native_widget, params_mac->ca_context_id, | |
| 79 params_mac->fullscreen_low_power_ca_context_valid, | |
| 80 params_mac->fullscreen_low_power_ca_context_id, params_mac->io_surface, | |
| 81 params_mac->pixel_size, params_mac->scale_factor, nullptr, nullptr); | |
| 82 } | |
| 83 GpuSurfacelessBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( | |
| 84 latency_info, result, params_mac); | |
| 85 } | |
| 86 | |
| 87 void GpuBrowserCompositorOutputSurfaceMac::SetSurfaceSuspendedForRecycle( | |
| 88 bool suspended) { | |
| 89 if (suspended) { | |
| 90 // It may be that there are frames in-flight from the GPU process back to | |
| 91 // the browser. Make sure that these frames are not displayed by ignoring | |
| 92 // them in GpuProcessHostUIShim, until the browser issues a SwapBuffers for | |
| 93 // the new content. | |
| 94 should_show_frames_state_ = SHOULD_NOT_SHOW_FRAMES_SUSPENDED; | |
| 95 } else { | |
| 96 // Discard the backbuffer before drawing the new frame. This is necessary | |
| 97 // only when using a ImageTransportSurfaceFBO with a | |
| 98 // CALayerStorageProvider. Discarding the backbuffer results in the next | |
| 99 // frame using a new CALayer and CAContext, which guarantees that the | |
| 100 // browser will not flash stale content when adding the remote CALayer to | |
| 101 // the NSView hierarchy (it could flash stale content because the system | |
| 102 // window server is not synchronized with any signals we control or | |
| 103 // observe). | |
| 104 if (should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED) { | |
| 105 DiscardBackbuffer(); | |
| 106 should_show_frames_state_ = | |
| 107 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED; | |
| 108 } | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 bool GpuBrowserCompositorOutputSurfaceMac::SurfaceIsSuspendForRecycle() const { | |
| 113 return should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED; | |
| 114 } | |
| 115 | |
| 116 } // namespace content | |
| OLD | NEW |