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/time/time.h" | 7 #include "base/time/time.h" |
8 #include "components/bitmap_uploader/bitmap_uploader.h" | 8 #include "components/bitmap_uploader/bitmap_uploader.h" |
9 #include "services/shell/public/cpp/connector.h" | 9 #include "services/shell/public/cpp/connector.h" |
10 #include "services/ui/common/gpu_service.h" | 10 #include "services/ui/common/gpu_service.h" |
11 #include "services/ui/public/cpp/window.h" | 11 #include "services/ui/public/cpp/window.h" |
12 #include "services/ui/public/cpp/window_tree_client.h" | 12 #include "services/ui/public/cpp/window_tree_client.h" |
13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
14 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
15 #include "third_party/skia/include/core/SkImageInfo.h" | 15 #include "third_party/skia/include/core/SkImageInfo.h" |
16 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
17 #include "third_party/skia/include/core/SkRect.h" | 17 #include "third_party/skia/include/core/SkRect.h" |
18 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
19 | 19 |
20 namespace mus_demo { | 20 namespace ui { |
| 21 namespace demo { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Milliseconds between frames. | 25 // Milliseconds between frames. |
25 const int64_t kFrameDelay = 33; | 26 const int64_t kFrameDelay = 33; |
26 | 27 |
27 // Size of square in pixels to draw. | 28 // Size of square in pixels to draw. |
28 const int kSquareSize = 300; | 29 const int kSquareSize = 300; |
29 | 30 |
30 const SkColor kBgColor = SK_ColorRED; | 31 const SkColor kBgColor = SK_ColorRED; |
(...skipping 29 matching lines...) Expand all Loading... |
60 MusDemo::MusDemo() {} | 61 MusDemo::MusDemo() {} |
61 | 62 |
62 MusDemo::~MusDemo() { | 63 MusDemo::~MusDemo() { |
63 delete window_tree_client_; | 64 delete window_tree_client_; |
64 } | 65 } |
65 | 66 |
66 void MusDemo::OnStart(shell::Connector* connector, | 67 void MusDemo::OnStart(shell::Connector* connector, |
67 const shell::Identity& identity, | 68 const shell::Identity& identity, |
68 uint32_t id) { | 69 uint32_t id) { |
69 connector_ = connector; | 70 connector_ = connector; |
70 ui::GpuService::Initialize(connector_); | 71 GpuService::Initialize(connector_); |
71 window_tree_client_ = new ui::WindowTreeClient(this, this, nullptr); | 72 window_tree_client_ = new WindowTreeClient(this, this, nullptr); |
72 window_tree_client_->ConnectAsWindowManager(connector); | 73 window_tree_client_->ConnectAsWindowManager(connector); |
73 } | 74 } |
74 | 75 |
75 bool MusDemo::OnConnect(shell::Connection* connection) { | 76 bool MusDemo::OnConnect(shell::Connection* connection) { |
76 return true; | 77 return true; |
77 } | 78 } |
78 | 79 |
79 void MusDemo::OnEmbed(ui::Window* window) { | 80 void MusDemo::OnEmbed(Window* window) { |
80 // Not called for the WindowManager. | 81 // Not called for the WindowManager. |
81 NOTREACHED(); | 82 NOTREACHED(); |
82 } | 83 } |
83 | 84 |
84 void MusDemo::OnDidDestroyClient(ui::WindowTreeClient* client) { | 85 void MusDemo::OnDidDestroyClient(WindowTreeClient* client) { |
85 window_tree_client_ = nullptr; | 86 window_tree_client_ = nullptr; |
86 timer_.Stop(); | 87 timer_.Stop(); |
87 } | 88 } |
88 | 89 |
89 void MusDemo::OnEventObserved(const ui::Event& event, ui::Window* target) {} | 90 void MusDemo::OnEventObserved(const Event& event, Window* target) {} |
90 | 91 |
91 void MusDemo::SetWindowManagerClient(ui::WindowManagerClient* client) {} | 92 void MusDemo::SetWindowManagerClient(WindowManagerClient* client) {} |
92 | 93 |
93 bool MusDemo::OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) { | 94 bool MusDemo::OnWmSetBounds(Window* window, gfx::Rect* bounds) { |
94 return true; | 95 return true; |
95 } | 96 } |
96 | 97 |
97 bool MusDemo::OnWmSetProperty(ui::Window* window, | 98 bool MusDemo::OnWmSetProperty(Window* window, |
98 const std::string& name, | 99 const std::string& name, |
99 std::unique_ptr<std::vector<uint8_t>>* new_data) { | 100 std::unique_ptr<std::vector<uint8_t>>* new_data) { |
100 return true; | 101 return true; |
101 } | 102 } |
102 | 103 |
103 ui::Window* MusDemo::OnWmCreateTopLevelWindow( | 104 Window* MusDemo::OnWmCreateTopLevelWindow( |
104 std::map<std::string, std::vector<uint8_t>>* properties) { | 105 std::map<std::string, std::vector<uint8_t>>* properties) { |
105 return nullptr; | 106 return nullptr; |
106 } | 107 } |
107 | 108 |
108 void MusDemo::OnWmClientJankinessChanged( | 109 void MusDemo::OnWmClientJankinessChanged( |
109 const std::set<ui::Window*>& client_windows, | 110 const std::set<Window*>& client_windows, |
110 bool janky) { | 111 bool janky) { |
111 // Don't care | 112 // Don't care |
112 } | 113 } |
113 | 114 |
114 void MusDemo::OnWmNewDisplay(ui::Window* window, | 115 void MusDemo::OnWmNewDisplay(Window* window, const display::Display& display) { |
115 const display::Display& display) { | |
116 DCHECK(!window_); // Only support one display. | 116 DCHECK(!window_); // Only support one display. |
117 window_ = window; | 117 window_ = window; |
118 | 118 |
119 // Initialize bitmap uploader for sending frames to MUS. | 119 // Initialize bitmap uploader for sending frames to MUS. |
120 uploader_.reset(new bitmap_uploader::BitmapUploader(window_)); | 120 uploader_.reset(new bitmap_uploader::BitmapUploader(window_)); |
121 uploader_->Init(connector_); | 121 uploader_->Init(connector_); |
122 | 122 |
123 // Draw initial frame and start the timer to regularly draw frames. | 123 // Draw initial frame and start the timer to regularly draw frames. |
124 DrawFrame(); | 124 DrawFrame(); |
125 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay), | 125 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay), |
126 base::Bind(&MusDemo::DrawFrame, base::Unretained(this))); | 126 base::Bind(&MusDemo::DrawFrame, base::Unretained(this))); |
127 } | 127 } |
128 | 128 |
129 void MusDemo::OnWmPerformMoveLoop(ui::Window* window, | 129 void MusDemo::OnWmPerformMoveLoop(Window* window, |
130 ui::mojom::MoveLoopSource source, | 130 mojom::MoveLoopSource source, |
131 const gfx::Point& cursor_location, | 131 const gfx::Point& cursor_location, |
132 const base::Callback<void(bool)>& on_done) { | 132 const base::Callback<void(bool)>& on_done) { |
133 // Don't care | 133 // Don't care |
134 } | 134 } |
135 | 135 |
136 void MusDemo::OnWmCancelMoveLoop(ui::Window* window) {} | 136 void MusDemo::OnWmCancelMoveLoop(Window* window) {} |
137 | 137 |
138 void MusDemo::AllocBitmap() { | 138 void MusDemo::AllocBitmap() { |
139 const gfx::Rect bounds = window_->GetBoundsInRoot(); | 139 const gfx::Rect bounds = window_->GetBoundsInRoot(); |
140 | 140 |
141 // Allocate bitmap the same size as the window for drawing. | 141 // Allocate bitmap the same size as the window for drawing. |
142 bitmap_.reset(); | 142 bitmap_.reset(); |
143 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), | 143 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), |
144 kPremul_SkAlphaType); | 144 kPremul_SkAlphaType); |
145 bitmap_.allocPixels(image_info); | 145 bitmap_.allocPixels(image_info); |
146 } | 146 } |
(...skipping 27 matching lines...) Expand all Loading... |
174 const int bytes = bounds.width() * bounds.height() * 4; | 174 const int bytes = bounds.width() * bounds.height() * 4; |
175 std::unique_ptr<std::vector<unsigned char>> data( | 175 std::unique_ptr<std::vector<unsigned char>> data( |
176 new std::vector<unsigned char>(addr, addr + bytes)); | 176 new std::vector<unsigned char>(addr, addr + bytes)); |
177 bitmap_.unlockPixels(); | 177 bitmap_.unlockPixels(); |
178 | 178 |
179 // Send frame to MUS via BitmapUploader. | 179 // Send frame to MUS via BitmapUploader. |
180 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), | 180 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), |
181 bitmap_uploader::BitmapUploader::BGRA); | 181 bitmap_uploader::BitmapUploader::BGRA); |
182 } | 182 } |
183 | 183 |
184 } // namespace ui_demo | 184 } // namespace demo |
| 185 } // namespace ui |
OLD | NEW |