| 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/mus_browser_compositor_output_surface.h" | 5 #include "content/browser/compositor/mus_browser_compositor_output_surface.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/output_surface_frame.h" | 10 #include "cc/output/output_surface_frame.h" |
| 11 #include "cc/quads/render_pass.h" | 11 #include "cc/quads/render_pass.h" |
| 12 #include "cc/quads/texture_draw_quad.h" | 12 #include "cc/quads/texture_draw_quad.h" |
| 13 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" | 13 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" |
| 14 #include "content/common/gpu/client/context_provider_command_buffer.h" | 14 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 15 #include "gpu/command_buffer/client/gles2_interface.h" | 15 #include "gpu/command_buffer/client/gles2_interface.h" |
| 16 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 16 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 17 #include "services/ui/public/cpp/compositor_frame_sink.h" |
| 17 #include "services/ui/public/cpp/window.h" | 18 #include "services/ui/public/cpp/window.h" |
| 18 #include "services/ui/public/cpp/window_surface.h" | 19 #include "services/ui/public/cpp/window_surface.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 MusBrowserCompositorOutputSurface::MusBrowserCompositorOutputSurface( | 23 MusBrowserCompositorOutputSurface::MusBrowserCompositorOutputSurface( |
| 23 ui::Window* window, | 24 ui::Window* window, |
| 24 scoped_refptr<ContextProviderCommandBuffer> context, | 25 scoped_refptr<ContextProviderCommandBuffer> context, |
| 25 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, | 26 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, |
| 26 cc::SyntheticBeginFrameSource* begin_frame_source, | 27 cc::SyntheticBeginFrameSource* begin_frame_source, |
| 27 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 28 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
| 28 overlay_candidate_validator) | 29 overlay_candidate_validator) |
| 29 : GpuBrowserCompositorOutputSurface(std::move(context), | 30 : GpuBrowserCompositorOutputSurface(std::move(context), |
| 30 std::move(vsync_manager), | 31 std::move(vsync_manager), |
| 31 begin_frame_source, | 32 begin_frame_source, |
| 32 std::move(overlay_candidate_validator)), | 33 std::move(overlay_candidate_validator)), |
| 33 ui_window_(window) { | 34 ui_window_(window) { |
| 34 ui_window_surface_ = | 35 ui_compositor_frame_sink_ = ui_window_->RequestCompositorFrameSink( |
| 35 ui_window_->RequestSurface(ui::mojom::SurfaceType::DEFAULT); | 36 ui::mojom::SurfaceType::DEFAULT, context); |
| 36 } | 37 } |
| 37 | 38 |
| 38 MusBrowserCompositorOutputSurface::~MusBrowserCompositorOutputSurface() {} | 39 MusBrowserCompositorOutputSurface::~MusBrowserCompositorOutputSurface() {} |
| 39 | 40 |
| 40 void MusBrowserCompositorOutputSurface::SwapBuffers( | 41 void MusBrowserCompositorOutputSurface::SwapBuffers( |
| 41 cc::OutputSurfaceFrame frame) { | 42 cc::OutputSurfaceFrame frame) { |
| 42 const gfx::Rect bounds(ui_window_->bounds().size()); | 43 const gfx::Rect bounds(ui_window_->bounds().size()); |
| 43 cc::CompositorFrame ui_frame; | 44 cc::CompositorFrame ui_frame; |
| 44 ui_frame.metadata.latency_info = std::move(frame.latency_info); | 45 ui_frame.metadata.latency_info = std::move(frame.latency_info); |
| 45 // Reset latency_info to known empty state after moving contents. | 46 // Reset latency_info to known empty state after moving contents. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 const bool secure_output_only = false; | 99 const bool secure_output_only = false; |
| 99 | 100 |
| 100 cc::TextureDrawQuad* quad = | 101 cc::TextureDrawQuad* quad = |
| 101 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); | 102 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); |
| 102 quad->SetAll(sqs, rect, rect, rect, needs_blending, resource.id, gfx::Size(), | 103 quad->SetAll(sqs, rect, rect, rect, needs_blending, resource.id, gfx::Size(), |
| 103 premultiplied_alpha, uv_top_left, uv_bottom_right, | 104 premultiplied_alpha, uv_top_left, uv_bottom_right, |
| 104 background_color, vertex_opacity, y_flipped, nearest_neighbor, | 105 background_color, vertex_opacity, y_flipped, nearest_neighbor, |
| 105 secure_output_only); | 106 secure_output_only); |
| 106 | 107 |
| 107 ui_frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 108 ui_frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
| 108 // ui_frame_surface_ will be destroyed by MusBrowserCompositorOutputSurface's | 109 ui_compositor_frame_sink_->SubmitCompositorFrame(std::move(ui_frame)); |
| 109 // destructor, and the callback of SubmitCompositorFrame() will not be fired | |
| 110 // after ui_window_surface_ is destroyed, so it is safe to use | |
| 111 // base::Unretained(this) here. | |
| 112 ui_window_surface_->SubmitCompositorFrame( | |
| 113 std::move(ui_frame), | |
| 114 base::Bind(&MusBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted, | |
| 115 base::Unretained(this), std::vector<ui::LatencyInfo>(), | |
| 116 gfx::SwapResult::SWAP_ACK, nullptr)); | |
| 117 return; | 110 return; |
| 118 } | 111 } |
| 119 | 112 |
| 120 bool MusBrowserCompositorOutputSurface::BindToClient( | 113 bool MusBrowserCompositorOutputSurface::BindToClient( |
| 121 cc::OutputSurfaceClient* client) { | 114 cc::OutputSurfaceClient* client) { |
| 122 if (!GpuBrowserCompositorOutputSurface::BindToClient(client)) | 115 if (!GpuBrowserCompositorOutputSurface::BindToClient(client)) |
| 123 return false; | 116 return false; |
| 124 ui_window_surface_->BindToThread(); | 117 ui_compositor_frame_sink_->BindToClient(this); |
| 125 ui_window_surface_->set_client(this); | |
| 126 return true; | 118 return true; |
| 127 } | 119 } |
| 128 | 120 |
| 129 void MusBrowserCompositorOutputSurface::OnResourcesReturned( | 121 void MusBrowserCompositorOutputSurface::SetBeginFrameSource( |
| 130 ui::WindowSurface* surface, | 122 cc::BeginFrameSource* source) {} |
| 123 |
| 124 void MusBrowserCompositorOutputSurface::ReclaimResources( |
| 131 const cc::ReturnedResourceArray& resources) { | 125 const cc::ReturnedResourceArray& resources) { |
| 132 for (const auto& resource : resources) { | 126 for (const auto& resource : resources) { |
| 133 DCHECK_EQ(1, resource.count); | 127 DCHECK_EQ(1, resource.count); |
| 134 const gpu::Mailbox& mailbox = GetMailboxFromResourceId(resource.id); | 128 const gpu::Mailbox& mailbox = GetMailboxFromResourceId(resource.id); |
| 135 GetCommandBufferProxy()->ReturnFrontBuffer(mailbox, resource.sync_token, | 129 GetCommandBufferProxy()->ReturnFrontBuffer(mailbox, resource.sync_token, |
| 136 resource.lost); | 130 resource.lost); |
| 137 FreeResourceId(resource.id); | 131 FreeResourceId(resource.id); |
| 138 } | 132 } |
| 139 } | 133 } |
| 140 | 134 |
| 135 void MusBrowserCompositorOutputSurface::SetTreeActivationCallback( |
| 136 const base::Closure& callback) {} |
| 137 |
| 138 void MusBrowserCompositorOutputSurface::DidReceiveCompositorFrameAck() { |
| 139 OnGpuSwapBuffersCompleted(std::vector<ui::LatencyInfo>(), |
| 140 gfx::SwapResult::SWAP_ACK, nullptr); |
| 141 } |
| 142 |
| 143 void MusBrowserCompositorOutputSurface::DidLoseCompositorFrameSink() {} |
| 144 |
| 145 void MusBrowserCompositorOutputSurface::OnDraw( |
| 146 const gfx::Transform& transform, |
| 147 const gfx::Rect& viewport, |
| 148 bool resourceless_software_draw) {} |
| 149 |
| 150 void MusBrowserCompositorOutputSurface::SetMemoryPolicy( |
| 151 const cc::ManagedMemoryPolicy& policy) {} |
| 152 |
| 153 void MusBrowserCompositorOutputSurface::SetExternalTilePriorityConstraints( |
| 154 const gfx::Rect& viewport_rect, |
| 155 const gfx::Transform& transform) {} |
| 156 |
| 141 uint32_t MusBrowserCompositorOutputSurface::AllocateResourceId() { | 157 uint32_t MusBrowserCompositorOutputSurface::AllocateResourceId() { |
| 142 if (!free_resource_ids_.empty()) { | 158 if (!free_resource_ids_.empty()) { |
| 143 uint32_t id = free_resource_ids_.back(); | 159 uint32_t id = free_resource_ids_.back(); |
| 144 free_resource_ids_.pop_back(); | 160 free_resource_ids_.pop_back(); |
| 145 return id; | 161 return id; |
| 146 } | 162 } |
| 147 // If there is no free resource id, we generate a new mailbox in the mailbox | 163 // If there is no free resource id, we generate a new mailbox in the mailbox |
| 148 // vector, and the index of the new mailbox is the new allocated resource id. | 164 // vector, and the index of the new mailbox is the new allocated resource id. |
| 149 uint32_t id = mailboxes_.size(); | 165 uint32_t id = mailboxes_.size(); |
| 150 mailboxes_.push_back(gpu::Mailbox::Generate()); | 166 mailboxes_.push_back(gpu::Mailbox::Generate()); |
| 151 return id; | 167 return id; |
| 152 } | 168 } |
| 153 | 169 |
| 154 void MusBrowserCompositorOutputSurface::FreeResourceId(uint32_t id) { | 170 void MusBrowserCompositorOutputSurface::FreeResourceId(uint32_t id) { |
| 155 DCHECK_LT(id, mailboxes_.size()); | 171 DCHECK_LT(id, mailboxes_.size()); |
| 156 DCHECK(std::find(free_resource_ids_.begin(), free_resource_ids_.end(), id) == | 172 DCHECK(std::find(free_resource_ids_.begin(), free_resource_ids_.end(), id) == |
| 157 free_resource_ids_.end()); | 173 free_resource_ids_.end()); |
| 158 free_resource_ids_.push_back(id); | 174 free_resource_ids_.push_back(id); |
| 159 } | 175 } |
| 160 | 176 |
| 161 const gpu::Mailbox& MusBrowserCompositorOutputSurface::GetMailboxFromResourceId( | 177 const gpu::Mailbox& MusBrowserCompositorOutputSurface::GetMailboxFromResourceId( |
| 162 uint32_t id) { | 178 uint32_t id) { |
| 163 DCHECK_LT(id, mailboxes_.size()); | 179 DCHECK_LT(id, mailboxes_.size()); |
| 164 DCHECK(std::find(free_resource_ids_.begin(), free_resource_ids_.end(), id) == | 180 DCHECK(std::find(free_resource_ids_.begin(), free_resource_ids_.end(), id) == |
| 165 free_resource_ids_.end()); | 181 free_resource_ids_.end()); |
| 166 return mailboxes_[id]; | 182 return mailboxes_[id]; |
| 167 } | 183 } |
| 168 | 184 |
| 169 } // namespace content | 185 } // namespace content |
| OLD | NEW |