OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/macros.h" |
| 6 #include "mojo/application/application_runner_chromium.h" |
| 7 #include "mojo/public/c/system/main.h" |
| 8 #include "mojo/public/cpp/application/application_connection.h" |
| 9 #include "mojo/public/cpp/application/application_delegate.h" |
| 10 #include "mojo/public/cpp/application/application_impl.h" |
| 11 #include "mojo/services/public/cpp/view_manager/view.h" |
| 12 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 13 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
| 14 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 15 #include "sky/compositor/layer.h" |
| 16 #include "sky/compositor/layer_host.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 |
| 19 namespace examples { |
| 20 namespace { |
| 21 |
| 22 gfx::Size ToSize(const mojo::Rect& rect) { |
| 23 return gfx::Size(rect.width, rect.height); |
| 24 } |
| 25 } |
| 26 |
| 27 class SkyCompositorApp : public mojo::ApplicationDelegate, |
| 28 public mojo::ViewManagerDelegate, |
| 29 public sky::LayerClient, |
| 30 public sky::LayerHostClient { |
| 31 public: |
| 32 SkyCompositorApp() : shell_(nullptr), view_(nullptr) {} |
| 33 virtual ~SkyCompositorApp() {} |
| 34 |
| 35 void Initialize(mojo::ApplicationImpl* app) override { |
| 36 shell_ = app->shell(); |
| 37 view_manager_client_factory_.reset( |
| 38 new mojo::ViewManagerClientFactory(app->shell(), this)); |
| 39 } |
| 40 |
| 41 bool ConfigureIncomingConnection( |
| 42 mojo::ApplicationConnection* connection) override { |
| 43 connection->AddService(view_manager_client_factory_.get()); |
| 44 return true; |
| 45 } |
| 46 |
| 47 void OnEmbed(mojo::ViewManager* view_manager, |
| 48 mojo::View* root, |
| 49 mojo::ServiceProviderImpl* exported_services, |
| 50 scoped_ptr<mojo::ServiceProvider> imported_services) override { |
| 51 view_ = root; |
| 52 |
| 53 layer_host_.reset(new sky::LayerHost(this)); |
| 54 root_layer_ = make_scoped_refptr(new sky::Layer(this)); |
| 55 layer_host_->SetRootLayer(root_layer_); |
| 56 } |
| 57 |
| 58 void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override { |
| 59 mojo::ApplicationImpl::Terminate(); |
| 60 } |
| 61 |
| 62 private: |
| 63 // sky::LayerHostClient |
| 64 mojo::Shell* GetShell() override { return shell_; } |
| 65 |
| 66 void BeginFrame() override { root_layer_->SetSize(ToSize(view_->bounds())); } |
| 67 |
| 68 void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) override { |
| 69 view_->SetSurfaceId(surface_id.Pass()); |
| 70 } |
| 71 |
| 72 // sky::LayerClient |
| 73 void PaintContents(SkCanvas* canvas, const gfx::Rect& clip) override { |
| 74 SkPaint paint; |
| 75 paint.setColor(SK_ColorGREEN); |
| 76 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 77 canvas->drawCircle(50, 100, 100, paint); |
| 78 } |
| 79 |
| 80 mojo::Shell* shell_; |
| 81 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; |
| 82 mojo::View* view_; |
| 83 |
| 84 scoped_ptr<sky::LayerHost> layer_host_; |
| 85 scoped_refptr<sky::Layer> root_layer_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(SkyCompositorApp); |
| 88 }; |
| 89 |
| 90 } // namespace examples |
| 91 |
| 92 MojoResult MojoMain(MojoHandle handle) { |
| 93 mojo::ApplicationRunnerChromium runner(new examples::SkyCompositorApp); |
| 94 return runner.Run(handle); |
| 95 } |
OLD | NEW |