| 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_compositor_frame_sink_manager.h" | 5 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 6 | 6 |
| 7 #include "services/ui/surfaces/display_compositor.h" | 7 #include "services/ui/surfaces/display_compositor.h" |
| 8 #include "services/ui/ws/ids.h" | 8 #include "services/ui/ws/ids.h" |
| 9 #include "services/ui/ws/server_window.h" | 9 #include "services/ui/ws/server_window.h" |
| 10 #include "services/ui/ws/server_window_compositor_frame_sink.h" | 10 #include "services/ui/ws/server_window_compositor_frame_sink.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 return !waiting_for_initial_frames_; | 38 return !waiting_for_initial_frames_; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void ServerWindowCompositorFrameSinkManager::CreateCompositorFrameSink( | 41 void ServerWindowCompositorFrameSinkManager::CreateCompositorFrameSink( |
| 42 mojom::CompositorFrameSinkType compositor_frame_sink_type, | 42 mojom::CompositorFrameSinkType compositor_frame_sink_type, |
| 43 mojo::InterfaceRequest<cc::mojom::MojoCompositorFrameSink> request, | 43 mojo::InterfaceRequest<cc::mojom::MojoCompositorFrameSink> request, |
| 44 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 44 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 45 cc::FrameSinkId frame_sink_id( | 45 cc::FrameSinkId frame_sink_id( |
| 46 WindowIdToTransportId(window_->id()), | 46 WindowIdToTransportId(window_->id()), |
| 47 static_cast<uint32_t>(compositor_frame_sink_type)); | 47 static_cast<uint32_t>(compositor_frame_sink_type)); |
| 48 std::unique_ptr<ServerWindowCompositorFrameSink> compositor_frame_sink( | 48 CompositorFrameSinkData data; |
| 49 new ServerWindowCompositorFrameSink( | 49 data.compositor_frame_sink = |
| 50 this, frame_sink_id, std::move(request), std::move(client))); | 50 base::MakeUnique<ServerWindowCompositorFrameSink>( |
| 51 this, frame_sink_id, std::move(request), std::move(client)); |
| 52 |
| 51 type_to_compositor_frame_sink_map_[compositor_frame_sink_type] = | 53 type_to_compositor_frame_sink_map_[compositor_frame_sink_type] = |
| 52 std::move(compositor_frame_sink); | 54 std::move(data); |
| 53 } | 55 } |
| 54 | 56 |
| 55 ServerWindowCompositorFrameSink* | 57 ServerWindowCompositorFrameSink* |
| 56 ServerWindowCompositorFrameSinkManager::GetDefaultCompositorFrameSink() const { | 58 ServerWindowCompositorFrameSinkManager::GetDefaultCompositorFrameSink() const { |
| 57 return GetCompositorFrameSinkByType(mojom::CompositorFrameSinkType::DEFAULT); | 59 return GetCompositorFrameSinkByType(mojom::CompositorFrameSinkType::DEFAULT); |
| 58 } | 60 } |
| 59 | 61 |
| 60 ServerWindowCompositorFrameSink* | 62 ServerWindowCompositorFrameSink* |
| 61 ServerWindowCompositorFrameSinkManager::GetUnderlayCompositorFrameSink() const { | 63 ServerWindowCompositorFrameSinkManager::GetUnderlayCompositorFrameSink() const { |
| 62 return GetCompositorFrameSinkByType(mojom::CompositorFrameSinkType::UNDERLAY); | 64 return GetCompositorFrameSinkByType(mojom::CompositorFrameSinkType::UNDERLAY); |
| 63 } | 65 } |
| 64 | 66 |
| 65 ServerWindowCompositorFrameSink* | 67 ServerWindowCompositorFrameSink* |
| 66 ServerWindowCompositorFrameSinkManager::GetCompositorFrameSinkByType( | 68 ServerWindowCompositorFrameSinkManager::GetCompositorFrameSinkByType( |
| 67 mojom::CompositorFrameSinkType type) const { | 69 mojom::CompositorFrameSinkType type) const { |
| 68 auto iter = type_to_compositor_frame_sink_map_.find(type); | 70 auto iter = type_to_compositor_frame_sink_map_.find(type); |
| 69 return iter == type_to_compositor_frame_sink_map_.end() ? nullptr | 71 return iter == type_to_compositor_frame_sink_map_.end() |
| 70 : iter->second.get(); | 72 ? nullptr |
| 73 : iter->second.compositor_frame_sink.get(); |
| 71 } | 74 } |
| 72 | 75 |
| 73 bool ServerWindowCompositorFrameSinkManager::HasCompositorFrameSinkOfType( | 76 bool ServerWindowCompositorFrameSinkManager::HasCompositorFrameSinkOfType( |
| 74 mojom::CompositorFrameSinkType type) const { | 77 mojom::CompositorFrameSinkType type) const { |
| 75 return type_to_compositor_frame_sink_map_.count(type) > 0; | 78 return type_to_compositor_frame_sink_map_.count(type) > 0; |
| 76 } | 79 } |
| 77 | 80 |
| 78 bool ServerWindowCompositorFrameSinkManager::HasAnyCompositorFrameSink() const { | 81 bool ServerWindowCompositorFrameSinkManager::HasAnyCompositorFrameSink() const { |
| 79 return GetDefaultCompositorFrameSink() || GetUnderlayCompositorFrameSink(); | 82 return GetDefaultCompositorFrameSink() || GetUnderlayCompositorFrameSink(); |
| 80 } | 83 } |
| 81 | 84 |
| 85 gfx::Size ServerWindowCompositorFrameSinkManager::GetLastFrameSize( |
| 86 mojom::CompositorFrameSinkType type) const { |
| 87 auto it = type_to_compositor_frame_sink_map_.find(type); |
| 88 if (it == type_to_compositor_frame_sink_map_.end()) |
| 89 return gfx::Size(); |
| 90 |
| 91 return it->second.last_submitted_frame_size; |
| 92 } |
| 93 |
| 94 cc::SurfaceId ServerWindowCompositorFrameSinkManager::GetLastSurfaceId( |
| 95 mojom::CompositorFrameSinkType type) const { |
| 96 auto it = type_to_compositor_frame_sink_map_.find(type); |
| 97 if (it == type_to_compositor_frame_sink_map_.end()) |
| 98 return cc::SurfaceId(); |
| 99 |
| 100 return it->second.last_submitted_surface_id; |
| 101 } |
| 102 |
| 103 void ServerWindowCompositorFrameSinkManager::SetLastSurfaceId( |
| 104 mojom::CompositorFrameSinkType type, |
| 105 const cc::SurfaceId& surface_id, |
| 106 const gfx::Size& frame_size) { |
| 107 CompositorFrameSinkData& data = type_to_compositor_frame_sink_map_[type]; |
| 108 data.last_submitted_surface_id = surface_id; |
| 109 data.last_submitted_frame_size = frame_size; |
| 110 } |
| 111 |
| 82 cc::SurfaceManager* | 112 cc::SurfaceManager* |
| 83 ServerWindowCompositorFrameSinkManager::GetCompositorFrameSinkManager() { | 113 ServerWindowCompositorFrameSinkManager::GetCompositorFrameSinkManager() { |
| 84 return window()->delegate()->GetDisplayCompositor()->manager(); | 114 return window()->delegate()->GetDisplayCompositor()->manager(); |
| 85 } | 115 } |
| 86 | 116 |
| 87 bool ServerWindowCompositorFrameSinkManager:: | 117 bool ServerWindowCompositorFrameSinkManager:: |
| 88 IsCompositorFrameSinkReadyAndNonEmpty( | 118 IsCompositorFrameSinkReadyAndNonEmpty( |
| 89 mojom::CompositorFrameSinkType type) const { | 119 mojom::CompositorFrameSinkType type) const { |
| 90 auto iter = type_to_compositor_frame_sink_map_.find(type); | 120 auto iter = type_to_compositor_frame_sink_map_.find(type); |
| 91 if (iter == type_to_compositor_frame_sink_map_.end()) | 121 if (iter == type_to_compositor_frame_sink_map_.end()) |
| 92 return false; | 122 return false; |
| 93 if (iter->second->last_submitted_frame_size().IsEmpty()) | 123 if (!iter->second.compositor_frame_sink || |
| 124 iter->second.compositor_frame_sink->last_submitted_frame_size().IsEmpty()) |
| 94 return false; | 125 return false; |
| 95 const gfx::Size& last_submitted_frame_size = | 126 const gfx::Size& last_submitted_frame_size = |
| 96 iter->second->last_submitted_frame_size(); | 127 iter->second.compositor_frame_sink->last_submitted_frame_size(); |
| 97 return last_submitted_frame_size.width() >= window_->bounds().width() && | 128 return last_submitted_frame_size.width() >= window_->bounds().width() && |
| 98 last_submitted_frame_size.height() >= window_->bounds().height(); | 129 last_submitted_frame_size.height() >= window_->bounds().height(); |
| 99 } | 130 } |
| 100 | 131 |
| 132 CompositorFrameSinkData::CompositorFrameSinkData() {} |
| 133 |
| 134 CompositorFrameSinkData::~CompositorFrameSinkData() {} |
| 135 |
| 136 CompositorFrameSinkData::CompositorFrameSinkData( |
| 137 CompositorFrameSinkData&& other) |
| 138 : last_submitted_surface_id(other.last_submitted_surface_id), |
| 139 compositor_frame_sink(std::move(other.compositor_frame_sink)) {} |
| 140 |
| 141 CompositorFrameSinkData& CompositorFrameSinkData::operator=( |
| 142 CompositorFrameSinkData&& other) { |
| 143 last_submitted_surface_id = other.last_submitted_surface_id; |
| 144 compositor_frame_sink = std::move(other.compositor_frame_sink); |
| 145 return *this; |
| 146 } |
| 147 |
| 101 } // namespace ws | 148 } // namespace ws |
| 102 } // namespace ui | 149 } // namespace ui |
| OLD | NEW |