Chromium Code Reviews| 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 "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 Loading... | |
| 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 } | |
| 96 | 103 |
| 104 // mus::WindowManagerDelegate: | |
| 105 void MusDemo::SetWindowManagerClient(mus::WindowManagerClient* client) { | |
| 106 window_manager_client_ = client; | |
| 107 } | |
|
kylechar
2016/05/24 14:38:42
Nit: Keep the consistent whitespace between the ne
rjkroege
2016/05/24 18:05:15
Done.
| |
| 97 bool MusDemo::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { | 108 bool MusDemo::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { |
| 98 return true; | 109 return true; |
| 99 } | 110 } |
| 100 | |
| 101 bool MusDemo::OnWmSetProperty(mus::Window* window, | 111 bool MusDemo::OnWmSetProperty(mus::Window* window, |
| 102 const std::string& name, | 112 const std::string& name, |
| 103 std::unique_ptr<std::vector<uint8_t>>* new_data) { | 113 std::unique_ptr<std::vector<uint8_t>>* new_data) { |
| 104 return true; | 114 return true; |
| 105 } | 115 } |
| 106 | 116 |
| 107 mus::Window* MusDemo::OnWmCreateTopLevelWindow( | 117 mus::Window* MusDemo::OnWmCreateTopLevelWindow( |
| 108 std::map<std::string, std::vector<uint8_t>>* properties) { | 118 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 109 // TODO(kylechar): Check if this should return something useful. | |
| 110 return nullptr; | 119 return nullptr; |
| 111 } | 120 } |
| 112 | 121 |
| 113 void MusDemo::OnAccelerator(uint32_t id, const ui::Event& event) {} | 122 void MusDemo::OnAccelerator(uint32_t id, const ui::Event& event) { |
| 123 // Don't care | |
| 124 } | |
| 125 | |
| 114 | 126 |
| 115 void MusDemo::AllocBitmap() { | 127 void MusDemo::AllocBitmap() { |
| 116 const gfx::Rect bounds = window_->GetBoundsInRoot(); | 128 const gfx::Rect bounds = window_->GetBoundsInRoot(); |
| 117 | 129 |
| 118 // Allocate bitmap the same size as the window for drawing. | 130 // Allocate bitmap the same size as the window for drawing. |
| 119 bitmap_.reset(); | 131 bitmap_.reset(); |
| 120 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), | 132 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), |
| 121 kPremul_SkAlphaType); | 133 kPremul_SkAlphaType); |
| 122 bitmap_.allocPixels(image_info); | 134 bitmap_.allocPixels(image_info); |
| 123 } | 135 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 152 std::unique_ptr<std::vector<unsigned char>> data( | 164 std::unique_ptr<std::vector<unsigned char>> data( |
| 153 new std::vector<unsigned char>(addr, addr + bytes)); | 165 new std::vector<unsigned char>(addr, addr + bytes)); |
| 154 bitmap_.unlockPixels(); | 166 bitmap_.unlockPixels(); |
| 155 | 167 |
| 156 // Send frame to MUS via BitmapUploader. | 168 // Send frame to MUS via BitmapUploader. |
| 157 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), | 169 uploader_->SetBitmap(bounds.width(), bounds.height(), std::move(data), |
| 158 bitmap_uploader::BitmapUploader::BGRA); | 170 bitmap_uploader::BitmapUploader::BGRA); |
| 159 } | 171 } |
| 160 | 172 |
| 161 } // namespace mus_demo | 173 } // namespace mus_demo |
| OLD | NEW |