| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/mus/ws/server_window_surface.h" | |
| 6 | |
| 7 #include "base/callback.h" | |
| 8 #include "cc/output/compositor_frame.h" | |
| 9 #include "cc/quads/shared_quad_state.h" | |
| 10 #include "cc/quads/surface_draw_quad.h" | |
| 11 #include "components/mus/surfaces/surfaces_state.h" | |
| 12 #include "components/mus/ws/server_window.h" | |
| 13 #include "components/mus/ws/server_window_delegate.h" | |
| 14 #include "components/mus/ws/server_window_surface_manager.h" | |
| 15 | |
| 16 namespace mus { | |
| 17 namespace ws { | |
| 18 namespace { | |
| 19 | |
| 20 void CallCallback(const base::Closure& callback, cc::SurfaceDrawStatus status) { | |
| 21 callback.Run(); | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 ServerWindowSurface::ServerWindowSurface( | |
| 27 ServerWindowSurfaceManager* manager, | |
| 28 mojo::InterfaceRequest<Surface> request, | |
| 29 mojom::SurfaceClientPtr client) | |
| 30 : manager_(manager), | |
| 31 surface_id_(manager->GenerateId()), | |
| 32 surface_factory_(manager_->GetSurfaceManager(), this), | |
| 33 client_(std::move(client)), | |
| 34 binding_(this, std::move(request)), | |
| 35 registered_surface_factory_client_(false) { | |
| 36 surface_factory_.Create(surface_id_); | |
| 37 } | |
| 38 | |
| 39 ServerWindowSurface::~ServerWindowSurface() { | |
| 40 // SurfaceFactory's destructor will attempt to return resources which will | |
| 41 // call back into here and access |client_| so we should destroy | |
| 42 // |surface_factory_|'s resources early on. | |
| 43 surface_factory_.DestroyAll(); | |
| 44 | |
| 45 if (registered_surface_factory_client_) { | |
| 46 cc::SurfaceManager* surface_manager = manager_->GetSurfaceManager(); | |
| 47 surface_manager->UnregisterSurfaceFactoryClient(manager_->id_namespace()); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 void ServerWindowSurface::SubmitCompositorFrame( | |
| 52 cc::CompositorFrame frame, | |
| 53 const SubmitCompositorFrameCallback& callback) { | |
| 54 gfx::Size frame_size = | |
| 55 frame.delegated_frame_data->render_pass_list[0]->output_rect.size(); | |
| 56 if (!surface_id_.is_null()) { | |
| 57 // If the size of the CompostiorFrame has changed then destroy the existing | |
| 58 // Surface and create a new one of the appropriate size. | |
| 59 if (frame_size != last_submitted_frame_size_) { | |
| 60 // Rendering of the topmost frame happens in two phases. First the frame | |
| 61 // is generated and submitted, and a later date it is actually drawn. | |
| 62 // During the time the frame is generated and drawn we can't destroy the | |
| 63 // surface, otherwise when drawn you get an empty surface. To deal with | |
| 64 // this we schedule destruction via the delegate. The delegate will call | |
| 65 // us back when we're not waiting on a frame to be drawn (which may be | |
| 66 // synchronously). | |
| 67 surfaces_scheduled_for_destruction_.insert(surface_id_); | |
| 68 window()->delegate()->ScheduleSurfaceDestruction(window()); | |
| 69 surface_id_ = manager_->GenerateId(); | |
| 70 surface_factory_.Create(surface_id_); | |
| 71 } | |
| 72 } | |
| 73 surface_factory_.SubmitCompositorFrame(surface_id_, std::move(frame), | |
| 74 base::Bind(&CallCallback, callback)); | |
| 75 last_submitted_frame_size_ = frame_size; | |
| 76 window()->delegate()->OnScheduleWindowPaint(window()); | |
| 77 } | |
| 78 | |
| 79 void ServerWindowSurface::DestroySurfacesScheduledForDestruction() { | |
| 80 std::set<cc::SurfaceId> surfaces; | |
| 81 surfaces.swap(surfaces_scheduled_for_destruction_); | |
| 82 for (auto& id : surfaces) | |
| 83 surface_factory_.Destroy(id); | |
| 84 } | |
| 85 | |
| 86 void ServerWindowSurface::RegisterForBeginFrames() { | |
| 87 DCHECK(!registered_surface_factory_client_); | |
| 88 registered_surface_factory_client_ = true; | |
| 89 cc::SurfaceManager* surface_manager = manager_->GetSurfaceManager(); | |
| 90 surface_manager->RegisterSurfaceFactoryClient(manager_->id_namespace(), this); | |
| 91 } | |
| 92 | |
| 93 ServerWindow* ServerWindowSurface::window() { | |
| 94 return manager_->window(); | |
| 95 } | |
| 96 | |
| 97 void ServerWindowSurface::ReturnResources( | |
| 98 const cc::ReturnedResourceArray& resources) { | |
| 99 if (!client_ || !base::MessageLoop::current()) | |
| 100 return; | |
| 101 client_->ReturnResources(mojo::Array<cc::ReturnedResource>::From(resources)); | |
| 102 } | |
| 103 | |
| 104 void ServerWindowSurface::SetBeginFrameSource( | |
| 105 cc::BeginFrameSource* begin_frame_source) { | |
| 106 // TODO(tansell): Implement this. | |
| 107 } | |
| 108 | |
| 109 } // namespace ws | |
| 110 } // namespace mus | |
| OLD | NEW |