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 "services/ui/ws/server_window_surface_manager.h" | |
6 | |
7 #include "services/ui/surfaces/display_compositor.h" | |
8 #include "services/ui/ws/ids.h" | |
9 #include "services/ui/ws/server_window.h" | |
10 #include "services/ui/ws/server_window_delegate.h" | |
11 #include "services/ui/ws/server_window_surface.h" | |
12 | |
13 namespace ui { | |
14 namespace ws { | |
15 | |
16 ServerWindowSurfaceManager::ServerWindowSurfaceManager(ServerWindow* window) | |
17 : window_(window), | |
18 waiting_for_initial_frames_( | |
19 window_->properties().count(ui::mojom::kWaitForUnderlay_Property) > | |
20 0) { | |
21 } | |
22 | |
23 ServerWindowSurfaceManager::~ServerWindowSurfaceManager() { | |
24 // Explicitly clear the type to surface manager so that this manager | |
25 // is still valid prior during ~ServerWindowSurface. | |
26 type_to_surface_map_.clear(); | |
27 } | |
28 | |
29 bool ServerWindowSurfaceManager::ShouldDraw() { | |
30 if (!waiting_for_initial_frames_) | |
31 return true; | |
32 | |
33 waiting_for_initial_frames_ = | |
34 !IsSurfaceReadyAndNonEmpty(mojom::SurfaceType::DEFAULT) || | |
35 !IsSurfaceReadyAndNonEmpty(mojom::SurfaceType::UNDERLAY); | |
36 return !waiting_for_initial_frames_; | |
37 } | |
38 | |
39 void ServerWindowSurfaceManager::CreateSurface( | |
40 mojom::SurfaceType surface_type, | |
41 mojo::InterfaceRequest<cc::mojom::MojoCompositorFrameSink> request, | |
42 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | |
43 cc::FrameSinkId frame_sink_id(WindowIdToTransportId(window_->id()), | |
44 static_cast<uint32_t>(surface_type)); | |
45 std::unique_ptr<ServerWindowSurface> surface(new ServerWindowSurface( | |
46 this, frame_sink_id, std::move(request), std::move(client))); | |
47 type_to_surface_map_[surface_type] = std::move(surface); | |
48 } | |
49 | |
50 ServerWindowSurface* ServerWindowSurfaceManager::GetDefaultSurface() const { | |
51 return GetSurfaceByType(mojom::SurfaceType::DEFAULT); | |
52 } | |
53 | |
54 ServerWindowSurface* ServerWindowSurfaceManager::GetUnderlaySurface() const { | |
55 return GetSurfaceByType(mojom::SurfaceType::UNDERLAY); | |
56 } | |
57 | |
58 ServerWindowSurface* ServerWindowSurfaceManager::GetSurfaceByType( | |
59 mojom::SurfaceType type) const { | |
60 auto iter = type_to_surface_map_.find(type); | |
61 return iter == type_to_surface_map_.end() ? nullptr : iter->second.get(); | |
62 } | |
63 | |
64 bool ServerWindowSurfaceManager::HasSurfaceOfType( | |
65 mojom::SurfaceType type) const { | |
66 return type_to_surface_map_.count(type) > 0; | |
67 } | |
68 | |
69 bool ServerWindowSurfaceManager::HasAnySurface() const { | |
70 return GetDefaultSurface() || GetUnderlaySurface(); | |
71 } | |
72 | |
73 cc::SurfaceManager* ServerWindowSurfaceManager::GetSurfaceManager() { | |
74 return window()->delegate()->GetDisplayCompositor()->manager(); | |
75 } | |
76 | |
77 bool ServerWindowSurfaceManager::IsSurfaceReadyAndNonEmpty( | |
78 mojom::SurfaceType type) const { | |
79 auto iter = type_to_surface_map_.find(type); | |
80 if (iter == type_to_surface_map_.end()) | |
81 return false; | |
82 if (iter->second->last_submitted_frame_size().IsEmpty()) | |
83 return false; | |
84 const gfx::Size& last_submitted_frame_size = | |
85 iter->second->last_submitted_frame_size(); | |
86 return last_submitted_frame_size.width() >= window_->bounds().width() && | |
87 last_submitted_frame_size.height() >= window_->bounds().height(); | |
88 } | |
89 | |
90 } // namespace ws | |
91 } // namespace ui | |
OLD | NEW |