| 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_manager.h" | 5 #include "services/ui/ws/server_window_surface_manager.h" |
| 6 | 6 |
| 7 #include "services/ui/surfaces/surfaces_state.h" | 7 #include "services/ui/surfaces/surfaces_state.h" |
| 8 #include "services/ui/ws/server_window.h" | 8 #include "services/ui/ws/server_window.h" |
| 9 #include "services/ui/ws/server_window_delegate.h" | 9 #include "services/ui/ws/server_window_delegate.h" |
| 10 #include "services/ui/ws/server_window_surface.h" | 10 #include "services/ui/ws/server_window_surface.h" |
| 11 | 11 |
| 12 namespace ui { | 12 namespace ui { |
| 13 namespace ws { | 13 namespace ws { |
| 14 | 14 |
| 15 ServerWindowSurfaceManager::ServerWindowSurfaceManager(ServerWindow* window) | 15 ServerWindowSurfaceManager::ServerWindowSurfaceManager(ServerWindow* window) |
| 16 : window_(window), | 16 : window_(window), |
| 17 surface_id_allocator_( | |
| 18 window->delegate()->GetSurfacesState()->next_client_id()), | |
| 19 waiting_for_initial_frames_( | 17 waiting_for_initial_frames_( |
| 20 window_->properties().count(ui::mojom::kWaitForUnderlay_Property) > | 18 window_->properties().count(ui::mojom::kWaitForUnderlay_Property) > |
| 21 0) { | 19 0) { |
| 22 surface_id_allocator_.RegisterSurfaceClientId(GetSurfaceManager()); | |
| 23 } | 20 } |
| 24 | 21 |
| 25 ServerWindowSurfaceManager::~ServerWindowSurfaceManager() { | 22 ServerWindowSurfaceManager::~ServerWindowSurfaceManager() { |
| 26 // Explicitly clear the type to surface manager so that this manager | 23 // Explicitly clear the type to surface manager so that this manager |
| 27 // is still valid prior during ~ServerWindowSurface. | 24 // is still valid prior during ~ServerWindowSurface. |
| 28 type_to_surface_map_.clear(); | 25 type_to_surface_map_.clear(); |
| 29 } | 26 } |
| 30 | 27 |
| 31 bool ServerWindowSurfaceManager::ShouldDraw() { | 28 bool ServerWindowSurfaceManager::ShouldDraw() { |
| 32 if (!waiting_for_initial_frames_) | 29 if (!waiting_for_initial_frames_) |
| 33 return true; | 30 return true; |
| 34 | 31 |
| 35 waiting_for_initial_frames_ = | 32 waiting_for_initial_frames_ = |
| 36 !IsSurfaceReadyAndNonEmpty(mojom::SurfaceType::DEFAULT) || | 33 !IsSurfaceReadyAndNonEmpty(mojom::SurfaceType::DEFAULT) || |
| 37 !IsSurfaceReadyAndNonEmpty(mojom::SurfaceType::UNDERLAY); | 34 !IsSurfaceReadyAndNonEmpty(mojom::SurfaceType::UNDERLAY); |
| 38 return !waiting_for_initial_frames_; | 35 return !waiting_for_initial_frames_; |
| 39 } | 36 } |
| 40 | 37 |
| 41 void ServerWindowSurfaceManager::CreateSurface( | 38 void ServerWindowSurfaceManager::CreateSurface( |
| 42 mojom::SurfaceType surface_type, | 39 mojom::SurfaceType surface_type, |
| 43 mojo::InterfaceRequest<mojom::Surface> request, | 40 mojo::InterfaceRequest<mojom::Surface> request, |
| 44 mojom::SurfaceClientPtr client) { | 41 mojom::SurfaceClientPtr client) { |
| 45 std::unique_ptr<ServerWindowSurface> surface( | 42 std::unique_ptr<ServerWindowSurface> surface( |
| 46 new ServerWindowSurface(this, std::move(request), std::move(client))); | 43 new ServerWindowSurface(this, std::move(request), std::move(client))); |
| 47 if (!HasAnySurface()) { | |
| 48 // Only one SurfaceFactoryClient can be registered per surface id namespace, | |
| 49 // so register the first one. Since all surfaces created by this manager | |
| 50 // represent the same window, the begin frame source can be shared by | |
| 51 // all surfaces created here. | |
| 52 surface->RegisterForBeginFrames(); | |
| 53 } | |
| 54 type_to_surface_map_[surface_type] = std::move(surface); | 44 type_to_surface_map_[surface_type] = std::move(surface); |
| 55 } | 45 } |
| 56 | 46 |
| 57 ServerWindowSurface* ServerWindowSurfaceManager::GetDefaultSurface() const { | 47 ServerWindowSurface* ServerWindowSurfaceManager::GetDefaultSurface() const { |
| 58 return GetSurfaceByType(mojom::SurfaceType::DEFAULT); | 48 return GetSurfaceByType(mojom::SurfaceType::DEFAULT); |
| 59 } | 49 } |
| 60 | 50 |
| 61 ServerWindowSurface* ServerWindowSurfaceManager::GetUnderlaySurface() const { | 51 ServerWindowSurface* ServerWindowSurfaceManager::GetUnderlaySurface() const { |
| 62 return GetSurfaceByType(mojom::SurfaceType::UNDERLAY); | 52 return GetSurfaceByType(mojom::SurfaceType::UNDERLAY); |
| 63 } | 53 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 87 if (iter == type_to_surface_map_.end()) | 77 if (iter == type_to_surface_map_.end()) |
| 88 return false; | 78 return false; |
| 89 if (iter->second->last_submitted_frame_size().IsEmpty()) | 79 if (iter->second->last_submitted_frame_size().IsEmpty()) |
| 90 return false; | 80 return false; |
| 91 const gfx::Size& last_submitted_frame_size = | 81 const gfx::Size& last_submitted_frame_size = |
| 92 iter->second->last_submitted_frame_size(); | 82 iter->second->last_submitted_frame_size(); |
| 93 return last_submitted_frame_size.width() >= window_->bounds().width() && | 83 return last_submitted_frame_size.width() >= window_->bounds().width() && |
| 94 last_submitted_frame_size.height() >= window_->bounds().height(); | 84 last_submitted_frame_size.height() >= window_->bounds().height(); |
| 95 } | 85 } |
| 96 | 86 |
| 97 cc::SurfaceId ServerWindowSurfaceManager::GenerateId() { | |
| 98 return surface_id_allocator_.GenerateId(); | |
| 99 } | |
| 100 | |
| 101 } // namespace ws | 87 } // namespace ws |
| 102 } // namespace ui | 88 } // namespace ui |
| OLD | NEW |