Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: services/ui/demo/mus_demo.cc

Issue 2688813003: Mus Demo: Add square size parameter to the WindowTreeData constructor (Closed)
Patch Set: Rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 22 matching lines...) Expand all
33 33
34 // Milliseconds between frames. 34 // Milliseconds between frames.
35 const int64_t kFrameDelay = 33; 35 const int64_t kFrameDelay = 33;
36 36
37 // Size of square in pixels to draw. 37 // Size of square in pixels to draw.
38 const int kSquareSize = 300; 38 const int kSquareSize = 300;
39 39
40 const SkColor kBgColor = SK_ColorRED; 40 const SkColor kBgColor = SK_ColorRED;
41 const SkColor kFgColor = SK_ColorYELLOW; 41 const SkColor kFgColor = SK_ColorYELLOW;
42 42
43 void DrawSquare(const gfx::Rect& bounds, double angle, SkCanvas* canvas) { 43 void DrawSquare(const gfx::Rect& bounds,
44 double angle,
45 SkCanvas* canvas,
46 int size) {
44 // Create SkRect to draw centered inside the bounds. 47 // Create SkRect to draw centered inside the bounds.
45 gfx::Point top_left = bounds.CenterPoint(); 48 gfx::Point top_left = bounds.CenterPoint();
46 top_left.Offset(-kSquareSize / 2, -kSquareSize / 2); 49 top_left.Offset(-size / 2, -size / 2);
47 SkRect rect = 50 SkRect rect = SkRect::MakeXYWH(top_left.x(), top_left.y(), size, size);
48 SkRect::MakeXYWH(top_left.x(), top_left.y(), kSquareSize, kSquareSize);
49 51
50 // Set SkPaint to fill solid color. 52 // Set SkPaint to fill solid color.
51 SkPaint paint; 53 SkPaint paint;
52 paint.setStyle(SkPaint::kFill_Style); 54 paint.setStyle(SkPaint::kFill_Style);
53 paint.setColor(kFgColor); 55 paint.setColor(kFgColor);
54 56
55 // Rotate the canvas. 57 // Rotate the canvas.
56 const gfx::Size canvas_size = bounds.size(); 58 const gfx::Size canvas_size = bounds.size();
57 if (angle != 0.0) { 59 if (angle != 0.0) {
58 canvas->translate(SkFloatToScalar(canvas_size.width() * 0.5f), 60 canvas->translate(SkFloatToScalar(canvas_size.width() * 0.5f),
59 SkFloatToScalar(canvas_size.height() * 0.5f)); 61 SkFloatToScalar(canvas_size.height() * 0.5f));
60 canvas->rotate(angle); 62 canvas->rotate(angle);
61 canvas->translate(-SkFloatToScalar(canvas_size.width() * 0.5f), 63 canvas->translate(-SkFloatToScalar(canvas_size.width() * 0.5f),
62 -SkFloatToScalar(canvas_size.height() * 0.5f)); 64 -SkFloatToScalar(canvas_size.height() * 0.5f));
63 } 65 }
64 66
65 canvas->drawRect(rect, paint); 67 canvas->drawRect(rect, paint);
66 } 68 }
67 69
68 } // namespace 70 } // namespace
69 71
70 class MusDemo::WindowTreeData { 72 class MusDemo::WindowTreeData {
71 public: 73 public:
72 explicit WindowTreeData( 74 explicit WindowTreeData(
73 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { 75 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
76 int square_size)
77 : square_size_(square_size) {
74 Init(std::move(window_tree_host)); 78 Init(std::move(window_tree_host));
75 } 79 }
76 80
77 private: 81 private:
78 // Initializes the window tree host and start drawing frames. 82 // Initializes the window tree host and start drawing frames.
79 void Init(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host); 83 void Init(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host);
80 84
81 // Draws one frame, incrementing the rotation angle. 85 // Draws one frame, incrementing the rotation angle.
82 void DrawFrame(); 86 void DrawFrame();
83 87
84 // Helper function to retrieve the window to which we draw the bitmap. 88 // Helper function to retrieve the window to which we draw the bitmap.
85 aura::Window* bitmap_window() { 89 aura::Window* bitmap_window() {
86 DCHECK(!window_tree_host_->window()->children().empty()); 90 DCHECK(!window_tree_host_->window()->children().empty());
87 return window_tree_host_->window()->children()[0]; 91 return window_tree_host_->window()->children()[0];
88 } 92 }
89 93
90 // The Window tree host corresponding to this data. 94 // The Window tree host corresponding to this data.
91 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_; 95 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_;
92 96
93 // Destroys itself when the window gets destroyed. 97 // Destroys itself when the window gets destroyed.
94 aura_extra::ImageWindowDelegate* window_delegate_ = nullptr; 98 aura_extra::ImageWindowDelegate* window_delegate_ = nullptr;
95 99
96 // Timer for calling DrawFrame(). 100 // Timer for calling DrawFrame().
97 base::RepeatingTimer timer_; 101 base::RepeatingTimer timer_;
98 102
99 // Current rotation angle for drawing. 103 // Current rotation angle for drawing.
100 double angle_ = 0.0; 104 double angle_ = 0.0;
101 105
106 // Size in pixels of the square to draw.
107 const int square_size_;
108
102 DISALLOW_COPY_AND_ASSIGN(WindowTreeData); 109 DISALLOW_COPY_AND_ASSIGN(WindowTreeData);
103 }; 110 };
104 111
105 void MusDemo::WindowTreeData::Init( 112 void MusDemo::WindowTreeData::Init(
106 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { 113 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
107 window_tree_host->InitHost(); 114 window_tree_host->InitHost();
108 window_tree_host->Show(); 115 window_tree_host->Show();
109 // Take ownership of the WTH. 116 // Take ownership of the WTH.
110 window_tree_host_ = std::move(window_tree_host); 117 window_tree_host_ = std::move(window_tree_host);
111 118
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 215
209 void MusDemo::OnWmWillCreateDisplay(const display::Display& display) { 216 void MusDemo::OnWmWillCreateDisplay(const display::Display& display) {
210 screen_->display_list().AddDisplay(display, 217 screen_->display_list().AddDisplay(display,
211 display::DisplayList::Type::PRIMARY); 218 display::DisplayList::Type::PRIMARY);
212 } 219 }
213 220
214 void MusDemo::OnWmNewDisplay( 221 void MusDemo::OnWmNewDisplay(
215 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, 222 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
216 const display::Display& display) { 223 const display::Display& display) {
217 DCHECK(!window_tree_data_); // Only support one display. 224 DCHECK(!window_tree_data_); // Only support one display.
218 window_tree_data_ = 225 window_tree_data_ = base::MakeUnique<WindowTreeData>(
219 base::MakeUnique<WindowTreeData>(std::move(window_tree_host)); 226 std::move(window_tree_host), kSquareSize);
220 } 227 }
221 228
222 void MusDemo::OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) { 229 void MusDemo::OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) {
223 window_tree_data_.reset(); 230 window_tree_data_.reset();
224 } 231 }
225 232
226 void MusDemo::OnWmDisplayModified(const display::Display& display) {} 233 void MusDemo::OnWmDisplayModified(const display::Display& display) {}
227 234
228 mojom::EventResult MusDemo::OnAccelerator(uint32_t id, const Event& event) { 235 mojom::EventResult MusDemo::OnAccelerator(uint32_t id, const Event& event) {
229 return mojom::EventResult::UNHANDLED; 236 return mojom::EventResult::UNHANDLED;
(...skipping 27 matching lines...) Expand all
257 // Allocate a bitmap of correct size. 264 // Allocate a bitmap of correct size.
258 SkBitmap bitmap; 265 SkBitmap bitmap;
259 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), 266 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
260 kPremul_SkAlphaType); 267 kPremul_SkAlphaType);
261 bitmap.allocPixels(image_info); 268 bitmap.allocPixels(image_info);
262 269
263 // Draw the rotated square on background in bitmap. 270 // Draw the rotated square on background in bitmap.
264 SkCanvas canvas(bitmap); 271 SkCanvas canvas(bitmap);
265 canvas.clear(kBgColor); 272 canvas.clear(kBgColor);
266 // TODO(kylechar): Add GL drawing instead of software rasterization in future. 273 // TODO(kylechar): Add GL drawing instead of software rasterization in future.
267 DrawSquare(bounds, angle_, &canvas); 274 DrawSquare(bounds, angle_, &canvas, square_size_);
268 canvas.flush(); 275 canvas.flush();
269 276
270 gfx::ImageSkiaRep image_skia_rep(bitmap, 1); 277 gfx::ImageSkiaRep image_skia_rep(bitmap, 1);
271 gfx::ImageSkia image_skia(image_skia_rep); 278 gfx::ImageSkia image_skia(image_skia_rep);
272 gfx::Image image(image_skia); 279 gfx::Image image(image_skia);
273 280
274 window_delegate_->SetImage(image); 281 window_delegate_->SetImage(image);
275 bitmap_window()->SchedulePaintInRect(gfx::Rect(bounds.size())); 282 bitmap_window()->SchedulePaintInRect(gfx::Rect(bounds.size()));
276 } 283 }
277 284
278 } // namespace demo 285 } // namespace demo
279 } // namespace aura 286 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698