Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/demo/mus_demo.h" | 5 #include "services/ui/demo/mus_demo.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "services/service_manager/public/cpp/connector.h" | 9 #include "services/service_manager/public/cpp/connector.h" |
| 10 #include "services/service_manager/public/cpp/service_context.h" | 10 #include "services/service_manager/public/cpp/service_context.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 canvas->rotate(angle); | 60 canvas->rotate(angle); |
| 61 canvas->translate(-SkFloatToScalar(canvas_size.width() * 0.5f), | 61 canvas->translate(-SkFloatToScalar(canvas_size.width() * 0.5f), |
| 62 -SkFloatToScalar(canvas_size.height() * 0.5f)); | 62 -SkFloatToScalar(canvas_size.height() * 0.5f)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 canvas->drawRect(rect, paint); | 65 canvas->drawRect(rect, paint); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 class MusDemo::WindowTreeData { | |
| 71 public: | |
| 72 explicit WindowTreeData( | |
| 73 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host); | |
| 74 ~WindowTreeData(); | |
| 75 | |
| 76 private: | |
| 77 // Draws one frame, incrementing the rotation angle. | |
| 78 void DrawFrame(); | |
| 79 | |
| 80 // The Window tree host corresponding to this data. | |
| 81 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_; | |
| 82 | |
| 83 // Root window of the window tree host. | |
| 84 aura::Window* root_window_ = nullptr; | |
|
sky
2017/02/09 20:53:16
Why do you need to cache this? window_tree_host_->
| |
| 85 | |
| 86 // Window to which we draw the bitmap. | |
| 87 std::unique_ptr<aura::Window> bitmap_window_; | |
|
sky
2017/02/09 20:53:16
Windows are generally owned by their parent. Are y
| |
| 88 | |
| 89 // Destroys itself when the window gets destroyed. | |
| 90 aura_extra::ImageWindowDelegate* window_delegate_ = nullptr; | |
| 91 | |
| 92 // Timer for calling DrawFrame(). | |
| 93 base::RepeatingTimer timer_; | |
| 94 | |
| 95 // Current rotation angle for drawing. | |
| 96 double angle_ = 0.0; | |
| 97 | |
| 98 // Last time a frame was drawn. | |
| 99 base::TimeTicks last_draw_frame_time_; | |
| 100 }; | |
|
sky
2017/02/09 20:53:16
DISALLOW...
| |
| 101 | |
| 70 MusDemo::MusDemo() {} | 102 MusDemo::MusDemo() {} |
| 71 | 103 |
| 72 MusDemo::~MusDemo() { | 104 MusDemo::~MusDemo() { |
| 73 display::Screen::SetScreenInstance(nullptr); | 105 display::Screen::SetScreenInstance(nullptr); |
| 74 } | 106 } |
| 75 | 107 |
| 76 void MusDemo::OnStart() { | 108 void MusDemo::OnStart() { |
| 77 screen_ = base::MakeUnique<display::ScreenBase>(); | 109 screen_ = base::MakeUnique<display::ScreenBase>(); |
| 78 display::Screen::SetScreenInstance(screen_.get()); | 110 display::Screen::SetScreenInstance(screen_.get()); |
| 79 | 111 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 103 void MusDemo::OnUnembed(aura::Window* root) { | 135 void MusDemo::OnUnembed(aura::Window* root) { |
| 104 NOTREACHED(); | 136 NOTREACHED(); |
| 105 } | 137 } |
| 106 | 138 |
| 107 void MusDemo::OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) { | 139 void MusDemo::OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) { |
| 108 // Not called for the WindowManager. | 140 // Not called for the WindowManager. |
| 109 NOTREACHED(); | 141 NOTREACHED(); |
| 110 } | 142 } |
| 111 | 143 |
| 112 void MusDemo::OnLostConnection(aura::WindowTreeClient* client) { | 144 void MusDemo::OnLostConnection(aura::WindowTreeClient* client) { |
| 113 root_window_ = nullptr; | |
| 114 window_tree_client_.reset(); | 145 window_tree_client_.reset(); |
| 115 timer_.Stop(); | 146 window_tree_data_.reset(); |
| 116 } | 147 } |
| 117 | 148 |
| 118 void MusDemo::OnPointerEventObserved(const PointerEvent& event, | 149 void MusDemo::OnPointerEventObserved(const PointerEvent& event, |
| 119 aura::Window* target) {} | 150 aura::Window* target) {} |
| 120 | 151 |
| 121 aura::PropertyConverter* MusDemo::GetPropertyConverter() { | 152 aura::PropertyConverter* MusDemo::GetPropertyConverter() { |
| 122 return property_converter_.get(); | 153 return property_converter_.get(); |
| 123 } | 154 } |
| 124 | 155 |
| 125 void MusDemo::SetWindowManagerClient(aura::WindowManagerClient* client) {} | 156 void MusDemo::SetWindowManagerClient(aura::WindowManagerClient* client) {} |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 150 } | 181 } |
| 151 | 182 |
| 152 void MusDemo::OnWmWillCreateDisplay(const display::Display& display) { | 183 void MusDemo::OnWmWillCreateDisplay(const display::Display& display) { |
| 153 screen_->display_list().AddDisplay(display, | 184 screen_->display_list().AddDisplay(display, |
| 154 display::DisplayList::Type::PRIMARY); | 185 display::DisplayList::Type::PRIMARY); |
| 155 } | 186 } |
| 156 | 187 |
| 157 void MusDemo::OnWmNewDisplay( | 188 void MusDemo::OnWmNewDisplay( |
| 158 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, | 189 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| 159 const display::Display& display) { | 190 const display::Display& display) { |
| 160 DCHECK(!root_window_); // Only support one display. | 191 DCHECK(!window_tree_data_); // Only support one display. |
| 192 window_tree_data_ = | |
| 193 base::MakeUnique<WindowTreeData>(std::move(window_tree_host)); | |
| 194 } | |
| 161 | 195 |
| 196 MusDemo::WindowTreeData::WindowTreeData( | |
| 197 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | |
| 162 window_tree_host->InitHost(); | 198 window_tree_host->InitHost(); |
| 163 window_tree_host->Show(); | 199 window_tree_host->Show(); |
| 164 root_window_ = window_tree_host->window(); | 200 root_window_ = window_tree_host->window(); |
| 165 // Take ownership of the WTH. | 201 // Take ownership of the WTH. |
| 166 window_tree_host_ = std::move(window_tree_host); | 202 window_tree_host_ = std::move(window_tree_host); |
| 167 | 203 |
| 168 // Initialize the window for the bitmap. | 204 // Initialize the window for the bitmap. |
| 169 window_delegate_ = new aura_extra::ImageWindowDelegate(); | 205 window_delegate_ = new aura_extra::ImageWindowDelegate(); |
| 170 bitmap_window_ = base::MakeUnique<aura::Window>(window_delegate_); | 206 bitmap_window_ = base::MakeUnique<aura::Window>(window_delegate_); |
| 171 bitmap_window_->Init(LAYER_TEXTURED); | 207 bitmap_window_->Init(LAYER_TEXTURED); |
| 172 bitmap_window_->SetBounds(root_window_->bounds()); | 208 bitmap_window_->SetBounds(root_window_->bounds()); |
| 173 bitmap_window_->Show(); | 209 bitmap_window_->Show(); |
| 174 bitmap_window_->SetName("Bitmap"); | 210 bitmap_window_->SetName("Bitmap"); |
| 175 | 211 |
| 176 root_window_->AddChild(bitmap_window_.get()); | 212 root_window_->AddChild(bitmap_window_.get()); |
| 177 | 213 |
| 178 // Draw initial frame and start the timer to regularly draw frames. | 214 // Draw initial frame and start the timer to regularly draw frames. |
| 179 DrawFrame(); | 215 DrawFrame(); |
| 180 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay), | 216 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay), |
| 181 base::Bind(&MusDemo::DrawFrame, base::Unretained(this))); | 217 base::Bind(&WindowTreeData::DrawFrame, base::Unretained(this))); |
| 182 } | 218 } |
| 183 | 219 |
| 184 void MusDemo::OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) { | 220 void MusDemo::OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) { |
| 221 window_tree_data_.reset(); | |
| 222 } | |
| 223 | |
| 224 MusDemo::WindowTreeData::~WindowTreeData() { | |
| 185 timer_.Stop(); | 225 timer_.Stop(); |
| 186 root_window_->RemoveChild(bitmap_window_.get()); | 226 root_window_->RemoveChild(bitmap_window_.get()); |
| 187 bitmap_window_.reset(); | 227 bitmap_window_.reset(); |
| 188 } | 228 } |
| 189 | 229 |
| 190 void MusDemo::OnWmDisplayModified(const display::Display& display) {} | 230 void MusDemo::OnWmDisplayModified(const display::Display& display) {} |
| 191 | 231 |
| 192 mojom::EventResult MusDemo::OnAccelerator(uint32_t id, const Event& event) { | 232 mojom::EventResult MusDemo::OnAccelerator(uint32_t id, const Event& event) { |
| 193 return mojom::EventResult::UNHANDLED; | 233 return mojom::EventResult::UNHANDLED; |
| 194 } | 234 } |
| 195 | 235 |
| 196 void MusDemo::OnWmPerformMoveLoop(aura::Window* window, | 236 void MusDemo::OnWmPerformMoveLoop(aura::Window* window, |
| 197 mojom::MoveLoopSource source, | 237 mojom::MoveLoopSource source, |
| 198 const gfx::Point& cursor_location, | 238 const gfx::Point& cursor_location, |
| 199 const base::Callback<void(bool)>& on_done) { | 239 const base::Callback<void(bool)>& on_done) { |
| 200 // Don't care | 240 // Don't care |
| 201 } | 241 } |
| 202 | 242 |
| 203 void MusDemo::OnWmCancelMoveLoop(aura::Window* window) {} | 243 void MusDemo::OnWmCancelMoveLoop(aura::Window* window) {} |
| 204 | 244 |
| 205 void MusDemo::OnWmSetClientArea( | 245 void MusDemo::OnWmSetClientArea( |
| 206 aura::Window* window, | 246 aura::Window* window, |
| 207 const gfx::Insets& insets, | 247 const gfx::Insets& insets, |
| 208 const std::vector<gfx::Rect>& additional_client_areas) {} | 248 const std::vector<gfx::Rect>& additional_client_areas) {} |
| 209 | 249 |
| 210 bool MusDemo::IsWindowActive(aura::Window* window) { return false; } | 250 bool MusDemo::IsWindowActive(aura::Window* window) { return false; } |
| 211 | 251 |
| 212 void MusDemo::OnWmDeactivateWindow(aura::Window* window) {} | 252 void MusDemo::OnWmDeactivateWindow(aura::Window* window) {} |
| 213 | 253 |
| 214 void MusDemo::DrawFrame() { | 254 void MusDemo::WindowTreeData::DrawFrame() { |
| 215 base::TimeTicks now = base::TimeTicks::Now(); | 255 base::TimeTicks now = base::TimeTicks::Now(); |
| 216 | 256 |
| 217 VLOG(1) << (now - last_draw_frame_time_).InMilliseconds() | 257 VLOG(1) << (now - last_draw_frame_time_).InMilliseconds() |
| 218 << "ms since the last frame was drawn."; | 258 << "ms since the last frame was drawn."; |
| 219 last_draw_frame_time_ = now; | 259 last_draw_frame_time_ = now; |
| 220 | 260 |
| 221 angle_ += 2.0; | 261 angle_ += 2.0; |
| 222 if (angle_ >= 360.0) | 262 if (angle_ >= 360.0) |
| 223 angle_ = 0.0; | 263 angle_ = 0.0; |
| 224 | 264 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 240 gfx::ImageSkiaRep image_skia_rep(bitmap, 1); | 280 gfx::ImageSkiaRep image_skia_rep(bitmap, 1); |
| 241 gfx::ImageSkia image_skia(image_skia_rep); | 281 gfx::ImageSkia image_skia(image_skia_rep); |
| 242 gfx::Image image(image_skia); | 282 gfx::Image image(image_skia); |
| 243 | 283 |
| 244 window_delegate_->SetImage(image); | 284 window_delegate_->SetImage(image); |
| 245 bitmap_window_->SchedulePaintInRect(bitmap_window_->bounds()); | 285 bitmap_window_->SchedulePaintInRect(bitmap_window_->bounds()); |
| 246 } | 286 } |
| 247 | 287 |
| 248 } // namespace demo | 288 } // namespace demo |
| 249 } // namespace aura | 289 } // namespace aura |
| OLD | NEW |