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_compositor_frame_sink_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_compositor_frame_sink.h" |
| 11 #include "services/ui/ws/server_window_delegate.h" |
| 12 |
| 13 namespace ui { |
| 14 namespace ws { |
| 15 |
| 16 ServerWindowCompositorFrameSinkManager::ServerWindowCompositorFrameSinkManager( |
| 17 ServerWindow* window) |
| 18 : window_(window), |
| 19 waiting_for_initial_frames_( |
| 20 window_->properties().count(ui::mojom::kWaitForUnderlay_Property) > |
| 21 0) {} |
| 22 |
| 23 ServerWindowCompositorFrameSinkManager:: |
| 24 ~ServerWindowCompositorFrameSinkManager() { |
| 25 // Explicitly clear the type to surface manager so that this manager |
| 26 // is still valid prior during ~ServerWindowCompositorFrameSink. |
| 27 type_to_compositor_frame_sink_map_.clear(); |
| 28 } |
| 29 |
| 30 bool ServerWindowCompositorFrameSinkManager::ShouldDraw() { |
| 31 if (!waiting_for_initial_frames_) |
| 32 return true; |
| 33 |
| 34 waiting_for_initial_frames_ = !IsCompositorFrameSinkReadyAndNonEmpty( |
| 35 mojom::CompositorFrameSinkType::DEFAULT) || |
| 36 !IsCompositorFrameSinkReadyAndNonEmpty( |
| 37 mojom::CompositorFrameSinkType::UNDERLAY); |
| 38 return !waiting_for_initial_frames_; |
| 39 } |
| 40 |
| 41 void ServerWindowCompositorFrameSinkManager::CreateCompositorFrameSink( |
| 42 mojom::CompositorFrameSinkType compositor_frame_sink_type, |
| 43 mojo::InterfaceRequest<cc::mojom::MojoCompositorFrameSink> request, |
| 44 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 45 cc::FrameSinkId frame_sink_id( |
| 46 WindowIdToTransportId(window_->id()), |
| 47 static_cast<uint32_t>(compositor_frame_sink_type)); |
| 48 std::unique_ptr<ServerWindowCompositorFrameSink> compositor_frame_sink( |
| 49 new ServerWindowCompositorFrameSink( |
| 50 this, frame_sink_id, std::move(request), std::move(client))); |
| 51 type_to_compositor_frame_sink_map_[compositor_frame_sink_type] = |
| 52 std::move(compositor_frame_sink); |
| 53 } |
| 54 |
| 55 ServerWindowCompositorFrameSink* |
| 56 ServerWindowCompositorFrameSinkManager::GetDefaultCompositorFrameSink() const { |
| 57 return GetCompositorFrameSinkByType(mojom::CompositorFrameSinkType::DEFAULT); |
| 58 } |
| 59 |
| 60 ServerWindowCompositorFrameSink* |
| 61 ServerWindowCompositorFrameSinkManager::GetUnderlayCompositorFrameSink() const { |
| 62 return GetCompositorFrameSinkByType(mojom::CompositorFrameSinkType::UNDERLAY); |
| 63 } |
| 64 |
| 65 ServerWindowCompositorFrameSink* |
| 66 ServerWindowCompositorFrameSinkManager::GetCompositorFrameSinkByType( |
| 67 mojom::CompositorFrameSinkType type) const { |
| 68 auto iter = type_to_compositor_frame_sink_map_.find(type); |
| 69 return iter == type_to_compositor_frame_sink_map_.end() ? nullptr |
| 70 : iter->second.get(); |
| 71 } |
| 72 |
| 73 bool ServerWindowCompositorFrameSinkManager::HasCompositorFrameSinkOfType( |
| 74 mojom::CompositorFrameSinkType type) const { |
| 75 return type_to_compositor_frame_sink_map_.count(type) > 0; |
| 76 } |
| 77 |
| 78 bool ServerWindowCompositorFrameSinkManager::HasAnyCompositorFrameSink() const { |
| 79 return GetDefaultCompositorFrameSink() || GetUnderlayCompositorFrameSink(); |
| 80 } |
| 81 |
| 82 cc::SurfaceManager* |
| 83 ServerWindowCompositorFrameSinkManager::GetCompositorFrameSinkManager() { |
| 84 return window()->delegate()->GetDisplayCompositor()->manager(); |
| 85 } |
| 86 |
| 87 bool ServerWindowCompositorFrameSinkManager:: |
| 88 IsCompositorFrameSinkReadyAndNonEmpty( |
| 89 mojom::CompositorFrameSinkType type) const { |
| 90 auto iter = type_to_compositor_frame_sink_map_.find(type); |
| 91 if (iter == type_to_compositor_frame_sink_map_.end()) |
| 92 return false; |
| 93 if (iter->second->last_submitted_frame_size().IsEmpty()) |
| 94 return false; |
| 95 const gfx::Size& last_submitted_frame_size = |
| 96 iter->second->last_submitted_frame_size(); |
| 97 return last_submitted_frame_size.width() >= window_->bounds().width() && |
| 98 last_submitted_frame_size.height() >= window_->bounds().height(); |
| 99 } |
| 100 |
| 101 } // namespace ws |
| 102 } // namespace ui |
OLD | NEW |