| 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 "base/trace_event/trace_event.h" |
| 8 #include "cc/output/ca_layer_overlay.h" |
| 7 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" | 9 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" |
| 8 #include "content/browser/gpu/gpu_surface_tracker.h" | 10 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 9 #include "content/common/gpu/client/context_provider_command_buffer.h" | 11 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 10 #include "gpu/GLES2/gl2extchromium.h" | 12 #include "gpu/GLES2/gl2extchromium.h" |
| 11 #include "gpu/ipc/client/gpu_process_hosted_ca_layer_tree_params.h" | 13 #include "gpu/ipc/client/gpu_process_hosted_ca_layer_tree_params.h" |
| 12 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" | 14 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" |
| 15 #include "ui/accelerated_widget_mac/ca_layer_tree_coordinator.h" |
| 16 #include "ui/accelerated_widget_mac/ca_renderer_layer_tree.h" |
| 13 #include "ui/base/cocoa/remote_layer_api.h" | 17 #include "ui/base/cocoa/remote_layer_api.h" |
| 18 #include "ui/gfx/geometry/rect_conversions.h" |
| 14 #include "ui/gfx/mac/io_surface.h" | 19 #include "ui/gfx/mac/io_surface.h" |
| 15 | 20 |
| 16 namespace content { | 21 namespace content { |
| 17 | 22 |
| 18 struct GpuOutputSurfaceMac::RemoteLayers { | 23 struct GpuOutputSurfaceMac::RemoteLayers { |
| 19 void UpdateLayers(CAContextID content_ca_context_id, | 24 void UpdateLayers(CAContextID content_ca_context_id, |
| 20 CAContextID fullscreen_low_power_ca_context_id) { | 25 CAContextID fullscreen_low_power_ca_context_id) { |
| 21 if (content_ca_context_id) { | 26 if (content_ca_context_id) { |
| 22 if ([content_layer contextId] != content_ca_context_id) { | 27 if ([content_layer contextId] != content_ca_context_id) { |
| 23 content_layer.reset([[CALayerHost alloc] init]); | 28 content_layer.reset([[CALayerHost alloc] init]); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) | 60 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) |
| 56 : GpuSurfacelessBrowserCompositorOutputSurface( | 61 : GpuSurfacelessBrowserCompositorOutputSurface( |
| 57 std::move(context), | 62 std::move(context), |
| 58 surface_handle, | 63 surface_handle, |
| 59 std::move(vsync_manager), | 64 std::move(vsync_manager), |
| 60 task_runner, | 65 task_runner, |
| 61 std::move(overlay_candidate_validator), | 66 std::move(overlay_candidate_validator), |
| 62 GL_TEXTURE_RECTANGLE_ARB, | 67 GL_TEXTURE_RECTANGLE_ARB, |
| 63 GL_RGBA, | 68 GL_RGBA, |
| 64 gpu_memory_buffer_manager), | 69 gpu_memory_buffer_manager), |
| 65 remote_layers_(new RemoteLayers) {} | 70 remote_layers_(new RemoteLayers), |
| 71 ca_layer_tree_coordinator_(new ui::CALayerTreeCoordinator(true)) {} |
| 66 | 72 |
| 67 GpuOutputSurfaceMac::~GpuOutputSurfaceMac() {} | 73 GpuOutputSurfaceMac::~GpuOutputSurfaceMac() {} |
| 68 | 74 |
| 75 void GpuOutputSurfaceMac::Reshape(const gfx::Size& size, float scale_factor, boo
l alpha) { |
| 76 GpuSurfacelessBrowserCompositorOutputSurface::Reshape(size, scale_factor, alph
a); |
| 77 |
| 78 ca_layer_tree_coordinator_->Resize(size, scale_factor); |
| 79 } |
| 80 |
| 69 void GpuOutputSurfaceMac::SwapBuffers(cc::CompositorFrame* frame) { | 81 void GpuOutputSurfaceMac::SwapBuffers(cc::CompositorFrame* frame) { |
| 70 GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(frame); | 82 GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(frame); |
| 71 | 83 |
| 72 if (should_show_frames_state_ == | 84 if (should_show_frames_state_ == |
| 73 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) { | 85 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) { |
| 74 should_show_frames_state_ = SHOULD_SHOW_FRAMES; | 86 should_show_frames_state_ = SHOULD_SHOW_FRAMES; |
| 75 } | 87 } |
| 76 } | 88 } |
| 77 | 89 |
| 78 void GpuOutputSurfaceMac::OnGpuSwapBuffersCompleted( | 90 void GpuOutputSurfaceMac::OnGpuSwapBuffersCompleted( |
| 79 const std::vector<ui::LatencyInfo>& latency_info, | 91 const std::vector<ui::LatencyInfo>& latency_info, |
| 80 gfx::SwapResult result, | 92 gfx::SwapResult result, |
| 81 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { | 93 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { |
| 82 remote_layers_->UpdateLayers(params_mac->ca_context_id, | 94 remote_layers_->UpdateLayers(params_mac->ca_context_id, |
| 83 params_mac->fullscreen_low_power_ca_context_id); | 95 params_mac->fullscreen_low_power_ca_context_id); |
| 84 if (should_show_frames_state_ == SHOULD_SHOW_FRAMES) { | 96 if (should_show_frames_state_ == SHOULD_SHOW_FRAMES) { |
| 85 ui::AcceleratedWidgetMac* widget = ui::AcceleratedWidgetMac::Get( | 97 ui::AcceleratedWidgetMac* widget = ui::AcceleratedWidgetMac::Get( |
| 86 content::GpuSurfaceTracker::Get()->AcquireNativeWidget( | 98 content::GpuSurfaceTracker::Get()->AcquireNativeWidget( |
| 87 params_mac->surface_handle)); | 99 params_mac->surface_handle)); |
| 88 if (widget) { | 100 if (widget) { |
| 89 if (remote_layers_->content_layer) { | 101 if (1) { |
| 102 widget->GotCALayerFrame( |
| 103 base::scoped_nsobject<CALayer>( |
| 104 ca_layer_tree_coordinator_->GetCALayerForDisplay(), |
| 105 base::scoped_policy::RETAIN), |
| 106 false, |
| 107 base::scoped_nsobject<CALayer>( |
| 108 ca_layer_tree_coordinator_-> |
| 109 GetFullscreenLowPowerLayerForDisplay(), |
| 110 base::scoped_policy::RETAIN), |
| 111 params_mac->pixel_size, params_mac->scale_factor); |
| 112 } else if (remote_layers_->content_layer) { |
| 90 widget->GotCALayerFrame( | 113 widget->GotCALayerFrame( |
| 91 base::scoped_nsobject<CALayer>(remote_layers_->content_layer.get(), | 114 base::scoped_nsobject<CALayer>(remote_layers_->content_layer.get(), |
| 92 base::scoped_policy::RETAIN), | 115 base::scoped_policy::RETAIN), |
| 93 params_mac->fullscreen_low_power_ca_context_valid, | 116 params_mac->fullscreen_low_power_ca_context_valid, |
| 94 base::scoped_nsobject<CALayer>( | 117 base::scoped_nsobject<CALayer>( |
| 95 remote_layers_->fullscreen_low_power_layer.get(), | 118 remote_layers_->fullscreen_low_power_layer.get(), |
| 96 base::scoped_policy::RETAIN), | 119 base::scoped_policy::RETAIN), |
| 97 params_mac->pixel_size, params_mac->scale_factor); | 120 params_mac->pixel_size, params_mac->scale_factor); |
| 98 } else { | 121 } else { |
| 99 widget->GotIOSurfaceFrame(params_mac->io_surface, | 122 widget->GotIOSurfaceFrame(params_mac->io_surface, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 127 should_show_frames_state_ = | 150 should_show_frames_state_ = |
| 128 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED; | 151 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED; |
| 129 } | 152 } |
| 130 } | 153 } |
| 131 } | 154 } |
| 132 | 155 |
| 133 bool GpuOutputSurfaceMac::SurfaceIsSuspendForRecycle() const { | 156 bool GpuOutputSurfaceMac::SurfaceIsSuspendForRecycle() const { |
| 134 return should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED; | 157 return should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED; |
| 135 } | 158 } |
| 136 | 159 |
| 160 void GpuOutputSurfaceMac::ProcessCALayers(const cc::CALayerOverlayList& ca_layer
_overlays) { |
| 161 { |
| 162 TRACE_EVENT0("browser", "GpuOutputSurfaceMac::ProcessCALayers Construct"); |
| 163 for (const auto& ca_layer_overlay : ca_layer_overlays) { |
| 164 base::ScopedCFTypeRef<IOSurfaceRef> io_surface; |
| 165 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; |
| 166 if (ca_layer_overlay.resource_lock) { |
| 167 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
| 168 ca_layer_overlay.resource_lock->GetGpuMemoryBuffer(); |
| 169 if (gpu_memory_buffer) { |
| 170 io_surface.reset(static_cast<IOSurfaceRef>(gpu_memory_buffer->GetIOSur
face()), |
| 171 base::scoped_policy::RETAIN); |
| 172 } |
| 173 } |
| 174 ca_layer_tree_coordinator_->GetPendingCARendererLayerTree()-> |
| 175 ScheduleCALayer(ca_layer_overlay.is_clipped, |
| 176 gfx::ToNearestRect(ca_layer_overlay.clip_rect), |
| 177 ca_layer_overlay.sorting_context_id, |
| 178 gfx::Transform(ca_layer_overlay.transform), |
| 179 io_surface, |
| 180 cv_pixel_buffer, |
| 181 ca_layer_overlay.contents_rect, |
| 182 gfx::ToNearestRect(ca_layer_overlay.bounds_rect), |
| 183 ca_layer_overlay.background_color, |
| 184 ca_layer_overlay.edge_aa_mask, |
| 185 ca_layer_overlay.opacity, |
| 186 ca_layer_overlay.filter); |
| 187 } |
| 188 } |
| 189 |
| 190 TRACE_EVENT0("browser", "GpuOutputSurfaceMac::ProcessCALayers Commit"); |
| 191 bool fullscreen_low_power_layer_valid = false; |
| 192 ca_layer_tree_coordinator_->CommitPendingTreesToCA( |
| 193 gfx::Rect(SurfaceSize()), &fullscreen_low_power_layer_valid); |
| 194 } |
| 195 |
| 137 } // namespace content | 196 } // namespace content |
| OLD | NEW |