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

Unified Diff: mojo/examples/aura_demo/aura_demo.cc

Issue 120503003: run aura_demo as a mojo app (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: builds on X11 now too Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: mojo/examples/aura_demo/aura_demo.cc
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7296e54228b1ef70accf781a086f3c12215a5d46
--- /dev/null
+++ b/mojo/examples/aura_demo/aura_demo.cc
@@ -0,0 +1,214 @@
+// Copyright 2013 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 <stdio.h>
+#include <string>
+
+#include "base/message_loop/message_loop.h"
+#include "mojo/common/bindings_support_impl.h"
+#include "mojo/examples/aura_demo/demo_screen.h"
+#include "mojo/examples/aura_demo/root_window_host_mojo.h"
+#include "mojo/examples/compositor_app/compositor_host.h"
+#include "mojo/examples/compositor_app/gles2_client_impl.h"
+#include "mojo/public/bindings/lib/bindings_support.h"
+#include "mojo/public/bindings/lib/remote_ptr.h"
+#include "mojo/public/gles2/gles2.h"
+#include "mojo/public/system/core.h"
+#include "mojo/public/system/macros.h"
+#include "mojom/native_viewport.h"
+#include "mojom/shell.h"
+#include "ui/aura/client/default_capture_client.h"
+#include "ui/aura/client/window_tree_client.h"
+#include "ui/aura/env.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_delegate.h"
+#include "ui/base/hit_test.h"
+#include "ui/gfx/canvas.h"
+
+#if defined(WIN32)
+#if !defined(CDECL)
+#define CDECL __cdecl
+#endif
+#define AURA_DEMO_EXPORT __declspec(dllexport)
+#else
+#define CDECL
+#define AURA_DEMO_EXPORT __attribute__((visibility("default")))
+#endif
+
+namespace mojo {
+namespace examples {
+
+// Trivial WindowDelegate implementation that draws a colored background.
+class DemoWindowDelegate : public aura::WindowDelegate {
+ public:
+ explicit DemoWindowDelegate(SkColor color) : color_(color) {}
+
+ // Overridden from WindowDelegate:
+ virtual gfx::Size GetMinimumSize() const OVERRIDE {
+ return gfx::Size();
+ }
+
+ virtual gfx::Size GetMaximumSize() const OVERRIDE {
+ return gfx::Size();
+ }
+
+ virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds) OVERRIDE {}
+ virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
+ return gfx::kNullCursor;
+ }
+ virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
+ return HTCAPTION;
+ }
+ virtual bool ShouldDescendIntoChildForEventHandling(
+ aura::Window* child,
+ const gfx::Point& location) OVERRIDE {
+ return true;
+ }
+ virtual bool CanFocus() OVERRIDE { return true; }
+ virtual void OnCaptureLost() OVERRIDE {}
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ canvas->DrawColor(color_, SkXfermode::kSrc_Mode);
+ }
+ virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
+ virtual void OnWindowDestroying() OVERRIDE {}
+ virtual void OnWindowDestroyed() OVERRIDE {}
+ virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {}
+ virtual bool HasHitTestMask() const OVERRIDE { return false; }
+ virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
+ virtual void DidRecreateLayer(ui::Layer* old_layer,
+ ui::Layer* new_layer) OVERRIDE {}
+
+ private:
+ SkColor color_;
+
+ DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
+};
+
+class DemoWindowTreeClient : public aura::client::WindowTreeClient {
+ public:
+ explicit DemoWindowTreeClient(aura::Window* window) : window_(window) {
+ aura::client::SetWindowTreeClient(window_, this);
+ }
+
+ virtual ~DemoWindowTreeClient() {
+ aura::client::SetWindowTreeClient(window_, NULL);
+ }
+
+ // Overridden from aura::client::WindowTreeClient:
+ virtual aura::Window* GetDefaultParent(aura::Window* context,
+ aura::Window* window,
+ const gfx::Rect& bounds) OVERRIDE {
+ if (!capture_client_) {
+ capture_client_.reset(
+ new aura::client::DefaultCaptureClient(window_->GetRootWindow()));
+ }
+ return window_;
+ }
+
+ private:
+ aura::Window* window_;
+
+ scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
+
+ DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient);
+};
+
+class AuraDemo : public ShellClientStub {
+ public:
+ explicit AuraDemo(ScopedMessagePipeHandle shell_handle)
+ : shell_(shell_handle.Pass()) {
+ shell_.SetPeer(this);
+
+ screen_.reset(DemoScreen::Create());
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
+
+ mojo::ScopedMessagePipeHandle client_handle, native_viewport_handle;
+ CreateMessagePipe(&client_handle, &native_viewport_handle);
+ root_window_host_.reset(new RootWindowHostMojo(
+ native_viewport_handle.Pass(),
+ base::Bind(&AuraDemo::HostContextCreated, base::Unretained(this))));
+ mojo::AllocationScope scope;
+ shell_->Connect("mojo:mojo_native_viewport_service", client_handle.Pass());
+ }
+
+ virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
+ NOTREACHED() << "AuraDemo can't be connected to.";
+ }
+
+ private:
+
sky 2014/01/06 23:19:43 nit: remove newline.
+ void HostContextCreated() {
+ aura::RootWindow::CreateParams params(gfx::Rect(0, 0, 500, 500));
+ params.host = root_window_host_.get();
+ root_window_.reset(new aura::RootWindow(params));
+ root_window_host_->set_delegate(root_window_.get());
+ root_window_->Init();
+
+ window_tree_client_.reset(new DemoWindowTreeClient(root_window_->window()));
+
+ delegate1_.reset(new DemoWindowDelegate(SK_ColorBLUE));
+ window1_.reset(new aura::Window(delegate1_.get()));
+ window1_->Init(ui::LAYER_TEXTURED);
+ window1_->SetBounds(gfx::Rect(100, 100, 400, 400));
+ window1_->Show();
+ root_window_->window()->AddChild(window1_.get());
+
+ delegate2_.reset(new DemoWindowDelegate(SK_ColorRED));
+ window2_.reset(new aura::Window(delegate2_.get()));
+ window2_->Init(ui::LAYER_TEXTURED);
+ window2_->SetBounds(gfx::Rect(200, 200, 350, 350));
+ window2_->Show();
+ root_window_->window()->AddChild(window2_.get());
+
+ delegate21_.reset(new DemoWindowDelegate(SK_ColorGREEN));
+ window21_.reset(new aura::Window(delegate21_.get()));
+ window21_->Init(ui::LAYER_TEXTURED);
+ window21_->SetBounds(gfx::Rect(10, 10, 50, 50));
+ window21_->Show();
+ window2_->AddChild(window21_.get());
+
+ root_window_->host()->Show();
+ }
+
+ scoped_ptr<DemoScreen> screen_;
+
+ scoped_ptr<DemoWindowTreeClient> window_tree_client_;
+
+ scoped_ptr<aura::Window> window1_;
+ scoped_ptr<aura::Window> window2_;
+ scoped_ptr<aura::Window> window21_;
+
+ scoped_ptr<DemoWindowDelegate> delegate1_;
+ scoped_ptr<DemoWindowDelegate> delegate2_;
+ scoped_ptr<DemoWindowDelegate> delegate21_;
+
+ mojo::RemotePtr<Shell> shell_;
+ scoped_ptr<RootWindowHostMojo> root_window_host_;
+ scoped_ptr<aura::RootWindow> root_window_;
+};
+
+} // namespace examples
+} // namespace mojo
+
+extern "C" AURA_DEMO_EXPORT MojoResult CDECL MojoMain(
+ MojoHandle shell_handle) {
+ base::MessageLoop loop;
+ mojo::common::BindingsSupportImpl bindings_support_impl;
+ mojo::BindingsSupport::Set(&bindings_support_impl);
+ MojoGLES2Initialize();
+
+ // TODO(beng): This crashes in a DCHECK on X11 because this thread's
+ // MessageLoop is not of TYPE_UI. I think we need a way to build
+ // Aura that doesn't define platform-specific stuff.
+ aura::Env::CreateInstance();
+ mojo::examples::AuraDemo app(
+ mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass());
+ loop.Run();
+
+ MojoGLES2Terminate();
+ mojo::BindingsSupport::Set(NULL);
+ return MOJO_RESULT_OK;
+}

Powered by Google App Engine
This is Rietveld 408576698