| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_output_surface_mac.h" | 5 #include "content/browser/compositor/gpu_output_surface_mac.h" |
| 6 | 6 |
| 7 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" | 7 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" |
| 8 #include "content/browser/gpu/gpu_surface_tracker.h" | 8 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 9 #include "content/common/gpu/client/context_provider_command_buffer.h" | 9 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 10 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "gpu/GLES2/gl2extchromium.h" |
| 11 #include "gpu/ipc/client/gpu_process_hosted_ca_layer_tree_params.h" | 11 #include "gpu/ipc/client/gpu_process_hosted_ca_layer_tree_params.h" |
| 12 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" | 12 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" |
| 13 #include "ui/base/cocoa/remote_layer_api.h" | 13 #include "ui/base/cocoa/remote_layer_api.h" |
| 14 #include "ui/gfx/mac/io_surface.h" | 14 #include "ui/gfx/mac/io_surface.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 struct GpuOutputSurfaceMac::RemoteLayers { |
| 19 void UpdateLayers(CAContextID content_ca_context_id, |
| 20 CAContextID fullscreen_low_power_ca_context_id) { |
| 21 if (content_ca_context_id) { |
| 22 if ([content_layer contextId] != content_ca_context_id) { |
| 23 content_layer.reset([[CALayerHost alloc] init]); |
| 24 [content_layer setContextId:content_ca_context_id]; |
| 25 [content_layer |
| 26 setAutoresizingMask:kCALayerMaxXMargin | kCALayerMaxYMargin]; |
| 27 } |
| 28 } else { |
| 29 content_layer.reset(); |
| 30 } |
| 31 |
| 32 if (fullscreen_low_power_ca_context_id) { |
| 33 if ([fullscreen_low_power_layer contextId] != |
| 34 fullscreen_low_power_ca_context_id) { |
| 35 fullscreen_low_power_layer.reset([[CALayerHost alloc] init]); |
| 36 [fullscreen_low_power_layer |
| 37 setContextId:fullscreen_low_power_ca_context_id]; |
| 38 } |
| 39 } else { |
| 40 fullscreen_low_power_layer.reset(); |
| 41 } |
| 42 } |
| 43 |
| 44 base::scoped_nsobject<CALayerHost> content_layer; |
| 45 base::scoped_nsobject<CALayerHost> fullscreen_low_power_layer; |
| 46 }; |
| 47 |
| 18 GpuOutputSurfaceMac::GpuOutputSurfaceMac( | 48 GpuOutputSurfaceMac::GpuOutputSurfaceMac( |
| 19 scoped_refptr<ContextProviderCommandBuffer> context, | 49 scoped_refptr<ContextProviderCommandBuffer> context, |
| 20 gpu::SurfaceHandle surface_handle, | 50 gpu::SurfaceHandle surface_handle, |
| 21 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, | 51 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, |
| 22 base::SingleThreadTaskRunner* task_runner, | 52 base::SingleThreadTaskRunner* task_runner, |
| 23 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 53 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
| 24 overlay_candidate_validator, | 54 overlay_candidate_validator, |
| 25 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) | 55 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) |
| 26 : GpuSurfacelessBrowserCompositorOutputSurface( | 56 : GpuSurfacelessBrowserCompositorOutputSurface( |
| 27 std::move(context), | 57 std::move(context), |
| 28 surface_handle, | 58 surface_handle, |
| 29 std::move(vsync_manager), | 59 std::move(vsync_manager), |
| 30 task_runner, | 60 task_runner, |
| 31 std::move(overlay_candidate_validator), | 61 std::move(overlay_candidate_validator), |
| 32 GL_TEXTURE_RECTANGLE_ARB, | 62 GL_TEXTURE_RECTANGLE_ARB, |
| 33 GL_RGBA, | 63 GL_RGBA, |
| 34 gpu_memory_buffer_manager) {} | 64 gpu_memory_buffer_manager), |
| 65 remote_layers_(new RemoteLayers) {} |
| 35 | 66 |
| 36 GpuOutputSurfaceMac::~GpuOutputSurfaceMac() {} | 67 GpuOutputSurfaceMac::~GpuOutputSurfaceMac() {} |
| 37 | 68 |
| 38 void GpuOutputSurfaceMac::SwapBuffers(cc::CompositorFrame* frame) { | 69 void GpuOutputSurfaceMac::SwapBuffers(cc::CompositorFrame* frame) { |
| 39 GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(frame); | 70 GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(frame); |
| 40 | 71 |
| 41 if (should_show_frames_state_ == | 72 if (should_show_frames_state_ == |
| 42 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) { | 73 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) { |
| 43 should_show_frames_state_ = SHOULD_SHOW_FRAMES; | 74 should_show_frames_state_ = SHOULD_SHOW_FRAMES; |
| 44 } | 75 } |
| 45 } | 76 } |
| 46 | 77 |
| 47 void GpuOutputSurfaceMac::OnGpuSwapBuffersCompleted( | 78 void GpuOutputSurfaceMac::OnGpuSwapBuffersCompleted( |
| 48 const std::vector<ui::LatencyInfo>& latency_info, | 79 const std::vector<ui::LatencyInfo>& latency_info, |
| 49 gfx::SwapResult result, | 80 gfx::SwapResult result, |
| 50 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { | 81 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { |
| 82 remote_layers_->UpdateLayers(params_mac->ca_context_id, |
| 83 params_mac->fullscreen_low_power_ca_context_id); |
| 51 if (should_show_frames_state_ == SHOULD_SHOW_FRAMES) { | 84 if (should_show_frames_state_ == SHOULD_SHOW_FRAMES) { |
| 52 gfx::AcceleratedWidget native_widget = | 85 ui::AcceleratedWidgetMac* widget = ui::AcceleratedWidgetMac::Get( |
| 53 content::GpuSurfaceTracker::Get()->AcquireNativeWidget( | 86 content::GpuSurfaceTracker::Get()->AcquireNativeWidget( |
| 54 params_mac->surface_handle); | 87 params_mac->surface_handle)); |
| 55 ui::AcceleratedWidgetMacGotFrame( | 88 if (widget) { |
| 56 native_widget, params_mac->ca_context_id, | 89 if (remote_layers_->content_layer) { |
| 57 params_mac->fullscreen_low_power_ca_context_valid, | 90 widget->GotCALayerFrame( |
| 58 params_mac->fullscreen_low_power_ca_context_id, params_mac->io_surface, | 91 base::scoped_nsobject<CALayer>(remote_layers_->content_layer.get(), |
| 59 params_mac->pixel_size, params_mac->scale_factor, nullptr, nullptr); | 92 base::scoped_policy::RETAIN), |
| 93 params_mac->fullscreen_low_power_ca_context_valid, |
| 94 base::scoped_nsobject<CALayer>( |
| 95 remote_layers_->fullscreen_low_power_layer.get(), |
| 96 base::scoped_policy::RETAIN), |
| 97 params_mac->pixel_size, params_mac->scale_factor); |
| 98 } else { |
| 99 widget->GotIOSurfaceFrame(params_mac->io_surface, |
| 100 params_mac->pixel_size, |
| 101 params_mac->scale_factor); |
| 102 } |
| 103 } |
| 60 } | 104 } |
| 61 GpuSurfacelessBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( | 105 GpuSurfacelessBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( |
| 62 latency_info, result, params_mac); | 106 latency_info, result, params_mac); |
| 63 } | 107 } |
| 64 | 108 |
| 65 void GpuOutputSurfaceMac::SetSurfaceSuspendedForRecycle(bool suspended) { | 109 void GpuOutputSurfaceMac::SetSurfaceSuspendedForRecycle(bool suspended) { |
| 66 if (suspended) { | 110 if (suspended) { |
| 67 // It may be that there are frames in-flight from the GPU process back to | 111 // 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 | 112 // the browser. Make sure that these frames are not displayed by ignoring |
| 69 // them in GpuProcessHostUIShim, until the browser issues a SwapBuffers for | 113 // them in GpuProcessHostUIShim, until the browser issues a SwapBuffers for |
| (...skipping 14 matching lines...) Expand all Loading... |
| 84 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED; | 128 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED; |
| 85 } | 129 } |
| 86 } | 130 } |
| 87 } | 131 } |
| 88 | 132 |
| 89 bool GpuOutputSurfaceMac::SurfaceIsSuspendForRecycle() const { | 133 bool GpuOutputSurfaceMac::SurfaceIsSuspendForRecycle() const { |
| 90 return should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED; | 134 return should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED; |
| 91 } | 135 } |
| 92 | 136 |
| 93 } // namespace content | 137 } // namespace content |
| OLD | NEW |