| 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 "services/ui/ws/server_window_surface.h" | 5 #include "services/ui/ws/server_window_surface.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/quads/shared_quad_state.h" | 9 #include "cc/quads/shared_quad_state.h" |
| 10 #include "cc/quads/surface_draw_quad.h" | 10 #include "cc/quads/surface_draw_quad.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 callback.Run(); | 21 callback.Run(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 ServerWindowSurface::ServerWindowSurface( | 26 ServerWindowSurface::ServerWindowSurface( |
| 27 ServerWindowSurfaceManager* manager, | 27 ServerWindowSurfaceManager* manager, |
| 28 mojo::InterfaceRequest<Surface> request, | 28 mojo::InterfaceRequest<Surface> request, |
| 29 mojom::SurfaceClientPtr client) | 29 mojom::SurfaceClientPtr client) |
| 30 : manager_(manager), | 30 : manager_(manager), |
| 31 surface_id_(manager->GenerateId()), | 31 surface_id_allocator_( |
| 32 manager->window()->delegate()->GetSurfacesState()->next_client_id()), |
| 32 surface_factory_(manager_->GetSurfaceManager(), this), | 33 surface_factory_(manager_->GetSurfaceManager(), this), |
| 33 client_(std::move(client)), | 34 client_(std::move(client)), |
| 34 binding_(this, std::move(request)), | 35 binding_(this, std::move(request)) { |
| 35 registered_surface_factory_client_(false) { | 36 cc::SurfaceManager* surface_manager = manager_->GetSurfaceManager(); |
| 36 surface_factory_.Create(surface_id_); | 37 surface_id_allocator_.RegisterSurfaceClientId(surface_manager); |
| 38 surface_manager->RegisterSurfaceFactoryClient( |
| 39 surface_id_allocator_.client_id(), this); |
| 37 } | 40 } |
| 38 | 41 |
| 39 ServerWindowSurface::~ServerWindowSurface() { | 42 ServerWindowSurface::~ServerWindowSurface() { |
| 40 // SurfaceFactory's destructor will attempt to return resources which will | 43 // SurfaceFactory's destructor will attempt to return resources which will |
| 41 // call back into here and access |client_| so we should destroy | 44 // call back into here and access |client_| so we should destroy |
| 42 // |surface_factory_|'s resources early on. | 45 // |surface_factory_|'s resources early on. |
| 43 surface_factory_.DestroyAll(); | 46 surface_factory_.DestroyAll(); |
| 44 | 47 cc::SurfaceManager* surface_manager = manager_->GetSurfaceManager(); |
| 45 if (registered_surface_factory_client_) { | 48 surface_manager->UnregisterSurfaceFactoryClient( |
| 46 cc::SurfaceManager* surface_manager = manager_->GetSurfaceManager(); | 49 surface_id_allocator_.client_id()); |
| 47 surface_manager->UnregisterSurfaceFactoryClient(manager_->client_id()); | |
| 48 } | |
| 49 } | 50 } |
| 50 | 51 |
| 51 void ServerWindowSurface::SubmitCompositorFrame( | 52 void ServerWindowSurface::SubmitCompositorFrame( |
| 52 cc::CompositorFrame frame, | 53 cc::CompositorFrame frame, |
| 53 const SubmitCompositorFrameCallback& callback) { | 54 const SubmitCompositorFrameCallback& callback) { |
| 54 gfx::Size frame_size = | 55 gfx::Size frame_size = |
| 55 frame.delegated_frame_data->render_pass_list[0]->output_rect.size(); | 56 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 |
| 57 // If the size of the CompostiorFrame has changed then destroy the existing | 58 // Surface and create a new one of the appropriate size. |
| 58 // Surface and create a new one of the appropriate size. | 59 if (surface_id_.is_null() || frame_size != last_submitted_frame_size_) { |
| 59 if (frame_size != last_submitted_frame_size_) { | 60 // Rendering of the topmost frame happens in two phases. First the frame |
| 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. |
| 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 |
| 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 |
| 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 |
| 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 |
| 65 // us back when we're not waiting on a frame to be drawn (which may be | 66 // synchronously). |
| 66 // synchronously). | 67 if (!surface_id_.is_null()) { |
| 67 surfaces_scheduled_for_destruction_.insert(surface_id_); | 68 surfaces_scheduled_for_destruction_.insert(surface_id_); |
| 68 window()->delegate()->ScheduleSurfaceDestruction(window()); | 69 window()->delegate()->ScheduleSurfaceDestruction(window()); |
| 69 surface_id_ = manager_->GenerateId(); | |
| 70 surface_factory_.Create(surface_id_); | |
| 71 } | 70 } |
| 71 surface_id_ = surface_id_allocator_.GenerateId(); |
| 72 surface_factory_.Create(surface_id_); |
| 72 } | 73 } |
| 73 surface_factory_.SubmitCompositorFrame(surface_id_, std::move(frame), | 74 surface_factory_.SubmitCompositorFrame(surface_id_, std::move(frame), |
| 74 base::Bind(&CallCallback, callback)); | 75 base::Bind(&CallCallback, callback)); |
| 75 last_submitted_frame_size_ = frame_size; | 76 last_submitted_frame_size_ = frame_size; |
| 76 window()->delegate()->OnScheduleWindowPaint(window()); | 77 window()->delegate()->OnScheduleWindowPaint(window()); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void ServerWindowSurface::DestroySurfacesScheduledForDestruction() { | 80 void ServerWindowSurface::DestroySurfacesScheduledForDestruction() { |
| 80 std::set<cc::SurfaceId> surfaces; | 81 std::set<cc::SurfaceId> surfaces; |
| 81 surfaces.swap(surfaces_scheduled_for_destruction_); | 82 surfaces.swap(surfaces_scheduled_for_destruction_); |
| 82 for (auto& id : surfaces) | 83 for (auto& id : surfaces) |
| 83 surface_factory_.Destroy(id); | 84 surface_factory_.Destroy(id); |
| 84 } | 85 } |
| 85 | 86 |
| 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_->client_id(), this); | |
| 91 } | |
| 92 | |
| 93 ServerWindow* ServerWindowSurface::window() { | 87 ServerWindow* ServerWindowSurface::window() { |
| 94 return manager_->window(); | 88 return manager_->window(); |
| 95 } | 89 } |
| 96 | 90 |
| 97 void ServerWindowSurface::ReturnResources( | 91 void ServerWindowSurface::ReturnResources( |
| 98 const cc::ReturnedResourceArray& resources) { | 92 const cc::ReturnedResourceArray& resources) { |
| 99 if (!client_ || !base::MessageLoop::current()) | 93 if (!client_ || !base::MessageLoop::current()) |
| 100 return; | 94 return; |
| 101 client_->ReturnResources(mojo::Array<cc::ReturnedResource>::From(resources)); | 95 client_->ReturnResources(mojo::Array<cc::ReturnedResource>::From(resources)); |
| 102 } | 96 } |
| 103 | 97 |
| 104 void ServerWindowSurface::SetBeginFrameSource( | 98 void ServerWindowSurface::SetBeginFrameSource( |
| 105 cc::BeginFrameSource* begin_frame_source) { | 99 cc::BeginFrameSource* begin_frame_source) { |
| 106 // TODO(tansell): Implement this. | 100 // TODO(tansell): Implement this. |
| 107 } | 101 } |
| 108 | 102 |
| 109 } // namespace ws | 103 } // namespace ws |
| 110 } // namespace ui | 104 } // namespace ui |
| OLD | NEW |