| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/ws/server_window_surface.h" | 5 #include "components/mus/ws/server_window_surface.h" |
| 6 | 6 |
| 7 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
| 8 #include "cc/quads/shared_quad_state.h" | 8 #include "cc/quads/shared_quad_state.h" |
| 9 #include "cc/quads/surface_draw_quad.h" | 9 #include "cc/quads/surface_draw_quad.h" |
| 10 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" | 10 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // this we schedule destruction via the delegate. The delegate will call | 63 // this we schedule destruction via the delegate. The delegate will call |
| 64 // us back when we're not waiting on a frame to be drawn (which may be | 64 // us back when we're not waiting on a frame to be drawn (which may be |
| 65 // synchronously). | 65 // synchronously). |
| 66 surfaces_scheduled_for_destruction_.insert(surface_id_); | 66 surfaces_scheduled_for_destruction_.insert(surface_id_); |
| 67 window()->delegate()->ScheduleSurfaceDestruction(window()); | 67 window()->delegate()->ScheduleSurfaceDestruction(window()); |
| 68 surface_id_ = manager_->GenerateId(); | 68 surface_id_ = manager_->GenerateId(); |
| 69 surface_factory_.Create(surface_id_); | 69 surface_factory_.Create(surface_id_); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 surface_factory_.SubmitCompositorFrame(surface_id_, | 72 surface_factory_.SubmitCompositorFrame(surface_id_, |
| 73 ConvertCompositorFrame(frame), | 73 ConvertToCompositorFrame(frame), |
| 74 base::Bind(&CallCallback, callback)); | 74 base::Bind(&CallCallback, callback)); |
| 75 last_submitted_frame_size_ = frame_size; | 75 last_submitted_frame_size_ = frame_size; |
| 76 window()->delegate()->OnScheduleWindowPaint(window()); | 76 window()->delegate()->OnScheduleWindowPaint(window()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ServerWindowSurface::DestroySurfacesScheduledForDestruction() { | 79 void ServerWindowSurface::DestroySurfacesScheduledForDestruction() { |
| 80 std::set<cc::SurfaceId> surfaces; | 80 std::set<cc::SurfaceId> surfaces; |
| 81 surfaces.swap(surfaces_scheduled_for_destruction_); | 81 surfaces.swap(surfaces_scheduled_for_destruction_); |
| 82 for (auto& id : surfaces) | 82 for (auto& id : surfaces) |
| 83 surface_factory_.Destroy(id); | 83 surface_factory_.Destroy(id); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void ServerWindowSurface::RegisterForBeginFrames() { | 86 void ServerWindowSurface::RegisterForBeginFrames() { |
| 87 DCHECK(!registered_surface_factory_client_); | 87 DCHECK(!registered_surface_factory_client_); |
| 88 registered_surface_factory_client_ = true; | 88 registered_surface_factory_client_ = true; |
| 89 cc::SurfaceManager* surface_manager = manager_->GetSurfaceManager(); | 89 cc::SurfaceManager* surface_manager = manager_->GetSurfaceManager(); |
| 90 surface_manager->RegisterSurfaceFactoryClient(manager_->id_namespace(), this); | 90 surface_manager->RegisterSurfaceFactoryClient(manager_->id_namespace(), this); |
| 91 } | 91 } |
| 92 | 92 |
| 93 ServerWindow* ServerWindowSurface::window() { | 93 ServerWindow* ServerWindowSurface::window() { |
| 94 return manager_->window(); | 94 return manager_->window(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 std::unique_ptr<cc::CompositorFrame> | |
| 98 ServerWindowSurface::ConvertCompositorFrame( | |
| 99 const mojom::CompositorFramePtr& input) { | |
| 100 referenced_window_ids_.clear(); | |
| 101 return ConvertToCompositorFrame(input, this); | |
| 102 } | |
| 103 | |
| 104 bool ServerWindowSurface::ConvertSurfaceDrawQuad( | |
| 105 const cc::mojom::DrawQuadPtr& input, | |
| 106 const cc::CompositorFrameMetadata& metadata, | |
| 107 cc::SharedQuadState* sqs, | |
| 108 cc::RenderPass* render_pass) { | |
| 109 // Surface ids originate from the client, meaning they are ClientWindowIds | |
| 110 // and can only be resolved by the client that submitted the frame. | |
| 111 const ClientWindowId other_client_window_id( | |
| 112 input->surface_quad_state->surface.local_id()); | |
| 113 ServerWindow* other_window = window()->delegate()->FindWindowForSurface( | |
| 114 window(), mojom::SurfaceType::DEFAULT, other_client_window_id); | |
| 115 if (!other_window) { | |
| 116 DVLOG(2) << "The window ID '" << other_client_window_id.id | |
| 117 << "' does not exist."; | |
| 118 // TODO(fsamuel): We return true here so that the CompositorFrame isn't | |
| 119 // entirely rejected. We just drop this SurfaceDrawQuad. This failure | |
| 120 // can happen if the client has an out of date view of the window tree. | |
| 121 // It would be nice if we can avoid reaching this state in the future. | |
| 122 return true; | |
| 123 } | |
| 124 | |
| 125 referenced_window_ids_.insert(other_window->id()); | |
| 126 | |
| 127 ServerWindowSurface* default_surface = | |
| 128 other_window->GetOrCreateSurfaceManager()->GetDefaultSurface(); | |
| 129 ServerWindowSurface* underlay_surface = | |
| 130 other_window->GetOrCreateSurfaceManager()->GetUnderlaySurface(); | |
| 131 | |
| 132 if (!default_surface && !underlay_surface) | |
| 133 return true; | |
| 134 | |
| 135 cc::SurfaceDrawQuad* surface_quad = | |
| 136 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | |
| 137 if (default_surface) { | |
| 138 surface_quad->SetAll(sqs, input->rect, input->opaque_rect, | |
| 139 input->visible_rect, input->needs_blending, | |
| 140 default_surface->id()); | |
| 141 } | |
| 142 if (underlay_surface) { | |
| 143 cc::SurfaceDrawQuad* underlay_quad = | |
| 144 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | |
| 145 underlay_quad->SetAll(sqs, input->rect, input->opaque_rect, | |
| 146 input->visible_rect, input->needs_blending, | |
| 147 underlay_surface->id()); | |
| 148 } | |
| 149 return true; | |
| 150 } | |
| 151 | |
| 152 void ServerWindowSurface::ReturnResources( | 97 void ServerWindowSurface::ReturnResources( |
| 153 const cc::ReturnedResourceArray& resources) { | 98 const cc::ReturnedResourceArray& resources) { |
| 154 if (!client_ || !base::MessageLoop::current()) | 99 if (!client_ || !base::MessageLoop::current()) |
| 155 return; | 100 return; |
| 156 client_->ReturnResources(mojo::Array<cc::ReturnedResource>::From(resources)); | 101 client_->ReturnResources(mojo::Array<cc::ReturnedResource>::From(resources)); |
| 157 } | 102 } |
| 158 | 103 |
| 159 void ServerWindowSurface::SetBeginFrameSource( | 104 void ServerWindowSurface::SetBeginFrameSource( |
| 160 cc::BeginFrameSource* begin_frame_source) { | 105 cc::BeginFrameSource* begin_frame_source) { |
| 161 // TODO(tansell): Implement this. | 106 // TODO(tansell): Implement this. |
| 162 } | 107 } |
| 163 | 108 |
| 164 } // namespace ws | 109 } // namespace ws |
| 165 } // namespace mus | 110 } // namespace mus |
| OLD | NEW |