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

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

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

Powered by Google App Engine
This is Rietveld 408576698