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