| 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/time/time.h" | 8 #include "base/time/time.h" |
| 8 #include "services/shell/public/cpp/connector.h" | 9 #include "services/shell/public/cpp/connector.h" |
| 9 #include "services/ui/demo/bitmap_uploader.h" | 10 #include "services/ui/demo/bitmap_uploader.h" |
| 10 #include "services/ui/public/cpp/gpu_service.h" | 11 #include "services/ui/public/cpp/gpu_service.h" |
| 11 #include "services/ui/public/cpp/window.h" | 12 #include "services/ui/public/cpp/window.h" |
| 12 #include "services/ui/public/cpp/window_tree_client.h" | 13 #include "services/ui/public/cpp/window_tree_client.h" |
| 13 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 14 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
| 15 #include "third_party/skia/include/core/SkImageInfo.h" | 16 #include "third_party/skia/include/core/SkImageInfo.h" |
| 16 #include "third_party/skia/include/core/SkPaint.h" | 17 #include "third_party/skia/include/core/SkPaint.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 -SkFloatToScalar(canvas_size.height() * 0.5f)); | 54 -SkFloatToScalar(canvas_size.height() * 0.5f)); |
| 54 } | 55 } |
| 55 | 56 |
| 56 canvas->drawRect(rect, paint); | 57 canvas->drawRect(rect, paint); |
| 57 } | 58 } |
| 58 | 59 |
| 59 } // namespace | 60 } // namespace |
| 60 | 61 |
| 61 MusDemo::MusDemo() {} | 62 MusDemo::MusDemo() {} |
| 62 | 63 |
| 63 MusDemo::~MusDemo() { | 64 MusDemo::~MusDemo() {} |
| 64 delete window_tree_client_; | |
| 65 } | |
| 66 | 65 |
| 67 void MusDemo::OnStart(const shell::Identity& identity) { | 66 void MusDemo::OnStart(const shell::Identity& identity) { |
| 68 gpu_service_ = GpuService::Create(connector()); | 67 gpu_service_ = GpuService::Create(connector()); |
| 69 window_tree_client_ = new WindowTreeClient(this, this, nullptr); | 68 window_tree_client_ = base::MakeUnique<WindowTreeClient>(this, this); |
| 70 window_tree_client_->ConnectAsWindowManager(connector()); | 69 window_tree_client_->ConnectAsWindowManager(connector()); |
| 71 } | 70 } |
| 72 | 71 |
| 73 bool MusDemo::OnConnect(const shell::Identity& remote_identity, | 72 bool MusDemo::OnConnect(const shell::Identity& remote_identity, |
| 74 shell::InterfaceRegistry* registry) { | 73 shell::InterfaceRegistry* registry) { |
| 75 return true; | 74 return true; |
| 76 } | 75 } |
| 77 | 76 |
| 78 void MusDemo::OnEmbed(Window* window) { | 77 void MusDemo::OnEmbed(Window* window) { |
| 79 // Not called for the WindowManager. | 78 // Not called for the WindowManager. |
| 80 NOTREACHED(); | 79 NOTREACHED(); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void MusDemo::OnDidDestroyClient(WindowTreeClient* client) { | 82 void MusDemo::OnEmbedRootDestroyed(Window* root) { |
| 84 window_tree_client_ = nullptr; | 83 // Not called for the WindowManager. |
| 84 NOTREACHED(); |
| 85 } |
| 86 |
| 87 void MusDemo::OnLostConnection(WindowTreeClient* client) { |
| 88 window_ = nullptr; |
| 89 window_tree_client_.reset(); |
| 85 timer_.Stop(); | 90 timer_.Stop(); |
| 86 } | 91 } |
| 87 | 92 |
| 88 void MusDemo::OnPointerEventObserved(const PointerEvent& event, | 93 void MusDemo::OnPointerEventObserved(const PointerEvent& event, |
| 89 Window* target) {} | 94 Window* target) {} |
| 90 | 95 |
| 91 void MusDemo::SetWindowManagerClient(WindowManagerClient* client) {} | 96 void MusDemo::SetWindowManagerClient(WindowManagerClient* client) {} |
| 92 | 97 |
| 93 bool MusDemo::OnWmSetBounds(Window* window, gfx::Rect* bounds) { | 98 bool MusDemo::OnWmSetBounds(Window* window, gfx::Rect* bounds) { |
| 94 return true; | 99 return true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 109 const std::set<Window*>& client_windows, | 114 const std::set<Window*>& client_windows, |
| 110 bool janky) { | 115 bool janky) { |
| 111 // Don't care | 116 // Don't care |
| 112 } | 117 } |
| 113 | 118 |
| 114 void MusDemo::OnWmNewDisplay(Window* window, const display::Display& display) { | 119 void MusDemo::OnWmNewDisplay(Window* window, const display::Display& display) { |
| 115 DCHECK(!window_); // Only support one display. | 120 DCHECK(!window_); // Only support one display. |
| 116 window_ = window; | 121 window_ = window; |
| 117 | 122 |
| 118 // Initialize bitmap uploader for sending frames to MUS. | 123 // Initialize bitmap uploader for sending frames to MUS. |
| 119 uploader_.reset(new ui::BitmapUploader(window_)); | 124 uploader_.reset(new BitmapUploader(window_)); |
| 120 uploader_->Init(gpu_service_.get()); | 125 uploader_->Init(gpu_service_.get()); |
| 121 | 126 |
| 122 // Draw initial frame and start the timer to regularly draw frames. | 127 // Draw initial frame and start the timer to regularly draw frames. |
| 123 DrawFrame(); | 128 DrawFrame(); |
| 124 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay), | 129 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay), |
| 125 base::Bind(&MusDemo::DrawFrame, base::Unretained(this))); | 130 base::Bind(&MusDemo::DrawFrame, base::Unretained(this))); |
| 126 } | 131 } |
| 127 | 132 |
| 128 void MusDemo::OnWmPerformMoveLoop(Window* window, | 133 void MusDemo::OnWmPerformMoveLoop(Window* window, |
| 129 mojom::MoveLoopSource source, | 134 mojom::MoveLoopSource source, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 bitmap_.lockPixels(); | 175 bitmap_.lockPixels(); |
| 171 const unsigned char* addr = | 176 const unsigned char* addr = |
| 172 static_cast<const unsigned char*>(bitmap_.getPixels()); | 177 static_cast<const unsigned char*>(bitmap_.getPixels()); |
| 173 const int bytes = bounds.width() * bounds.height() * 4; | 178 const int bytes = bounds.width() * bounds.height() * 4; |
| 174 std::unique_ptr<std::vector<unsigned char>> data( | 179 std::unique_ptr<std::vector<unsigned char>> data( |
| 175 new std::vector<unsigned char>(addr, addr + bytes)); | 180 new std::vector<unsigned char>(addr, addr + bytes)); |
| 176 bitmap_.unlockPixels(); | 181 bitmap_.unlockPixels(); |
| 177 | 182 |
| 178 // Send frame to MUS via BitmapUploader. | 183 // Send frame to MUS via BitmapUploader. |
| 179 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), | 184 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), |
| 180 ui::BitmapUploader::BGRA); | 185 BitmapUploader::BGRA); |
| 181 } | 186 } |
| 182 | 187 |
| 183 } // namespace demo | 188 } // namespace demo |
| 184 } // namespace ui | 189 } // namespace ui |
| OLD | NEW |