Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
danakj
2016/06/01 18:11:04
Why is this a .mm and not a .cc?
ccameron
2016/06/01 19:44:22
We keep track of the GPU-process-hosted CALayers i
| |
| 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_output_surface_mac.h" | |
| 6 | |
| 7 #include "components/display_compositor/compositor_overlay_candidate_validator.h " | |
| 8 #include "content/browser/gpu/gpu_surface_tracker.h" | |
| 9 #include "content/common/gpu/client/context_provider_command_buffer.h" | |
| 10 #include "gpu/GLES2/gl2extchromium.h" | |
| 11 #include "gpu/ipc/client/gpu_process_hosted_ca_layer_tree_params.h" | |
| 12 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" | |
| 13 #include "ui/base/cocoa/remote_layer_api.h" | |
| 14 #include "ui/gfx/mac/io_surface.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 GpuOutputSurfaceMac::GpuOutputSurfaceMac( | |
| 19 scoped_refptr<ContextProviderCommandBuffer> context, | |
| 20 gpu::SurfaceHandle surface_handle, | |
| 21 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, | |
| 22 base::SingleThreadTaskRunner* task_runner, | |
| 23 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | |
| 24 overlay_candidate_validator, | |
| 25 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) | |
| 26 : GpuSurfacelessBrowserCompositorOutputSurface( | |
| 27 context, | |
|
danakj
2016/06/01 18:11:04
move
ccameron
2016/06/01 19:44:22
Done.
| |
| 28 surface_handle, | |
| 29 vsync_manager, | |
|
danakj
2016/06/01 18:11:04
move
ccameron
2016/06/01 19:44:22
Done.
| |
| 30 task_runner, | |
| 31 std::move(overlay_candidate_validator), | |
| 32 GL_TEXTURE_RECTANGLE_ARB, | |
| 33 GL_RGBA, | |
| 34 gpu_memory_buffer_manager) {} | |
| 35 | |
| 36 GpuOutputSurfaceMac::~GpuOutputSurfaceMac() {} | |
| 37 | |
| 38 void GpuOutputSurfaceMac::SwapBuffers(cc::CompositorFrame* frame) { | |
| 39 GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(frame); | |
| 40 | |
| 41 if (should_show_frames_state_ == | |
| 42 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) { | |
| 43 should_show_frames_state_ = SHOULD_SHOW_FRAMES; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 void GpuOutputSurfaceMac::OnGpuSwapBuffersCompleted( | |
| 48 const std::vector<ui::LatencyInfo>& latency_info, | |
| 49 gfx::SwapResult result, | |
| 50 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { | |
| 51 if (should_show_frames_state_ == SHOULD_SHOW_FRAMES) { | |
| 52 gfx::AcceleratedWidget native_widget = | |
| 53 content::GpuSurfaceTracker::Get()->AcquireNativeWidget( | |
| 54 params_mac->surface_handle); | |
| 55 ui::AcceleratedWidgetMacGotFrame( | |
| 56 native_widget, params_mac->ca_context_id, | |
| 57 params_mac->fullscreen_low_power_ca_context_valid, | |
| 58 params_mac->fullscreen_low_power_ca_context_id, params_mac->io_surface, | |
| 59 params_mac->pixel_size, params_mac->scale_factor, nullptr, nullptr); | |
| 60 } | |
| 61 GpuSurfacelessBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( | |
| 62 latency_info, result, params_mac); | |
| 63 } | |
| 64 | |
| 65 void GpuOutputSurfaceMac::SetSurfaceSuspendedForRecycle(bool suspended) { | |
| 66 if (suspended) { | |
| 67 // It may be that there are frames in-flight from the GPU process back to | |
| 68 // the browser. Make sure that these frames are not displayed by ignoring | |
| 69 // them in GpuProcessHostUIShim, until the browser issues a SwapBuffers for | |
| 70 // the new content. | |
| 71 should_show_frames_state_ = SHOULD_NOT_SHOW_FRAMES_SUSPENDED; | |
| 72 } else { | |
| 73 // Discard the backbuffer before drawing the new frame. This is necessary | |
| 74 // only when using a ImageTransportSurfaceFBO with a | |
| 75 // CALayerStorageProvider. Discarding the backbuffer results in the next | |
| 76 // frame using a new CALayer and CAContext, which guarantees that the | |
| 77 // browser will not flash stale content when adding the remote CALayer to | |
| 78 // the NSView hierarchy (it could flash stale content because the system | |
| 79 // window server is not synchronized with any signals we control or | |
| 80 // observe). | |
| 81 if (should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED) { | |
| 82 DiscardBackbuffer(); | |
| 83 should_show_frames_state_ = | |
| 84 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED; | |
| 85 } | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 bool GpuOutputSurfaceMac::SurfaceIsSuspendForRecycle() const { | |
| 90 return should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED; | |
| 91 } | |
| 92 | |
| 93 } // namespace content | |
| OLD | NEW |