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

Unified Diff: services/ui/demo/mus_demo.cc

Issue 2679213003: Refactor Mus demo to prepare support for multiple external windows (Closed)
Patch Set: Use a class instead of a struct to improve data separation. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/demo/mus_demo.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/demo/mus_demo.cc
diff --git a/services/ui/demo/mus_demo.cc b/services/ui/demo/mus_demo.cc
index 0fbcd356c25475ef3794f4687541853891d9582f..f80c64fbaae611af6df9d0e7f61c3168bbb5d628 100644
--- a/services/ui/demo/mus_demo.cc
+++ b/services/ui/demo/mus_demo.cc
@@ -67,6 +67,38 @@ void DrawSquare(const gfx::Rect& bounds, double angle, SkCanvas* canvas) {
} // namespace
+class MusDemo::WindowTreeData {
+ public:
+ explicit WindowTreeData(
+ std::unique_ptr<aura::WindowTreeHostMus> window_tree_host);
+ ~WindowTreeData();
+
+ private:
+ // Draws one frame, incrementing the rotation angle.
+ void DrawFrame();
+
+ // The Window tree host corresponding to this data.
+ std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_;
+
+ // Root window of the window tree host.
+ aura::Window* root_window_ = nullptr;
sky 2017/02/09 20:53:16 Why do you need to cache this? window_tree_host_->
+
+ // Window to which we draw the bitmap.
+ std::unique_ptr<aura::Window> bitmap_window_;
sky 2017/02/09 20:53:16 Windows are generally owned by their parent. Are y
+
+ // 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;
+
+ // Last time a frame was drawn.
+ base::TimeTicks last_draw_frame_time_;
+};
sky 2017/02/09 20:53:16 DISALLOW...
+
MusDemo::MusDemo() {}
MusDemo::~MusDemo() {
@@ -110,9 +142,8 @@ void MusDemo::OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) {
}
void MusDemo::OnLostConnection(aura::WindowTreeClient* client) {
- root_window_ = nullptr;
window_tree_client_.reset();
- timer_.Stop();
+ window_tree_data_.reset();
}
void MusDemo::OnPointerEventObserved(const PointerEvent& event,
@@ -157,8 +188,13 @@ void MusDemo::OnWmWillCreateDisplay(const display::Display& display) {
void MusDemo::OnWmNewDisplay(
std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
const display::Display& display) {
- DCHECK(!root_window_); // Only support one display.
+ DCHECK(!window_tree_data_); // Only support one display.
+ window_tree_data_ =
+ base::MakeUnique<WindowTreeData>(std::move(window_tree_host));
+}
+MusDemo::WindowTreeData::WindowTreeData(
+ std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
window_tree_host->InitHost();
window_tree_host->Show();
root_window_ = window_tree_host->window();
@@ -178,10 +214,14 @@ void MusDemo::OnWmNewDisplay(
// Draw initial frame and start the timer to regularly draw frames.
DrawFrame();
timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay),
- base::Bind(&MusDemo::DrawFrame, base::Unretained(this)));
+ base::Bind(&WindowTreeData::DrawFrame, base::Unretained(this)));
}
void MusDemo::OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) {
+ window_tree_data_.reset();
+}
+
+MusDemo::WindowTreeData::~WindowTreeData() {
timer_.Stop();
root_window_->RemoveChild(bitmap_window_.get());
bitmap_window_.reset();
@@ -211,7 +251,7 @@ bool MusDemo::IsWindowActive(aura::Window* window) { return false; }
void MusDemo::OnWmDeactivateWindow(aura::Window* window) {}
-void MusDemo::DrawFrame() {
+void MusDemo::WindowTreeData::DrawFrame() {
base::TimeTicks now = base::TimeTicks::Now();
VLOG(1) << (now - last_draw_frame_time_).InMilliseconds()
« no previous file with comments | « services/ui/demo/mus_demo.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698