summaryrefslogtreecommitdiffstats
path: root/mojo/examples
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-28 02:39:06 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-28 02:39:06 +0000
commit10c6f09565830cbee5b1405d9b2c2689fb6d1c6c (patch)
tree83dd6cac42646e91c02c129af2d053f7a80c1b2e /mojo/examples
parent9ad009acc0ad30112b4e3c18a8ad66c518ee6b6b (diff)
downloadchromium_src-10c6f09565830cbee5b1405d9b2c2689fb6d1c6c.zip
chromium_src-10c6f09565830cbee5b1405d9b2c2689fb6d1c6c.tar.gz
chromium_src-10c6f09565830cbee5b1405d9b2c2689fb6d1c6c.tar.bz2
[Mojo] Draw GL from within sample_app
This CL replaces hello_world_service with native_viewport in mojo_shell and sample_app. After this CL, we're able to draw GL from within sample_app. However, we're still using a bit of a hack to transfer the GL interface to the sample_app. R=aa@chromium.org BUG=none Review URL: https://codereview.chromium.org/92643002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237659 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/examples')
-rw-r--r--mojo/examples/sample_app/hello_world_client_impl.cc28
-rw-r--r--mojo/examples/sample_app/hello_world_client_impl.h32
-rw-r--r--mojo/examples/sample_app/native_viewport_client_impl.cc41
-rw-r--r--mojo/examples/sample_app/native_viewport_client_impl.h33
-rw-r--r--mojo/examples/sample_app/sample_app.cc18
5 files changed, 81 insertions, 71 deletions
diff --git a/mojo/examples/sample_app/hello_world_client_impl.cc b/mojo/examples/sample_app/hello_world_client_impl.cc
deleted file mode 100644
index 2d6d112..0000000
--- a/mojo/examples/sample_app/hello_world_client_impl.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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 "mojo/examples/sample_app/hello_world_client_impl.h"
-
-#include <stdio.h>
-
-#include "base/message_loop/message_loop.h"
-
-namespace mojo {
-namespace examples {
-
-HelloWorldClientImpl::HelloWorldClientImpl(ScopedMessagePipeHandle pipe)
- : service_(pipe.Pass()) {
- service_.SetPeer(this);
-}
-
-void HelloWorldClientImpl::DidReceiveGreeting(int32_t result) {
- printf("DidReceiveGreeting from pipe: %d\n", result);
- // Stop the current message loop.
- base::MessageLoop::current()->QuitNow();
-}
-
-HelloWorldClientImpl::~HelloWorldClientImpl() {}
-
-} // examples
-} // mojo
diff --git a/mojo/examples/sample_app/hello_world_client_impl.h b/mojo/examples/sample_app/hello_world_client_impl.h
deleted file mode 100644
index 78277c0d..0000000
--- a/mojo/examples/sample_app/hello_world_client_impl.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// 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.
-
-#ifndef MOJO_EXAMPLES_SAMPLE_APP_HELLO_WORLD_CLIENT_IMPL_H_
-#define MOJO_EXAMPLES_SAMPLE_APP_HELLO_WORLD_CLIENT_IMPL_H_
-
-#include "mojo/public/bindings/lib/remote_ptr.h"
-#include "mojom/hello_world_service.h"
-
-namespace mojo {
-namespace examples {
-
-class HelloWorldClientImpl : public HelloWorldClientStub {
- public:
- explicit HelloWorldClientImpl(ScopedMessagePipeHandle pipe);
- virtual ~HelloWorldClientImpl();
-
- virtual void DidReceiveGreeting(int32_t result) MOJO_OVERRIDE;
-
- HelloWorldService* service() {
- return service_.get();
- }
-
- private:
- RemotePtr<HelloWorldService> service_;
-};
-
-} // examples
-} // mojo
-
-#endif // MOJO_EXAMPLES_SAMPLE_APP_HELLO_WORLD_CLIENT_IMPL_H_
diff --git a/mojo/examples/sample_app/native_viewport_client_impl.cc b/mojo/examples/sample_app/native_viewport_client_impl.cc
new file mode 100644
index 0000000..f7fa866
--- /dev/null
+++ b/mojo/examples/sample_app/native_viewport_client_impl.cc
@@ -0,0 +1,41 @@
+// 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 "mojo/examples/sample_app/native_viewport_client_impl.h"
+
+#include <stdio.h>
+
+#include "gpu/command_buffer/client/gles2_interface.h"
+
+namespace mojo {
+namespace examples {
+
+NativeViewportClientImpl::NativeViewportClientImpl(ScopedMessagePipeHandle pipe)
+ : service_(pipe.Pass()) {
+ service_.SetPeer(this);
+}
+
+NativeViewportClientImpl::~NativeViewportClientImpl() {
+}
+
+void NativeViewportClientImpl::DidOpen() {
+ printf("NativeViewportClientImpl::DidOpen\n");
+}
+
+void NativeViewportClientImpl::DidCreateGLContext(uint64_t encoded_gl) {
+ // Ack, Hans! It's the giant hack.
+ // TODO(abarth): Replace this hack with something more disciplined. Most
+ // likley, we should receive a MojoHandle that we pass off to a lib that
+ // populates the normal C API for GL.
+ gpu::gles2::GLES2Interface* gl =
+ reinterpret_cast<gpu::gles2::GLES2Interface*>(
+ static_cast<uintptr_t>(encoded_gl));
+
+ gl->ClearColor(0, 1, 0, 0);
+ gl->Clear(GL_COLOR_BUFFER_BIT);
+ gl->SwapBuffers();
+}
+
+} // examples
+} // mojo
diff --git a/mojo/examples/sample_app/native_viewport_client_impl.h b/mojo/examples/sample_app/native_viewport_client_impl.h
new file mode 100644
index 0000000..da5b0a1
--- /dev/null
+++ b/mojo/examples/sample_app/native_viewport_client_impl.h
@@ -0,0 +1,33 @@
+// 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.
+
+#ifndef MOJO_EXAMPLES_SAMPLE_APP_NATIVE_VIEWPORT_CLIENT_IMPL_H_
+#define MOJO_EXAMPLES_SAMPLE_APP_NATIVE_VIEWPORT_CLIENT_IMPL_H_
+
+#include "mojo/public/bindings/lib/remote_ptr.h"
+#include "mojom/native_viewport.h"
+
+namespace mojo {
+namespace examples {
+
+class NativeViewportClientImpl : public NativeViewportClientStub {
+ public:
+ explicit NativeViewportClientImpl(ScopedMessagePipeHandle pipe);
+ virtual ~NativeViewportClientImpl();
+
+ virtual void DidOpen() MOJO_OVERRIDE;
+ virtual void DidCreateGLContext(uint64_t gl) MOJO_OVERRIDE;
+
+ NativeViewport* service() {
+ return service_.get();
+ }
+
+ private:
+ RemotePtr<NativeViewport> service_;
+};
+
+} // examples
+} // mojo
+
+#endif // MOJO_EXAMPLES_SAMPLE_APP_NATIVE_VIEWPORT_CLIENT_IMPL_H_
diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc
index ef51a3b..1229a5f 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -7,7 +7,7 @@
#include "base/message_loop/message_loop.h"
#include "mojo/common/bindings_support_impl.h"
-#include "mojo/examples/sample_app/hello_world_client_impl.h"
+#include "mojo/examples/sample_app/native_viewport_client_impl.h"
#include "mojo/public/bindings/lib/bindings_support.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
@@ -25,15 +25,12 @@
namespace mojo {
namespace examples {
-void SayHello(ScopedMessagePipeHandle pipe) {
- // Send message out.
- HelloWorldClientImpl client(pipe.Pass());
- ScratchBuffer buf;
- const std::string kGreeting("hello, world!");
- String greeting(kGreeting, &buf);
- client.service()->Greeting(greeting);
+void Start(ScopedMessagePipeHandle pipe) {
+ printf("Starting sample app.\n");
+ NativeViewportClientImpl client(pipe.Pass());
+ printf("Opening native viewport.\n");
+ client.service()->Open();
- // Run loop to receieve Ack. The client will quit the loop.
base::MessageLoop::current()->Run();
}
@@ -42,13 +39,12 @@ void SayHello(ScopedMessagePipeHandle pipe) {
extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) {
base::MessageLoop loop;
- // Set the global bindings support.
mojo::common::BindingsSupportImpl bindings_support;
mojo::BindingsSupport::Set(&bindings_support);
mojo::ScopedMessagePipeHandle scoped_handle;
scoped_handle.reset(mojo::MessagePipeHandle(pipe));
- mojo::examples::SayHello(scoped_handle.Pass());
+ mojo::examples::Start(scoped_handle.Pass());
mojo::BindingsSupport::Set(NULL);
return MOJO_RESULT_OK;