| 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 "services/ui/surfaces/direct_output_surface_ozone.h" | 5 #include "services/ui/surfaces/display_output_surface_ozone.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "cc/output/context_provider.h" | 11 #include "cc/output/context_provider.h" |
| 12 #include "cc/output/output_surface_client.h" | 12 #include "cc/output/output_surface_client.h" |
| 13 #include "cc/output/output_surface_frame.h" | 13 #include "cc/output/output_surface_frame.h" |
| 14 #include "cc/scheduler/begin_frame_source.h" | 14 #include "cc/scheduler/begin_frame_source.h" |
| 15 #include "components/display_compositor/buffer_queue.h" | 15 #include "components/display_compositor/buffer_queue.h" |
| 16 #include "gpu/command_buffer/client/context_support.h" | 16 #include "gpu/command_buffer/client/context_support.h" |
| 17 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 18 #include "ui/display/types/display_snapshot.h" | 18 #include "ui/display/types/display_snapshot.h" |
| 19 | 19 |
| 20 using display_compositor::BufferQueue; | 20 using display_compositor::BufferQueue; |
| 21 | 21 |
| 22 namespace ui { | 22 namespace ui { |
| 23 | 23 |
| 24 DirectOutputSurfaceOzone::DirectOutputSurfaceOzone( | 24 DisplayOutputSurfaceOzone::DisplayOutputSurfaceOzone( |
| 25 scoped_refptr<cc::InProcessContextProvider> context_provider, | 25 scoped_refptr<cc::InProcessContextProvider> context_provider, |
| 26 gfx::AcceleratedWidget widget, | 26 gfx::AcceleratedWidget widget, |
| 27 cc::SyntheticBeginFrameSource* synthetic_begin_frame_source, | 27 cc::SyntheticBeginFrameSource* synthetic_begin_frame_source, |
| 28 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 28 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 29 uint32_t target, | 29 uint32_t target, |
| 30 uint32_t internalformat) | 30 uint32_t internalformat) |
| 31 : cc::OutputSurface(context_provider), | 31 : cc::OutputSurface(context_provider), |
| 32 gl_helper_(context_provider->ContextGL(), | 32 gl_helper_(context_provider->ContextGL(), |
| 33 context_provider->ContextSupport()), | 33 context_provider->ContextSupport()), |
| 34 synthetic_begin_frame_source_(synthetic_begin_frame_source), | 34 synthetic_begin_frame_source_(synthetic_begin_frame_source), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 // With a surface, swap buffer ack used to return early, before actually | 45 // With a surface, swap buffer ack used to return early, before actually |
| 46 // presenting the back buffer, enabling the browser compositor to run ahead. | 46 // presenting the back buffer, enabling the browser compositor to run ahead. |
| 47 // Surfaceless implementation acks at the time of actual buffer swap, which | 47 // Surfaceless implementation acks at the time of actual buffer swap, which |
| 48 // shifts the start of the new frame forward relative to the old | 48 // shifts the start of the new frame forward relative to the old |
| 49 // implementation. | 49 // implementation. |
| 50 capabilities_.max_frames_pending = 2; | 50 capabilities_.max_frames_pending = 2; |
| 51 | 51 |
| 52 buffer_queue_->Initialize(); | 52 buffer_queue_->Initialize(); |
| 53 | 53 |
| 54 context_provider->SetSwapBuffersCompletionCallback( | 54 context_provider->SetSwapBuffersCompletionCallback( |
| 55 base::Bind(&DirectOutputSurfaceOzone::OnGpuSwapBuffersCompleted, | 55 base::Bind(&DisplayOutputSurfaceOzone::OnGpuSwapBuffersCompleted, |
| 56 weak_ptr_factory_.GetWeakPtr())); | 56 weak_ptr_factory_.GetWeakPtr())); |
| 57 context_provider->SetUpdateVSyncParametersCallback( | 57 context_provider->SetUpdateVSyncParametersCallback( |
| 58 base::Bind(&DirectOutputSurfaceOzone::OnVSyncParametersUpdated, | 58 base::Bind(&DisplayOutputSurfaceOzone::OnVSyncParametersUpdated, |
| 59 weak_ptr_factory_.GetWeakPtr())); | 59 weak_ptr_factory_.GetWeakPtr())); |
| 60 } | 60 } |
| 61 | 61 |
| 62 DirectOutputSurfaceOzone::~DirectOutputSurfaceOzone() { | 62 DisplayOutputSurfaceOzone::~DisplayOutputSurfaceOzone() { |
| 63 // TODO(rjkroege): Support cleanup. | 63 // TODO(rjkroege): Support cleanup. |
| 64 } | 64 } |
| 65 | 65 |
| 66 void DirectOutputSurfaceOzone::BindToClient(cc::OutputSurfaceClient* client) { | 66 void DisplayOutputSurfaceOzone::BindToClient(cc::OutputSurfaceClient* client) { |
| 67 DCHECK(client); | 67 DCHECK(client); |
| 68 DCHECK(!client_); | 68 DCHECK(!client_); |
| 69 client_ = client; | 69 client_ = client; |
| 70 } | 70 } |
| 71 | 71 |
| 72 void DirectOutputSurfaceOzone::EnsureBackbuffer() {} | 72 void DisplayOutputSurfaceOzone::EnsureBackbuffer() {} |
| 73 | 73 |
| 74 void DirectOutputSurfaceOzone::DiscardBackbuffer() { | 74 void DisplayOutputSurfaceOzone::DiscardBackbuffer() { |
| 75 context_provider()->ContextGL()->DiscardBackbufferCHROMIUM(); | 75 context_provider()->ContextGL()->DiscardBackbufferCHROMIUM(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void DirectOutputSurfaceOzone::BindFramebuffer() { | 78 void DisplayOutputSurfaceOzone::BindFramebuffer() { |
| 79 DCHECK(buffer_queue_); | 79 DCHECK(buffer_queue_); |
| 80 buffer_queue_->BindFramebuffer(); | 80 buffer_queue_->BindFramebuffer(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // We call this on every frame that a value changes, but changing the size once | 83 // We call this on every frame that a value changes, but changing the size once |
| 84 // we've allocated backing NativePixmapOzone instances will cause a DCHECK | 84 // we've allocated backing NativePixmapOzone instances will cause a DCHECK |
| 85 // because Chrome never Reshape(s) after the first one from (0,0). NB: this | 85 // because Chrome never Reshape(s) after the first one from (0,0). NB: this |
| 86 // implies that screen size changes need to be plumbed differently. In | 86 // implies that screen size changes need to be plumbed differently. In |
| 87 // particular, we must create the native window in the size that the hardware | 87 // particular, we must create the native window in the size that the hardware |
| 88 // reports. | 88 // reports. |
| 89 void DirectOutputSurfaceOzone::Reshape(const gfx::Size& size, | 89 void DisplayOutputSurfaceOzone::Reshape(const gfx::Size& size, |
| 90 float device_scale_factor, | 90 float device_scale_factor, |
| 91 const gfx::ColorSpace& color_space, | 91 const gfx::ColorSpace& color_space, |
| 92 bool has_alpha) { | 92 bool has_alpha) { |
| 93 reshape_size_ = size; | 93 reshape_size_ = size; |
| 94 context_provider()->ContextGL()->ResizeCHROMIUM( | 94 context_provider()->ContextGL()->ResizeCHROMIUM( |
| 95 size.width(), size.height(), device_scale_factor, has_alpha); | 95 size.width(), size.height(), device_scale_factor, has_alpha); |
| 96 buffer_queue_->Reshape(size, device_scale_factor, color_space); | 96 buffer_queue_->Reshape(size, device_scale_factor, color_space); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void DirectOutputSurfaceOzone::SwapBuffers(cc::OutputSurfaceFrame frame) { | 99 void DisplayOutputSurfaceOzone::SwapBuffers(cc::OutputSurfaceFrame frame) { |
| 100 DCHECK(buffer_queue_); | 100 DCHECK(buffer_queue_); |
| 101 | 101 |
| 102 // TODO(rjkroege): What if swap happens again before OnGpuSwapBuffersCompleted | 102 // TODO(rjkroege): What if swap happens again before OnGpuSwapBuffersCompleted |
| 103 // then it would see the wrong size? | 103 // then it would see the wrong size? |
| 104 DCHECK(reshape_size_ == frame.size); | 104 DCHECK(reshape_size_ == frame.size); |
| 105 swap_size_ = reshape_size_; | 105 swap_size_ = reshape_size_; |
| 106 | 106 |
| 107 buffer_queue_->SwapBuffers(frame.sub_buffer_rect); | 107 buffer_queue_->SwapBuffers(frame.sub_buffer_rect); |
| 108 | 108 |
| 109 // Code combining GpuBrowserCompositorOutputSurface + DirectOutputSurface | 109 // Code combining GpuBrowserCompositorOutputSurface + DisplayOutputSurface |
| 110 if (frame.sub_buffer_rect == gfx::Rect(frame.size)) { | 110 if (frame.sub_buffer_rect == gfx::Rect(frame.size)) { |
| 111 context_provider_->ContextSupport()->Swap(); | 111 context_provider_->ContextSupport()->Swap(); |
| 112 } else { | 112 } else { |
| 113 context_provider_->ContextSupport()->PartialSwapBuffers( | 113 context_provider_->ContextSupport()->PartialSwapBuffers( |
| 114 frame.sub_buffer_rect); | 114 frame.sub_buffer_rect); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 uint32_t DirectOutputSurfaceOzone::GetFramebufferCopyTextureFormat() { | 118 uint32_t DisplayOutputSurfaceOzone::GetFramebufferCopyTextureFormat() { |
| 119 return buffer_queue_->internal_format(); | 119 return buffer_queue_->internal_format(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 cc::OverlayCandidateValidator* | 122 cc::OverlayCandidateValidator* |
| 123 DirectOutputSurfaceOzone::GetOverlayCandidateValidator() const { | 123 DisplayOutputSurfaceOzone::GetOverlayCandidateValidator() const { |
| 124 return nullptr; | 124 return nullptr; |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool DirectOutputSurfaceOzone::IsDisplayedAsOverlayPlane() const { | 127 bool DisplayOutputSurfaceOzone::IsDisplayedAsOverlayPlane() const { |
| 128 // TODO(rjkroege): implement remaining overlay functionality. | 128 // TODO(rjkroege): implement remaining overlay functionality. |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 unsigned DirectOutputSurfaceOzone::GetOverlayTextureId() const { | 132 unsigned DisplayOutputSurfaceOzone::GetOverlayTextureId() const { |
| 133 return buffer_queue_->current_texture_id(); | 133 return buffer_queue_->current_texture_id(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool DirectOutputSurfaceOzone::SurfaceIsSuspendForRecycle() const { | 136 bool DisplayOutputSurfaceOzone::SurfaceIsSuspendForRecycle() const { |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool DirectOutputSurfaceOzone::HasExternalStencilTest() const { | 140 bool DisplayOutputSurfaceOzone::HasExternalStencilTest() const { |
| 141 return false; | 141 return false; |
| 142 } | 142 } |
| 143 | 143 |
| 144 void DirectOutputSurfaceOzone::ApplyExternalStencil() {} | 144 void DisplayOutputSurfaceOzone::ApplyExternalStencil() {} |
| 145 | 145 |
| 146 void DirectOutputSurfaceOzone::OnGpuSwapBuffersCompleted( | 146 void DisplayOutputSurfaceOzone::OnGpuSwapBuffersCompleted( |
| 147 const std::vector<ui::LatencyInfo>& latency_info, | 147 const std::vector<ui::LatencyInfo>& latency_info, |
| 148 gfx::SwapResult result, | 148 gfx::SwapResult result, |
| 149 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { | 149 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { |
| 150 bool force_swap = false; | 150 bool force_swap = false; |
| 151 if (result == gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS) { | 151 if (result == gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS) { |
| 152 // Even through the swap failed, this is a fixable error so we can pretend | 152 // Even through the swap failed, this is a fixable error so we can pretend |
| 153 // it succeeded to the rest of the system. | 153 // it succeeded to the rest of the system. |
| 154 result = gfx::SwapResult::SWAP_ACK; | 154 result = gfx::SwapResult::SWAP_ACK; |
| 155 buffer_queue_->RecreateBuffers(); | 155 buffer_queue_->RecreateBuffers(); |
| 156 force_swap = true; | 156 force_swap = true; |
| 157 } | 157 } |
| 158 | 158 |
| 159 buffer_queue_->PageFlipComplete(); | 159 buffer_queue_->PageFlipComplete(); |
| 160 client_->DidReceiveSwapBuffersAck(); | 160 client_->DidReceiveSwapBuffersAck(); |
| 161 | 161 |
| 162 if (force_swap) | 162 if (force_swap) |
| 163 client_->SetNeedsRedrawRect(gfx::Rect(swap_size_)); | 163 client_->SetNeedsRedrawRect(gfx::Rect(swap_size_)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void DirectOutputSurfaceOzone::OnVSyncParametersUpdated( | 166 void DisplayOutputSurfaceOzone::OnVSyncParametersUpdated( |
| 167 base::TimeTicks timebase, | 167 base::TimeTicks timebase, |
| 168 base::TimeDelta interval) { | 168 base::TimeDelta interval) { |
| 169 // TODO(brianderson): We should not be receiving 0 intervals. | 169 // TODO(brianderson): We should not be receiving 0 intervals. |
| 170 synthetic_begin_frame_source_->OnUpdateVSyncParameters( | 170 synthetic_begin_frame_source_->OnUpdateVSyncParameters( |
| 171 timebase, | 171 timebase, |
| 172 interval.is_zero() ? cc::BeginFrameArgs::DefaultInterval() : interval); | 172 interval.is_zero() ? cc::BeginFrameArgs::DefaultInterval() : interval); |
| 173 } | 173 } |
| 174 | 174 |
| 175 } // namespace ui | 175 } // namespace ui |
| OLD | NEW |