| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/view_manager/display_manager.h" | 5 #include "mojo/services/view_manager/display_manager.h" |
| 6 | 6 |
| 7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
| 8 #include "cc/surfaces/surface_id_allocator.h" | 8 #include "cc/surfaces/surface_id_allocator.h" |
| 9 #include "mojo/public/cpp/application/application_connection.h" | 9 #include "mojo/public/cpp/application/application_connection.h" |
| 10 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 10 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 | 68 |
| 69 } // namespace | 69 } // namespace |
| 70 | 70 |
| 71 DisplayManager::DisplayManager( | 71 DisplayManager::DisplayManager( |
| 72 ApplicationConnection* app_connection, | 72 ApplicationConnection* app_connection, |
| 73 ConnectionManager* connection_manager, | 73 ConnectionManager* connection_manager, |
| 74 const Callback<void()>& native_viewport_closed_callback) | 74 const Callback<void()>& native_viewport_closed_callback) |
| 75 : connection_manager_(connection_manager), | 75 : connection_manager_(connection_manager), |
| 76 in_setup_(false), | 76 in_setup_(false), |
| 77 bounds_(800, 600), | 77 size_(800, 600), |
| 78 draw_timer_(false, false), | 78 draw_timer_(false, false), |
| 79 weak_factory_(this) { | 79 weak_factory_(this) { |
| 80 app_connection->ConnectToService("mojo:mojo_native_viewport_service", | 80 app_connection->ConnectToService("mojo:mojo_native_viewport_service", |
| 81 &native_viewport_); | 81 &native_viewport_); |
| 82 native_viewport_.set_client(this); | 82 native_viewport_.set_client(this); |
| 83 native_viewport_->Create(Size::From(bounds_)); | 83 native_viewport_->Create( |
| 84 Size::From(size_), |
| 85 base::Bind(&DisplayManager::OnCreatedNativeViewport, |
| 86 weak_factory_.GetWeakPtr())); |
| 84 native_viewport_->Show(); | 87 native_viewport_->Show(); |
| 85 app_connection->ConnectToService("mojo:mojo_surfaces_service", | 88 app_connection->ConnectToService("mojo:mojo_surfaces_service", |
| 86 &surfaces_service_); | 89 &surfaces_service_); |
| 87 surfaces_service_->CreateSurfaceConnection(base::Bind( | 90 surfaces_service_->CreateSurfaceConnection(base::Bind( |
| 88 &DisplayManager::OnSurfaceConnectionCreated, weak_factory_.GetWeakPtr())); | 91 &DisplayManager::OnSurfaceConnectionCreated, weak_factory_.GetWeakPtr())); |
| 89 } | 92 } |
| 90 | 93 |
| 91 DisplayManager::~DisplayManager() { | 94 DisplayManager::~DisplayManager() { |
| 92 } | 95 } |
| 93 | 96 |
| 94 void DisplayManager::SchedulePaint(const ServerView* view, | 97 void DisplayManager::SchedulePaint(const ServerView* view, |
| 95 const gfx::Rect& bounds) { | 98 const gfx::Rect& bounds) { |
| 96 if (!view->visible()) | 99 if (!view->visible()) |
| 97 return; | 100 return; |
| 98 gfx::Rect root_relative_rect = ConvertRectToRoot(view, bounds); | 101 gfx::Rect root_relative_rect = ConvertRectToRoot(view, bounds); |
| 99 if (root_relative_rect.IsEmpty()) | 102 if (root_relative_rect.IsEmpty()) |
| 100 return; | 103 return; |
| 101 dirty_rect_.Union(root_relative_rect); | 104 dirty_rect_.Union(root_relative_rect); |
| 102 if (!draw_timer_.IsRunning()) { | 105 if (!draw_timer_.IsRunning()) { |
| 103 draw_timer_.Start( | 106 draw_timer_.Start( |
| 104 FROM_HERE, | 107 FROM_HERE, |
| 105 base::TimeDelta(), | 108 base::TimeDelta(), |
| 106 base::Bind(&DisplayManager::Draw, base::Unretained(this))); | 109 base::Bind(&DisplayManager::Draw, base::Unretained(this))); |
| 107 } | 110 } |
| 108 } | 111 } |
| 109 | 112 |
| 113 void DisplayManager::OnCreatedNativeViewport(uint64_t native_viewport_id) { |
| 114 } |
| 115 |
| 110 void DisplayManager::OnSurfaceConnectionCreated(SurfacePtr surface, | 116 void DisplayManager::OnSurfaceConnectionCreated(SurfacePtr surface, |
| 111 uint32_t id_namespace) { | 117 uint32_t id_namespace) { |
| 112 surface_ = surface.Pass(); | 118 surface_ = surface.Pass(); |
| 113 surface_.set_client(this); | 119 surface_.set_client(this); |
| 114 surface_id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | 120 surface_id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); |
| 115 Draw(); | 121 Draw(); |
| 116 } | 122 } |
| 117 | 123 |
| 118 void DisplayManager::Draw() { | 124 void DisplayManager::Draw() { |
| 119 if (!surface_) | 125 if (!surface_) |
| 120 return; | 126 return; |
| 121 if (surface_id_.is_null()) { | 127 if (surface_id_.is_null()) { |
| 122 surface_id_ = surface_id_allocator_->GenerateId(); | 128 surface_id_ = surface_id_allocator_->GenerateId(); |
| 123 surface_->CreateSurface(SurfaceId::From(surface_id_), Size::From(bounds_)); | 129 surface_->CreateSurface(SurfaceId::From(surface_id_), Size::From(size_)); |
| 124 } | 130 } |
| 125 | 131 |
| 126 PassPtr pass = CreateDefaultPass(1, gfx::Rect(bounds_)); | 132 PassPtr pass = CreateDefaultPass(1, gfx::Rect(size_)); |
| 127 pass->damage_rect = Rect::From(dirty_rect_); | 133 pass->damage_rect = Rect::From(dirty_rect_); |
| 128 | 134 |
| 129 DrawViewTree(pass.get(), connection_manager_->root(), gfx::Vector2d()); | 135 DrawViewTree(pass.get(), connection_manager_->root(), gfx::Vector2d()); |
| 130 | 136 |
| 131 FramePtr frame = Frame::New(); | 137 FramePtr frame = Frame::New(); |
| 132 frame->passes.push_back(pass.Pass()); | 138 frame->passes.push_back(pass.Pass()); |
| 133 frame->resources.resize(0u); | 139 frame->resources.resize(0u); |
| 134 surface_->SubmitFrame(SurfaceId::From(surface_id_), frame.Pass()); | 140 surface_->SubmitFrame(SurfaceId::From(surface_id_), frame.Pass()); |
| 135 | 141 |
| 136 native_viewport_->SubmittedFrame(SurfaceId::From(surface_id_)); | 142 native_viewport_->SubmittedFrame(SurfaceId::From(surface_id_)); |
| 137 | 143 |
| 138 dirty_rect_ = gfx::Rect(); | 144 dirty_rect_ = gfx::Rect(); |
| 139 } | 145 } |
| 140 | 146 |
| 141 void DisplayManager::OnCreated(uint64_t native_viewport_id) { | |
| 142 } | |
| 143 | |
| 144 void DisplayManager::OnDestroyed() { | 147 void DisplayManager::OnDestroyed() { |
| 145 native_viewport_closed_callback_.Run(); | 148 native_viewport_closed_callback_.Run(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 void DisplayManager::OnBoundsChanged(SizePtr bounds) { | 151 void DisplayManager::OnSizeChanged(SizePtr size) { |
| 149 bounds_ = bounds.To<gfx::Size>(); | 152 size_ = size.To<gfx::Size>(); |
| 150 connection_manager_->root()->SetBounds(gfx::Rect(bounds_)); | 153 connection_manager_->root()->SetBounds(gfx::Rect(size_)); |
| 151 if (surface_id_.is_null()) | 154 if (surface_id_.is_null()) |
| 152 return; | 155 return; |
| 153 surface_->DestroySurface(SurfaceId::From(surface_id_)); | 156 surface_->DestroySurface(SurfaceId::From(surface_id_)); |
| 154 surface_id_ = cc::SurfaceId(); | 157 surface_id_ = cc::SurfaceId(); |
| 155 SchedulePaint(connection_manager_->root(), gfx::Rect(bounds_)); | 158 SchedulePaint(connection_manager_->root(), gfx::Rect(size_)); |
| 156 } | 159 } |
| 157 | 160 |
| 158 void DisplayManager::OnEvent(EventPtr event, | 161 void DisplayManager::OnEvent(EventPtr event, |
| 159 const mojo::Callback<void()>& callback) { | 162 const mojo::Callback<void()>& callback) { |
| 160 connection_manager_->DispatchViewInputEventToWindowManager(event.Pass()); | 163 connection_manager_->DispatchViewInputEventToWindowManager(event.Pass()); |
| 161 callback.Run(); | 164 callback.Run(); |
| 162 } | 165 } |
| 163 | 166 |
| 164 void DisplayManager::ReturnResources(Array<ReturnedResourcePtr> resources) { | 167 void DisplayManager::ReturnResources(Array<ReturnedResourcePtr> resources) { |
| 165 DCHECK_EQ(0u, resources.size()); | 168 DCHECK_EQ(0u, resources.size()); |
| 166 } | 169 } |
| 167 | 170 |
| 168 } // namespace service | 171 } // namespace service |
| 169 } // namespace mojo | 172 } // namespace mojo |
| OLD | NEW |