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

Side by Side Diff: components/mus/demo/mus_demo.cc

Issue 2072343002: Changes how window manager obtains WindowTree from mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include Created 4 years, 6 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 | « components/mus/demo/mus_demo.h ('k') | components/mus/mus_app.h » ('j') | 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 "components/mus/demo/mus_demo.h" 5 #include "components/mus/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 "components/mus/public/cpp/window.h"
9 #include "components/mus/public/cpp/window_tree_client.h" 10 #include "components/mus/public/cpp/window_tree_client.h"
11 #include "services/shell/public/cpp/connector.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 12 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkColor.h" 13 #include "third_party/skia/include/core/SkColor.h"
12 #include "third_party/skia/include/core/SkImageInfo.h" 14 #include "third_party/skia/include/core/SkImageInfo.h"
13 #include "third_party/skia/include/core/SkPaint.h" 15 #include "third_party/skia/include/core/SkPaint.h"
14 #include "third_party/skia/include/core/SkRect.h" 16 #include "third_party/skia/include/core/SkRect.h"
15 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
16 18
17 namespace mus_demo { 19 namespace mus_demo {
18 20
19 namespace { 21 namespace {
(...skipping 27 matching lines...) Expand all
47 canvas->rotate(angle); 49 canvas->rotate(angle);
48 canvas->translate(-SkFloatToScalar(canvas_size.width() * 0.5f), 50 canvas->translate(-SkFloatToScalar(canvas_size.width() * 0.5f),
49 -SkFloatToScalar(canvas_size.height() * 0.5f)); 51 -SkFloatToScalar(canvas_size.height() * 0.5f));
50 } 52 }
51 53
52 canvas->drawRect(rect, paint); 54 canvas->drawRect(rect, paint);
53 } 55 }
54 56
55 } // namespace 57 } // namespace
56 58
57 MusDemo::MusDemo() : window_manager_factory_binding_(this) {} 59 MusDemo::MusDemo() {}
58 60
59 MusDemo::~MusDemo() {} 61 MusDemo::~MusDemo() {
62 delete window_tree_client_;
63 }
60 64
61 void MusDemo::Initialize(shell::Connector* connector, 65 void MusDemo::Initialize(shell::Connector* connector,
62 const shell::Identity& identity, 66 const shell::Identity& identity,
63 uint32_t id) { 67 uint32_t id) {
64 connector_ = connector; 68 connector_ = connector;
65 mus::mojom::WindowManagerFactoryServicePtr wm_factory_service; 69 window_tree_client_ = new mus::WindowTreeClient(this, this, nullptr);
66 connector->ConnectToInterface("mojo:mus", &wm_factory_service); 70 window_tree_client_->ConnectAsWindowManager(connector);
67 wm_factory_service->SetWindowManagerFactory(
68 window_manager_factory_binding_.CreateInterfacePtrAndBind());
69 } 71 }
70 72
71 bool MusDemo::AcceptConnection(shell::Connection* connection) { 73 bool MusDemo::AcceptConnection(shell::Connection* connection) {
72 return true; 74 return true;
73 } 75 }
74 76
75 void MusDemo::OnEmbed(mus::Window* window) { 77 void MusDemo::OnEmbed(mus::Window* window) {
76 window_ = window; 78 // Not called for the WindowManager.
77 79 NOTREACHED();
78 // Initialize bitmap uploader for sending frames to MUS.
79 uploader_.reset(new bitmap_uploader::BitmapUploader(window_));
80 uploader_->Init(connector_);
81
82 // Draw initial frame and start the timer to regularly draw frames.
83 DrawFrame();
84 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay),
85 base::Bind(&MusDemo::DrawFrame, base::Unretained(this)));
86 } 80 }
87 81
88 void MusDemo::OnUnembed(mus::Window* root) {}
89
90 void MusDemo::OnWindowTreeClientDestroyed(mus::WindowTreeClient* client) { 82 void MusDemo::OnWindowTreeClientDestroyed(mus::WindowTreeClient* client) {
83 window_tree_client_ = nullptr;
91 timer_.Stop(); 84 timer_.Stop();
92 } 85 }
93 86
94 void MusDemo::OnEventObserved(const ui::Event& event, mus::Window* target) {} 87 void MusDemo::OnEventObserved(const ui::Event& event, mus::Window* target) {}
95 88
96 // mus::mojom::WindowManagerFactory: 89 void MusDemo::SetWindowManagerClient(mus::WindowManagerClient* client) {}
97 void MusDemo::CreateWindowManager(mus::mojom::DisplayPtr display,
98 mus::mojom::WindowTreeClientRequest request) {
99 new mus::WindowTreeClient(this, this, std::move(request));
100 }
101
102 // mus::WindowManagerDelegate:
103 void MusDemo::SetWindowManagerClient(mus::WindowManagerClient* client) {
104 window_manager_client_ = client;
105 }
106 90
107 bool MusDemo::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { 91 bool MusDemo::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) {
108 return true; 92 return true;
109 } 93 }
110 94
111 bool MusDemo::OnWmSetProperty(mus::Window* window, 95 bool MusDemo::OnWmSetProperty(mus::Window* window,
112 const std::string& name, 96 const std::string& name,
113 std::unique_ptr<std::vector<uint8_t>>* new_data) { 97 std::unique_ptr<std::vector<uint8_t>>* new_data) {
114 return true; 98 return true;
115 } 99 }
116 100
117 mus::Window* MusDemo::OnWmCreateTopLevelWindow( 101 mus::Window* MusDemo::OnWmCreateTopLevelWindow(
118 std::map<std::string, std::vector<uint8_t>>* properties) { 102 std::map<std::string, std::vector<uint8_t>>* properties) {
119 return nullptr; 103 return nullptr;
120 } 104 }
121 105
122 void MusDemo::OnWmClientJankinessChanged( 106 void MusDemo::OnWmClientJankinessChanged(
123 const std::set<mus::Window*>& client_windows, 107 const std::set<mus::Window*>& client_windows,
124 bool janky) { 108 bool janky) {
125 // Don't care 109 // Don't care
126 } 110 }
127 111
112 void MusDemo::OnWmNewDisplay(mus::Window* window,
113 const display::Display& display) {
114 DCHECK(!window_); // Only support one display.
115 window_ = window;
116
117 // Initialize bitmap uploader for sending frames to MUS.
118 uploader_.reset(new bitmap_uploader::BitmapUploader(window_));
119 uploader_->Init(connector_);
120
121 // Draw initial frame and start the timer to regularly draw frames.
122 DrawFrame();
123 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay),
124 base::Bind(&MusDemo::DrawFrame, base::Unretained(this)));
125 }
126
128 void MusDemo::OnAccelerator(uint32_t id, const ui::Event& event) { 127 void MusDemo::OnAccelerator(uint32_t id, const ui::Event& event) {
129 // Don't care 128 // Don't care
130 } 129 }
131 130
132 void MusDemo::AllocBitmap() { 131 void MusDemo::AllocBitmap() {
133 const gfx::Rect bounds = window_->GetBoundsInRoot(); 132 const gfx::Rect bounds = window_->GetBoundsInRoot();
134 133
135 // Allocate bitmap the same size as the window for drawing. 134 // Allocate bitmap the same size as the window for drawing.
136 bitmap_.reset(); 135 bitmap_.reset();
137 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), 136 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 std::unique_ptr<std::vector<unsigned char>> data( 168 std::unique_ptr<std::vector<unsigned char>> data(
170 new std::vector<unsigned char>(addr, addr + bytes)); 169 new std::vector<unsigned char>(addr, addr + bytes));
171 bitmap_.unlockPixels(); 170 bitmap_.unlockPixels();
172 171
173 // Send frame to MUS via BitmapUploader. 172 // Send frame to MUS via BitmapUploader.
174 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), 173 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data),
175 bitmap_uploader::BitmapUploader::BGRA); 174 bitmap_uploader::BitmapUploader::BGRA);
176 } 175 }
177 176
178 } // namespace mus_demo 177 } // namespace mus_demo
OLDNEW
« no previous file with comments | « components/mus/demo/mus_demo.h ('k') | components/mus/mus_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698