Chromium Code Reviews| Index: examples/sky_compositor_app/sky_compositor_app.cc |
| diff --git a/examples/sky_compositor_app/sky_compositor_app.cc b/examples/sky_compositor_app/sky_compositor_app.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..719c5e45598d91b6deac7cdb48567fd7ef6bb99c |
| --- /dev/null |
| +++ b/examples/sky_compositor_app/sky_compositor_app.cc |
| @@ -0,0 +1,95 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/macros.h" |
| +#include "mojo/application/application_runner_chromium.h" |
| +#include "mojo/public/c/system/main.h" |
| +#include "mojo/public/cpp/application/application_connection.h" |
| +#include "mojo/public/cpp/application/application_delegate.h" |
| +#include "mojo/public/cpp/application/application_impl.h" |
| +#include "mojo/services/public/cpp/view_manager/view.h" |
| +#include "mojo/services/public/cpp/view_manager/view_manager.h" |
| +#include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
| +#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| +#include "sky/compositor/layer.h" |
| +#include "sky/compositor/layer_host.h" |
| +#include "third_party/skia/include/core/SkCanvas.h" |
| + |
| +namespace examples { |
| +namespace { |
| + |
| +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
|
| + return gfx::Size(rect.width, rect.height); |
| +} |
| +} |
| + |
| +class SkyCompositorApp : public mojo::ApplicationDelegate, |
| + public mojo::ViewManagerDelegate, |
| + public sky::LayerClient, |
| + public sky::LayerHostClient { |
| + public: |
| + SkyCompositorApp() : shell_(nullptr), view_(nullptr) {} |
| + virtual ~SkyCompositorApp() {} |
| + |
| + void Initialize(mojo::ApplicationImpl* app) override { |
| + shell_ = app->shell(); |
| + view_manager_client_factory_.reset( |
| + new mojo::ViewManagerClientFactory(app->shell(), this)); |
| + } |
| + |
| + bool ConfigureIncomingConnection( |
| + mojo::ApplicationConnection* connection) override { |
| + connection->AddService(view_manager_client_factory_.get()); |
| + return true; |
| + } |
| + |
| + void OnEmbed(mojo::ViewManager* view_manager, |
| + mojo::View* root, |
| + mojo::ServiceProviderImpl* exported_services, |
| + scoped_ptr<mojo::ServiceProvider> imported_services) override { |
| + view_ = root; |
| + |
| + layer_host_.reset(new sky::LayerHost(this)); |
| + 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
|
| + layer_host_->SetRootLayer(root_layer_); |
| + } |
| + |
| + void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override { |
| + 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.
|
| + } |
| + |
| + private: |
| + // sky::LayerHostClient |
| + mojo::Shell* GetShell() override { return shell_; } |
|
eseidel
2014/11/20 20:40:31
Style explosion. I thought this was Shell()?
|
| + |
| + void BeginFrame() override { root_layer_->SetSize(ToSize(view_->bounds())); } |
| + |
| + void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) override { |
| + view_->SetSurfaceId(surface_id.Pass()); |
| + } |
| + |
| + // sky::LayerHostClient |
|
ojan
2014/11/20 21:25:46
// sky::LayerClient ?
abarth-chromium
2014/11/20 22:07:20
Done.
|
| + void PaintContents(SkCanvas* canvas, const gfx::Rect& clip) override { |
| + SkPaint paint; |
| + paint.setColor(SK_ColorGREEN); |
| + paint.setFlags(SkPaint::kAntiAlias_Flag); |
| + canvas->drawCircle(50, 100, 100, paint); |
| + } |
| + |
| + mojo::Shell* shell_; |
| + scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; |
| + mojo::View* view_; |
| + |
| + scoped_ptr<sky::LayerHost> layer_host_; |
| + scoped_refptr<sky::Layer> root_layer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SkyCompositorApp); |
| +}; |
| + |
| +} // namespace examples |
| + |
| +MojoResult MojoMain(MojoHandle handle) { |
| + mojo::ApplicationRunnerChromium runner(new examples::SkyCompositorApp); |
| + return runner.Run(handle); |
| +} |