Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: examples/sky_compositor_app/sky_compositor_app.cc

Issue 1239963003: Remove //services/sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « examples/sky_compositor_app/BUILD.gn ('k') | services/sky/OWNERS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/view_manager/public/cpp/view.h"
12 #include "mojo/services/view_manager/public/cpp/view_manager.h"
13 #include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h"
14 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h"
15 #include "services/sky/compositor/layer.h"
16 #include "services/sky/compositor/layer_host.h"
17 #include "services/sky/compositor/rasterizer_ganesh.h"
18 #include "third_party/skia/include/core/SkCanvas.h"
19
20 namespace examples {
21 namespace {
22
23 gfx::Size ToSize(const mojo::Rect& rect) {
24 return gfx::Size(rect.width, rect.height);
25 }
26
27 int RadiusAt(base::TimeDelta delta) {
28 return 50 + (delta.InMilliseconds() % 6000) * 100 / 6000;
29 }
30 }
31
32 class SkyCompositorApp : public mojo::ApplicationDelegate,
33 public mojo::ViewManagerDelegate,
34 public sky::LayerClient,
35 public sky::LayerHostClient {
36 public:
37 SkyCompositorApp() : shell_(nullptr), view_(nullptr) {}
38 ~SkyCompositorApp() override {}
39
40 void Initialize(mojo::ApplicationImpl* app) override {
41 shell_ = app->shell();
42 view_manager_client_factory_.reset(
43 new mojo::ViewManagerClientFactory(app->shell(), this));
44 }
45
46 bool ConfigureIncomingConnection(
47 mojo::ApplicationConnection* connection) override {
48 connection->AddService(view_manager_client_factory_.get());
49 return true;
50 }
51
52 void OnEmbed(mojo::View* root,
53 mojo::InterfaceRequest<mojo::ServiceProvider> services,
54 mojo::ServiceProviderPtr exposed_services) override {
55 view_ = root;
56 base_time_ = base::TimeTicks::Now();
57
58 layer_host_.reset(new sky::LayerHost(this));
59 root_layer_ = make_scoped_refptr(new sky::Layer(this));
60 root_layer_->set_rasterizer(
61 make_scoped_ptr(new sky::RasterizerGanesh(layer_host_.get())));
62 layer_host_->SetRootLayer(root_layer_);
63 layer_host_->SetNeedsAnimate();
64 }
65
66 void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override {
67 mojo::ApplicationImpl::Terminate();
68 }
69
70 private:
71 // sky::LayerHostClient
72 mojo::Shell* GetShell() override { return shell_; }
73
74 void BeginFrame(base::TimeTicks frame_time) override {
75 root_layer_->SetSize(ToSize(view_->bounds()));
76 layer_host_->SetNeedsAnimate();
77 }
78
79 void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) override {
80 view_->SetSurfaceId(surface_id.Pass());
81 }
82
83 // sky::LayerClient
84 void PaintContents(SkCanvas* canvas, const gfx::Rect& clip) override {
85 base::TimeTicks frame_time = base::TimeTicks::Now();
86 printf("Frame delta: %f\n",
87 (frame_time - last_frame_time_).InMillisecondsF());
88 last_frame_time_ = frame_time;
89
90 canvas->clear(SK_ColorGREEN);
91 SkPaint paint;
92 paint.setColor(SK_ColorBLUE);
93 paint.setFlags(SkPaint::kAntiAlias_Flag);
94 canvas->drawCircle(50, 100, RadiusAt(frame_time - base_time_), paint);
95 }
96
97 mojo::Shell* shell_;
98 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_;
99 mojo::View* view_;
100
101 scoped_ptr<sky::LayerHost> layer_host_;
102 scoped_refptr<sky::Layer> root_layer_;
103
104 base::TimeTicks base_time_;
105 base::TimeTicks last_frame_time_;
106
107 DISALLOW_COPY_AND_ASSIGN(SkyCompositorApp);
108 };
109
110 } // namespace examples
111
112 MojoResult MojoMain(MojoHandle handle) {
113 mojo::ApplicationRunnerChromium runner(new examples::SkyCompositorApp);
114 return runner.Run(handle);
115 }
OLDNEW
« no previous file with comments | « examples/sky_compositor_app/BUILD.gn ('k') | services/sky/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698