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

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

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

Powered by Google App Engine
This is Rietveld 408576698