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

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

Issue 2440453002: Splitting the Mus demo code out of a service. (Closed)
Patch Set: Addressed @sky comments and synced Created 4 years, 2 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 | « services/ui/demo/mus_demo.h ('k') | services/ui/demo/mus_demo_service.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 "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/ui/demo/bitmap_uploader.h" 10 #include "services/ui/demo/bitmap_uploader.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 canvas->drawRect(rect, paint); 57 canvas->drawRect(rect, paint);
58 } 58 }
59 59
60 } // namespace 60 } // namespace
61 61
62 MusDemo::MusDemo() {} 62 MusDemo::MusDemo() {}
63 63
64 MusDemo::~MusDemo() {} 64 MusDemo::~MusDemo() {}
65 65
66 void MusDemo::OnStart(const service_manager::Identity& identity) { 66 void MusDemo::Start(service_manager::Connector* connector) {
67 gpu_service_ = GpuService::Create(connector()); 67 gpu_service_ = GpuService::Create(connector);
68 window_tree_client_ = base::MakeUnique<WindowTreeClient>(this, this); 68 window_tree_client_ = base::MakeUnique<WindowTreeClient>(this, this);
69 window_tree_client_->ConnectAsWindowManager(connector()); 69 window_tree_client_->ConnectAsWindowManager(connector);
70 }
71
72 bool MusDemo::OnConnect(const service_manager::Identity& remote_identity,
73 service_manager::InterfaceRegistry* registry) {
74 return true;
75 } 70 }
76 71
77 void MusDemo::OnEmbed(Window* window) { 72 void MusDemo::OnEmbed(Window* window) {
78 // Not called for the WindowManager. 73 // Not called for the WindowManager.
79 NOTREACHED(); 74 NOTREACHED();
80 } 75 }
81 76
82 void MusDemo::OnEmbedRootDestroyed(Window* root) { 77 void MusDemo::OnEmbedRootDestroyed(Window* root) {
83 // Not called for the WindowManager. 78 // Not called for the WindowManager.
84 NOTREACHED(); 79 NOTREACHED();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 const gfx::Rect bounds = window_->GetBoundsInRoot(); 144 const gfx::Rect bounds = window_->GetBoundsInRoot();
150 145
151 // Allocate bitmap the same size as the window for drawing. 146 // Allocate bitmap the same size as the window for drawing.
152 bitmap_.reset(); 147 bitmap_.reset();
153 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), 148 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
154 kPremul_SkAlphaType); 149 kPremul_SkAlphaType);
155 bitmap_.allocPixels(image_info); 150 bitmap_.allocPixels(image_info);
156 } 151 }
157 152
158 void MusDemo::DrawFrame() { 153 void MusDemo::DrawFrame() {
154 base::TimeTicks now = base::TimeTicks::Now();
155
156 VLOG(1) << (now - last_draw_frame_time_).InMilliseconds()
157 << "ms since the last frame was drawn.";
158 last_draw_frame_time_ = now;
159
159 angle_ += 2.0; 160 angle_ += 2.0;
160 if (angle_ >= 360.0) 161 if (angle_ >= 360.0)
161 angle_ = 0.0; 162 angle_ = 0.0;
162 163
163 const gfx::Rect bounds = window_->GetBoundsInRoot(); 164 const gfx::Rect bounds = window_->GetBoundsInRoot();
164 165
165 // Check that bitmap and window sizes match, otherwise reallocate bitmap. 166 // Check that bitmap and window sizes match, otherwise reallocate bitmap.
166 const SkImageInfo info = bitmap_.info(); 167 const SkImageInfo info = bitmap_.info();
167 if (info.width() != bounds.width() || info.height() != bounds.height()) { 168 if (info.width() != bounds.width() || info.height() != bounds.height()) {
168 AllocBitmap(); 169 AllocBitmap();
(...skipping 10 matching lines...) Expand all
179 // TODO(rjkroege): Make a 1/0-copy bitmap uploader for the contents of a 180 // TODO(rjkroege): Make a 1/0-copy bitmap uploader for the contents of a
180 // SkBitmap. 181 // SkBitmap.
181 bitmap_.lockPixels(); 182 bitmap_.lockPixels();
182 const unsigned char* addr = 183 const unsigned char* addr =
183 static_cast<const unsigned char*>(bitmap_.getPixels()); 184 static_cast<const unsigned char*>(bitmap_.getPixels());
184 const int bytes = bounds.width() * bounds.height() * 4; 185 const int bytes = bounds.width() * bounds.height() * 4;
185 std::unique_ptr<std::vector<unsigned char>> data( 186 std::unique_ptr<std::vector<unsigned char>> data(
186 new std::vector<unsigned char>(addr, addr + bytes)); 187 new std::vector<unsigned char>(addr, addr + bytes));
187 bitmap_.unlockPixels(); 188 bitmap_.unlockPixels();
188 189
190 #if defined(OS_ANDROID)
191 // TODO(jcivelli): find a way to not have an ifdef here.
192 BitmapUploader::Format bitmap_format = BitmapUploader::RGBA;
193 #else
194 BitmapUploader::Format bitmap_format = BitmapUploader::BGRA;
195 #endif
196
189 // Send frame to MUS via BitmapUploader. 197 // Send frame to MUS via BitmapUploader.
190 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), 198 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data),
191 BitmapUploader::BGRA); 199 bitmap_format);
192 } 200 }
193 201
194 } // namespace demo 202 } // namespace demo
195 } // namespace ui 203 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/demo/mus_demo.h ('k') | services/ui/demo/mus_demo_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698