| OLD | NEW |
| 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 Loading... |
| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 const gfx::Rect bounds = window_->GetBoundsInRoot(); | 142 const gfx::Rect bounds = window_->GetBoundsInRoot(); |
| 148 | 143 |
| 149 // Allocate bitmap the same size as the window for drawing. | 144 // Allocate bitmap the same size as the window for drawing. |
| 150 bitmap_.reset(); | 145 bitmap_.reset(); |
| 151 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), | 146 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), |
| 152 kPremul_SkAlphaType); | 147 kPremul_SkAlphaType); |
| 153 bitmap_.allocPixels(image_info); | 148 bitmap_.allocPixels(image_info); |
| 154 } | 149 } |
| 155 | 150 |
| 156 void MusDemo::DrawFrame() { | 151 void MusDemo::DrawFrame() { |
| 152 base::TimeTicks now = base::TimeTicks::Now(); |
| 153 |
| 154 VLOG(1) << (now - last_draw_frame_time_).InMilliseconds() |
| 155 << "ms since the last frame was drawn."; |
| 156 last_draw_frame_time_ = now; |
| 157 |
| 157 angle_ += 2.0; | 158 angle_ += 2.0; |
| 158 if (angle_ >= 360.0) | 159 if (angle_ >= 360.0) |
| 159 angle_ = 0.0; | 160 angle_ = 0.0; |
| 160 | 161 |
| 161 const gfx::Rect bounds = window_->GetBoundsInRoot(); | 162 const gfx::Rect bounds = window_->GetBoundsInRoot(); |
| 162 | 163 |
| 163 // Check that bitmap and window sizes match, otherwise reallocate bitmap. | 164 // Check that bitmap and window sizes match, otherwise reallocate bitmap. |
| 164 const SkImageInfo info = bitmap_.info(); | 165 const SkImageInfo info = bitmap_.info(); |
| 165 if (info.width() != bounds.width() || info.height() != bounds.height()) { | 166 if (info.width() != bounds.width() || info.height() != bounds.height()) { |
| 166 AllocBitmap(); | 167 AllocBitmap(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 177 // TODO(rjkroege): Make a 1/0-copy bitmap uploader for the contents of a | 178 // TODO(rjkroege): Make a 1/0-copy bitmap uploader for the contents of a |
| 178 // SkBitmap. | 179 // SkBitmap. |
| 179 bitmap_.lockPixels(); | 180 bitmap_.lockPixels(); |
| 180 const unsigned char* addr = | 181 const unsigned char* addr = |
| 181 static_cast<const unsigned char*>(bitmap_.getPixels()); | 182 static_cast<const unsigned char*>(bitmap_.getPixels()); |
| 182 const int bytes = bounds.width() * bounds.height() * 4; | 183 const int bytes = bounds.width() * bounds.height() * 4; |
| 183 std::unique_ptr<std::vector<unsigned char>> data( | 184 std::unique_ptr<std::vector<unsigned char>> data( |
| 184 new std::vector<unsigned char>(addr, addr + bytes)); | 185 new std::vector<unsigned char>(addr, addr + bytes)); |
| 185 bitmap_.unlockPixels(); | 186 bitmap_.unlockPixels(); |
| 186 | 187 |
| 188 #if defined(OS_ANDROID) |
| 189 BitmapUploader::Format bitmap_format = BitmapUploader::RGBA; |
| 190 #else |
| 191 BitmapUploader::Format bitmap_format = BitmapUploader::BGRA; |
| 192 #endif |
| 193 |
| 187 // Send frame to MUS via BitmapUploader. | 194 // Send frame to MUS via BitmapUploader. |
| 188 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), | 195 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), |
| 189 BitmapUploader::BGRA); | 196 bitmap_format); |
| 190 } | 197 } |
| 191 | 198 |
| 192 } // namespace demo | 199 } // namespace demo |
| 193 } // namespace ui | 200 } // namespace ui |
| OLD | NEW |