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