| Index: services/ui/demo/mus_demo.cc
|
| diff --git a/services/ui/demo/mus_demo.cc b/services/ui/demo/mus_demo.cc
|
| index cf797498503f58fde7633245c47f00fca51012f8..b8ed5641f7e4f07d125a6706038a98c9719fe0ba 100644
|
| --- a/services/ui/demo/mus_demo.cc
|
| +++ b/services/ui/demo/mus_demo.cc
|
| @@ -69,45 +69,19 @@ void DrawSquare(const gfx::Rect& bounds,
|
|
|
| } // namespace
|
|
|
| -class MusDemo::WindowTreeData {
|
| - public:
|
| - explicit WindowTreeData(
|
| - std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
|
| - int square_size)
|
| - : square_size_(square_size) {
|
| - Init(std::move(window_tree_host));
|
| - }
|
| -
|
| - private:
|
| - // Initializes the window tree host and start drawing frames.
|
| - void Init(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host);
|
| -
|
| - // Draws one frame, incrementing the rotation angle.
|
| - void DrawFrame();
|
| -
|
| - // Helper function to retrieve the window to which we draw the bitmap.
|
| - aura::Window* bitmap_window() {
|
| - DCHECK(!window_tree_host_->window()->children().empty());
|
| - return window_tree_host_->window()->children()[0];
|
| - }
|
| -
|
| - // The Window tree host corresponding to this data.
|
| - std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_;
|
| -
|
| - // Destroys itself when the window gets destroyed.
|
| - aura_extra::ImageWindowDelegate* window_delegate_ = nullptr;
|
| -
|
| - // Timer for calling DrawFrame().
|
| - base::RepeatingTimer timer_;
|
| -
|
| - // Current rotation angle for drawing.
|
| - double angle_ = 0.0;
|
| +MusDemo::WindowTreeData::WindowTreeData(
|
| + std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
|
| + int square_size)
|
| + : square_size_(square_size) {
|
| + Init(std::move(window_tree_host));
|
| +}
|
|
|
| - // Size in pixels of the square to draw.
|
| - const int square_size_;
|
| +MusDemo::WindowTreeData::~WindowTreeData() {}
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(WindowTreeData);
|
| -};
|
| +aura::Window* MusDemo::WindowTreeData::bitmap_window() {
|
| + DCHECK(!window_tree_host_->window()->children().empty());
|
| + return window_tree_host_->window()->children()[0];
|
| +}
|
|
|
| void MusDemo::WindowTreeData::Init(
|
| std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
|
| @@ -132,6 +106,34 @@ void MusDemo::WindowTreeData::Init(
|
| base::Bind(&WindowTreeData::DrawFrame, base::Unretained(this)));
|
| }
|
|
|
| +void MusDemo::WindowTreeData::DrawFrame() {
|
| + angle_ += 2.0;
|
| + if (angle_ >= 360.0)
|
| + angle_ = 0.0;
|
| +
|
| + const gfx::Rect& bounds = bitmap_window()->bounds();
|
| +
|
| + // Allocate a bitmap of correct size.
|
| + SkBitmap bitmap;
|
| + SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
|
| + kPremul_SkAlphaType);
|
| + bitmap.allocPixels(image_info);
|
| +
|
| + // Draw the rotated square on background in bitmap.
|
| + SkCanvas canvas(bitmap);
|
| + canvas.clear(kBgColor);
|
| + // TODO(kylechar): Add GL drawing instead of software rasterization in future.
|
| + DrawSquare(bounds, angle_, &canvas, square_size_);
|
| + canvas.flush();
|
| +
|
| + gfx::ImageSkiaRep image_skia_rep(bitmap, 1);
|
| + gfx::ImageSkia image_skia(image_skia_rep);
|
| + gfx::Image image(image_skia);
|
| +
|
| + window_delegate_->SetImage(image);
|
| + bitmap_window()->SchedulePaintInRect(gfx::Rect(bounds.size()));
|
| +}
|
| +
|
| MusDemo::MusDemo() {}
|
|
|
| MusDemo::~MusDemo() {
|
| @@ -254,33 +256,5 @@ bool MusDemo::IsWindowActive(aura::Window* window) { return false; }
|
|
|
| void MusDemo::OnWmDeactivateWindow(aura::Window* window) {}
|
|
|
| -void MusDemo::WindowTreeData::DrawFrame() {
|
| - angle_ += 2.0;
|
| - if (angle_ >= 360.0)
|
| - angle_ = 0.0;
|
| -
|
| - const gfx::Rect& bounds = bitmap_window()->bounds();
|
| -
|
| - // Allocate a bitmap of correct size.
|
| - SkBitmap bitmap;
|
| - SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
|
| - kPremul_SkAlphaType);
|
| - bitmap.allocPixels(image_info);
|
| -
|
| - // Draw the rotated square on background in bitmap.
|
| - SkCanvas canvas(bitmap);
|
| - canvas.clear(kBgColor);
|
| - // TODO(kylechar): Add GL drawing instead of software rasterization in future.
|
| - DrawSquare(bounds, angle_, &canvas, square_size_);
|
| - canvas.flush();
|
| -
|
| - gfx::ImageSkiaRep image_skia_rep(bitmap, 1);
|
| - gfx::ImageSkia image_skia(image_skia_rep);
|
| - gfx::Image image(image_skia);
|
| -
|
| - window_delegate_->SetImage(image);
|
| - bitmap_window()->SchedulePaintInRect(gfx::Rect(bounds.size()));
|
| -}
|
| -
|
| } // namespace demo
|
| } // namespace aura
|
|
|