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) { | |
eseidel
2014/11/20 20:40:31
Lame you have to define this yourself. Does mojo:
abarth-chromium
2014/11/20 20:47:57
mojo::Rect doesn't have any helper functions. The
| |
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)); | |
eseidel
2014/11/20 20:40:31
What's with the lower_case_method?
abarth-chromium
2014/11/20 20:47:57
It's supposed to be an analogy to make_unique_ptr
| |
55 layer_host_->SetRootLayer(root_layer_); | |
56 } | |
57 | |
58 void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override { | |
59 base::MessageLoop::current()->Quit(); | |
eseidel
2014/11/20 20:40:31
AppManager::Terminate or some such. Look at what
abarth-chromium
2014/11/20 22:07:20
Done.
| |
60 } | |
61 | |
62 private: | |
63 // sky::LayerHostClient | |
64 mojo::Shell* GetShell() override { return shell_; } | |
eseidel
2014/11/20 20:40:31
Style explosion. I thought this was 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::LayerHostClient | |
ojan
2014/11/20 21:25:46
// sky::LayerClient ?
abarth-chromium
2014/11/20 22:07:20
Done.
| |
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 |