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