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

Unified Diff: examples/sky_compositor_app/sky_compositor_app.cc

Issue 740923002: Add a simple compositor for Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address reviewer comments 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 side-by-side diff with in-line comments
Download patch
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..39fe103b69b734f635eebebc496ab727a91dba0a
--- /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) {
+ 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));
+ layer_host_->SetRootLayer(root_layer_);
+ }
+
+ void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override {
+ mojo::ApplicationImpl::Terminate();
+ }
+
+ private:
+ // sky::LayerHostClient
+ mojo::Shell* GetShell() override { return shell_; }
+
+ void BeginFrame() override { root_layer_->SetSize(ToSize(view_->bounds())); }
+
+ void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) override {
+ view_->SetSurfaceId(surface_id.Pass());
+ }
+
+ // sky::LayerClient
+ 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);
+}

Powered by Google App Engine
This is Rietveld 408576698