summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mojo/examples/hello_world_service/hello_world_service_impl.cc4
-rw-r--r--mojo/examples/hello_world_service/hello_world_service_impl.h4
-rw-r--r--mojo/examples/sample_app/native_viewport_client_impl.cc30
-rw-r--r--mojo/examples/sample_app/native_viewport_client_impl.h16
-rw-r--r--mojo/examples/sample_app/sample_app.cc11
-rw-r--r--mojo/examples/sample_app/sample_gles2_delegate.cc31
-rw-r--r--mojo/examples/sample_app/sample_gles2_delegate.h25
-rw-r--r--mojo/mojo.gyp57
-rw-r--r--mojo/public/bindings/gles2_client/DEPS3
-rw-r--r--mojo/public/bindings/gles2_client/gles2_client_impl.cc68
-rw-r--r--mojo/public/bindings/gles2_client/gles2_client_impl.h43
-rw-r--r--mojo/services/gles2/DEPS4
-rw-r--r--mojo/services/gles2/gles2.mojom18
-rw-r--r--mojo/services/gles2/gles2_impl.cc47
-rw-r--r--mojo/services/gles2/gles2_impl.h43
-rw-r--r--mojo/services/native_viewport/DEPS3
-rw-r--r--mojo/services/native_viewport/native_viewport.mojom4
-rw-r--r--mojo/services/native_viewport/native_viewport_impl.cc39
-rw-r--r--mojo/services/native_viewport/native_viewport_impl.h7
19 files changed, 392 insertions, 65 deletions
diff --git a/mojo/examples/hello_world_service/hello_world_service_impl.cc b/mojo/examples/hello_world_service/hello_world_service_impl.cc
index 0217569..3bca0fd 100644
--- a/mojo/examples/hello_world_service/hello_world_service_impl.cc
+++ b/mojo/examples/hello_world_service/hello_world_service_impl.cc
@@ -23,5 +23,5 @@ void HelloWorldServiceImpl::Greeting(const String& greeting) {
HelloWorldServiceImpl::~HelloWorldServiceImpl() {}
-} // examples
-} // mojo
+} // namespace examples
+} // namespace mojo
diff --git a/mojo/examples/hello_world_service/hello_world_service_impl.h b/mojo/examples/hello_world_service/hello_world_service_impl.h
index 2eef9bd..cffb5c9 100644
--- a/mojo/examples/hello_world_service/hello_world_service_impl.h
+++ b/mojo/examples/hello_world_service/hello_world_service_impl.h
@@ -21,7 +21,7 @@ class HelloWorldServiceImpl : public HelloWorldServiceStub {
RemotePtr<HelloWorldClient> client_;
};
-} // examples
-} // mojo
+} // namespace examples
+} // namespace mojo
#endif // MOJO_EXAMPLES_HELLO_WORLD_SERVICE_HELLO_WORLD_SERVICE_IMPL_H_
diff --git a/mojo/examples/sample_app/native_viewport_client_impl.cc b/mojo/examples/sample_app/native_viewport_client_impl.cc
index f7fa866..7701a18 100644
--- a/mojo/examples/sample_app/native_viewport_client_impl.cc
+++ b/mojo/examples/sample_app/native_viewport_client_impl.cc
@@ -6,7 +6,7 @@
#include <stdio.h>
-#include "gpu/command_buffer/client/gles2_interface.h"
+#include "mojo/public/bindings/gles2_client/gles2_client_impl.h"
namespace mojo {
namespace examples {
@@ -19,23 +19,19 @@ NativeViewportClientImpl::NativeViewportClientImpl(ScopedMessagePipeHandle pipe)
NativeViewportClientImpl::~NativeViewportClientImpl() {
}
-void NativeViewportClientImpl::DidOpen() {
- printf("NativeViewportClientImpl::DidOpen\n");
+void NativeViewportClientImpl::Open() {
+ service_->Open();
+
+ ScopedMessagePipeHandle gles2;
+ ScopedMessagePipeHandle gles2_client;
+ CreateMessagePipe(&gles2, &gles2_client);
+
+ gles2_client_.reset(new GLES2ClientImpl(&gles2_delegate_, gles2.Pass()));
+ service_->CreateGLES2Context(gles2_client.release());
}
-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();
+void NativeViewportClientImpl::DidOpen() {
}
-} // examples
-} // mojo
+} // namespace examples
+} // namespace mojo
diff --git a/mojo/examples/sample_app/native_viewport_client_impl.h b/mojo/examples/sample_app/native_viewport_client_impl.h
index da5b0a1..d959c45 100644
--- a/mojo/examples/sample_app/native_viewport_client_impl.h
+++ b/mojo/examples/sample_app/native_viewport_client_impl.h
@@ -5,6 +5,8 @@
#ifndef MOJO_EXAMPLES_SAMPLE_APP_NATIVE_VIEWPORT_CLIENT_IMPL_H_
#define MOJO_EXAMPLES_SAMPLE_APP_NATIVE_VIEWPORT_CLIENT_IMPL_H_
+#include "base/memory/scoped_ptr.h"
+#include "mojo/examples/sample_app/sample_gles2_delegate.h"
#include "mojo/public/bindings/lib/remote_ptr.h"
#include "mojom/native_viewport.h"
@@ -16,18 +18,18 @@ class NativeViewportClientImpl : public NativeViewportClientStub {
explicit NativeViewportClientImpl(ScopedMessagePipeHandle pipe);
virtual ~NativeViewportClientImpl();
+ void Open();
+
+ private:
virtual void DidOpen() MOJO_OVERRIDE;
- virtual void DidCreateGLContext(uint64_t gl) MOJO_OVERRIDE;
- NativeViewport* service() {
- return service_.get();
- }
+ SampleGLES2Delegate gles2_delegate_;
+ scoped_ptr<GLES2ClientImpl> gles2_client_;
- private:
RemotePtr<NativeViewport> service_;
};
-} // examples
-} // mojo
+} // namespace examples
+} // namespace 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 1229a5f..1cf86c4 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -8,6 +8,7 @@
#include "base/message_loop/message_loop.h"
#include "mojo/common/bindings_support_impl.h"
#include "mojo/examples/sample_app/native_viewport_client_impl.h"
+#include "mojo/public/bindings/gles2_client/gles2_client_impl.h"
#include "mojo/public/bindings/lib/bindings_support.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
@@ -28,24 +29,24 @@ namespace examples {
void Start(ScopedMessagePipeHandle pipe) {
printf("Starting sample app.\n");
NativeViewportClientImpl client(pipe.Pass());
- printf("Opening native viewport.\n");
- client.service()->Open();
-
+ client.Open();
base::MessageLoop::current()->Run();
}
-} // examples
-} // mojo
+} // namespace examples
+} // namespace mojo
extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) {
base::MessageLoop loop;
mojo::common::BindingsSupportImpl bindings_support;
mojo::BindingsSupport::Set(&bindings_support);
+ mojo::GLES2ClientImpl::Initialize();
mojo::ScopedMessagePipeHandle scoped_handle;
scoped_handle.reset(mojo::MessagePipeHandle(pipe));
mojo::examples::Start(scoped_handle.Pass());
+ mojo::GLES2ClientImpl::Terminate();
mojo::BindingsSupport::Set(NULL);
return MOJO_RESULT_OK;
}
diff --git a/mojo/examples/sample_app/sample_gles2_delegate.cc b/mojo/examples/sample_app/sample_gles2_delegate.cc
new file mode 100644
index 0000000..4741569
--- /dev/null
+++ b/mojo/examples/sample_app/sample_gles2_delegate.cc
@@ -0,0 +1,31 @@
+// 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/sample_gles2_delegate.h"
+
+#include <stdio.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+namespace mojo {
+namespace examples {
+
+SampleGLES2Delegate::SampleGLES2Delegate() {
+}
+
+SampleGLES2Delegate::~SampleGLES2Delegate() {
+}
+
+void SampleGLES2Delegate::DidCreateContext(GLES2* gl) {
+ glClearColor(0, 1, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ gl->SwapBuffers();
+}
+
+void SampleGLES2Delegate::ContextLost(GLES2* gl) {
+}
+
+} // namespace examples
+} // namespace mojo
diff --git a/mojo/examples/sample_app/sample_gles2_delegate.h b/mojo/examples/sample_app/sample_gles2_delegate.h
new file mode 100644
index 0000000..04faceb
--- /dev/null
+++ b/mojo/examples/sample_app/sample_gles2_delegate.h
@@ -0,0 +1,25 @@
+// 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_SAMPLE_GLES2_DELEGATE_H_
+#define MOJO_EXAMPLES_SAMPLE_APP_SAMPLE_GLES2_DELEGATE_H_
+
+#include "mojo/public/bindings/gles2_client/gles2_client_impl.h"
+
+namespace mojo {
+namespace examples {
+
+class SampleGLES2Delegate : public GLES2Delegate {
+ public:
+ SampleGLES2Delegate();
+ virtual ~SampleGLES2Delegate();
+
+ virtual void DidCreateContext(GLES2* gl) MOJO_OVERRIDE;
+ virtual void ContextLost(GLES2* gl) MOJO_OVERRIDE;
+};
+
+} // namespace examples
+} // namespace mojo
+
+#endif // MOJO_EXAMPLES_SAMPLE_APP_SAMPLE_GLES2_DELEGATE_H_
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index b40ccf8..2e26d12 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -318,15 +318,20 @@
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
+ '../gpu/gpu.gyp:gles2_c_lib',
'../ui/gl/gl.gyp:gl',
- 'native_viewport',
+ 'gles2',
+ 'gles2_client_impl',
'mojo_common_lib',
'mojo_system',
+ 'native_viewport',
],
'sources': [
'examples/sample_app/native_viewport_client_impl.cc',
'examples/sample_app/native_viewport_client_impl.h',
'examples/sample_app/sample_app.cc',
+ 'examples/sample_app/sample_gles2_delegate.cc',
+ 'examples/sample_app/sample_gles2_delegate.h',
'examples/sample_app/spinning_cube.cc',
'examples/sample_app/spinning_cube.h',
],
@@ -446,6 +451,52 @@
],
},
{
+ 'target_name': 'gles2',
+ 'type': 'static_library',
+ 'sources': [
+ 'services/gles2/gles2.mojom',
+ ],
+ 'includes': [ 'public/bindings/mojom_bindings_generator.gypi' ],
+ 'export_dependent_settings': [
+ 'mojo_bindings',
+ 'mojo_system',
+ ],
+ },
+ {
+ 'target_name': 'gles2_impl',
+ 'type': 'static_library',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../gpu/gpu.gyp:command_buffer_service',
+ '../gpu/gpu.gyp:gles2_implementation',
+ '../ui/gfx/gfx.gyp:gfx',
+ '../ui/gl/gl.gyp:gl',
+ 'gles2',
+ ],
+ 'export_dependent_settings': [
+ 'gles2',
+ ],
+ 'sources': [
+ 'services/gles2/gles2_impl.cc',
+ 'services/gles2/gles2_impl.h',
+ ],
+ },
+ {
+ 'target_name': 'gles2_client_impl',
+ 'type': 'static_library',
+ 'dependencies': [
+ '../gpu/gpu.gyp:gles2_c_lib',
+ 'gles2',
+ ],
+ 'export_dependent_settings': [
+ 'gles2',
+ ],
+ 'sources': [
+ 'public/bindings/gles2_client/gles2_client_impl.cc',
+ 'public/bindings/gles2_client/gles2_client_impl.h',
+ ],
+ },
+ {
'target_name': 'native_viewport',
'type': 'static_library',
'sources': [
@@ -462,11 +513,9 @@
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
- '../gpu/gpu.gyp:command_buffer_service',
- '../gpu/gpu.gyp:gles2_implementation',
'../ui/events/events.gyp:events',
'../ui/gfx/gfx.gyp:gfx',
- '../ui/gl/gl.gyp:gl',
+ 'gles2_impl',
'native_viewport',
],
'export_dependent_settings': [
diff --git a/mojo/public/bindings/gles2_client/DEPS b/mojo/public/bindings/gles2_client/DEPS
new file mode 100644
index 0000000..08992c3
--- /dev/null
+++ b/mojo/public/bindings/gles2_client/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+gpu/command_buffer/client",
+]
diff --git a/mojo/public/bindings/gles2_client/gles2_client_impl.cc b/mojo/public/bindings/gles2_client/gles2_client_impl.cc
new file mode 100644
index 0000000..a6e4323
--- /dev/null
+++ b/mojo/public/bindings/gles2_client/gles2_client_impl.cc
@@ -0,0 +1,68 @@
+// 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/public/bindings/gles2_client/gles2_client_impl.h"
+
+#include <assert.h>
+
+#include "gpu/command_buffer/client/gles2_lib.h"
+
+namespace mojo {
+namespace {
+
+bool g_gles2_initialized = false;
+
+} // namespace
+
+GLES2Delegate::~GLES2Delegate() {
+}
+
+void GLES2Delegate::DidCreateContext(GLES2* gl) {
+}
+
+void GLES2Delegate::ContextLost(GLES2* gl) {
+}
+
+GLES2ClientImpl::GLES2ClientImpl(GLES2Delegate* delegate,
+ ScopedMessagePipeHandle gl)
+ : delegate_(delegate),
+ gl_(gl.Pass()) {
+ assert(g_gles2_initialized);
+ gl_.SetPeer(this);
+}
+
+GLES2ClientImpl::~GLES2ClientImpl() {
+}
+
+void GLES2ClientImpl::Initialize() {
+ assert(!g_gles2_initialized);
+ gles2::Initialize();
+ g_gles2_initialized = true;
+}
+
+void GLES2ClientImpl::Terminate() {
+ assert(g_gles2_initialized);
+ gles2::Terminate();
+ g_gles2_initialized = false;
+}
+
+void GLES2ClientImpl::DidCreateContext(uint64_t encoded) {
+ // 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 use to wire up the
+ // client side of an out-of-process command buffer. Given that we're
+ // still in-process, we just reinterpret_cast the value into a GL interface.
+ gpu::gles2::GLES2Interface* gl_interface =
+ reinterpret_cast<gpu::gles2::GLES2Interface*>(
+ static_cast<uintptr_t>(encoded));
+ gles2::SetGLContext(gl_interface);
+
+ delegate_->DidCreateContext(gl());
+}
+
+void GLES2ClientImpl::ContextLost() {
+ delegate_->ContextLost(gl());
+}
+
+} // mojo
diff --git a/mojo/public/bindings/gles2_client/gles2_client_impl.h b/mojo/public/bindings/gles2_client/gles2_client_impl.h
new file mode 100644
index 0000000..656cc85
--- /dev/null
+++ b/mojo/public/bindings/gles2_client/gles2_client_impl.h
@@ -0,0 +1,43 @@
+// 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_PUBLIC_BINDINGS_GLES2_CLIENT_GLES2_CLIENT_IMPL_H_
+#define MOJO_PUBLIC_BINDINGS_GLES2_CLIENT_GLES2_CLIENT_IMPL_H_
+
+#include "mojo/public/bindings/lib/remote_ptr.h"
+#include "mojom/gles2.h"
+
+namespace mojo {
+
+class GLES2Delegate {
+ public:
+ virtual ~GLES2Delegate();
+ virtual void DidCreateContext(GLES2* gl);
+ virtual void ContextLost(GLES2* gl);
+};
+
+class GLES2ClientImpl : public GLES2ClientStub {
+ public:
+ explicit GLES2ClientImpl(GLES2Delegate* delegate,
+ ScopedMessagePipeHandle gl);
+ virtual ~GLES2ClientImpl();
+
+ static void Initialize();
+ static void Terminate();
+
+ GLES2* gl() {
+ return gl_.get();
+ }
+
+ private:
+ virtual void DidCreateContext(uint64_t encoded) MOJO_OVERRIDE;
+ virtual void ContextLost() MOJO_OVERRIDE;
+
+ GLES2Delegate* delegate_;
+ RemotePtr<GLES2> gl_;
+};
+
+} // mojo
+
+#endif // MOJO_PUBLIC_BINDINGS_GLES2_CLIENT_GLES2_CLIENT_IMPL_H_
diff --git a/mojo/services/gles2/DEPS b/mojo/services/gles2/DEPS
new file mode 100644
index 0000000..93a965e
--- /dev/null
+++ b/mojo/services/gles2/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "+gpu/command_buffer/client",
+ "+ui/gfx",
+]
diff --git a/mojo/services/gles2/gles2.mojom b/mojo/services/gles2/gles2.mojom
new file mode 100644
index 0000000..ecd144b
--- /dev/null
+++ b/mojo/services/gles2/gles2.mojom
@@ -0,0 +1,18 @@
+// 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.
+
+module mojo {
+
+[Peer=GLES2Client]
+interface GLES2 {
+ void SwapBuffers();
+};
+
+[Peer=GLES2]
+interface GLES2Client {
+ void DidCreateContext(uint64 encoded);
+ void ContextLost();
+};
+
+}
diff --git a/mojo/services/gles2/gles2_impl.cc b/mojo/services/gles2/gles2_impl.cc
new file mode 100644
index 0000000..dc214e56
--- /dev/null
+++ b/mojo/services/gles2/gles2_impl.cc
@@ -0,0 +1,47 @@
+// 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/services/gles2/gles2_impl.h"
+
+#include "base/bind.h"
+#include "gpu/command_buffer/client/gl_in_process_context.h"
+#include "gpu/command_buffer/client/gles2_implementation.h"
+
+namespace mojo {
+namespace services {
+
+GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client)
+ : client_(client.Pass()) {
+ client_.SetPeer(this);
+}
+
+GLES2Impl::~GLES2Impl() {
+}
+
+void GLES2Impl::SwapBuffers() {
+ if (!gl_context_)
+ return;
+ gl_context_->GetImplementation()->SwapBuffers();
+}
+
+void GLES2Impl::CreateContext(gfx::AcceleratedWidget widget,
+ const gfx::Size& size) {
+ gpu::GLInProcessContextAttribs attribs;
+ gl_context_.reset(gpu::GLInProcessContext::CreateContext(
+ false, widget, size, false, attribs, gfx::PreferDiscreteGpu));
+ gl_context_->SetContextLostCallback(base::Bind(
+ &GLES2Impl::OnGLContextLost, base::Unretained(this)));
+
+ gpu::gles2::GLES2Interface* gl = gl_context_->GetImplementation();
+ uint64_t encoded_gl = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(gl));
+
+ client_->DidCreateContext(encoded_gl);
+}
+
+void GLES2Impl::OnGLContextLost() {
+ client_->ContextLost();
+}
+
+} // namespace services
+} // namespace mojo
diff --git a/mojo/services/gles2/gles2_impl.h b/mojo/services/gles2/gles2_impl.h
new file mode 100644
index 0000000..a98a48b
--- /dev/null
+++ b/mojo/services/gles2/gles2_impl.h
@@ -0,0 +1,43 @@
+// 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_SERVICES_GLES2_GLES2_IMPL_H_
+#define MOJO_SERVICES_GLES2_GLES2_IMPL_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "mojo/public/bindings/lib/remote_ptr.h"
+#include "mojo/public/system/core_cpp.h"
+#include "mojom/gles2.h"
+#include "ui/gfx/native_widget_types.h"
+#include "ui/gfx/size.h"
+
+namespace gpu {
+class GLInProcessContext;
+}
+
+namespace mojo {
+namespace services {
+
+class GLES2Impl : public GLES2Stub {
+ public:
+ explicit GLES2Impl(ScopedMessagePipeHandle client);
+ virtual ~GLES2Impl();
+
+ virtual void SwapBuffers() OVERRIDE;
+
+ void CreateContext(gfx::AcceleratedWidget widget, const gfx::Size& size);
+
+ private:
+ void OnGLContextLost();
+
+ scoped_ptr<gpu::GLInProcessContext> gl_context_;
+ RemotePtr<GLES2Client> client_;
+
+ DISALLOW_COPY_AND_ASSIGN(GLES2Impl);
+};
+
+} // namespace services
+} // namespace mojo
+
+#endif // MOJO_SERVICES_GLES2_GLES2_IMPL_H_
diff --git a/mojo/services/native_viewport/DEPS b/mojo/services/native_viewport/DEPS
index 39917a2..6e465aa 100644
--- a/mojo/services/native_viewport/DEPS
+++ b/mojo/services/native_viewport/DEPS
@@ -1,6 +1,5 @@
include_rules = [
- "+base",
- "+gpu/command_buffer/client",
+ "+mojo/services/gles2",
"+ui/events",
"+ui/gfx",
]
diff --git a/mojo/services/native_viewport/native_viewport.mojom b/mojo/services/native_viewport/native_viewport.mojom
index 6bd750c..bd43b93 100644
--- a/mojo/services/native_viewport/native_viewport.mojom
+++ b/mojo/services/native_viewport/native_viewport.mojom
@@ -8,14 +8,12 @@ module mojo {
interface NativeViewport {
void Open();
void Close();
+ void CreateGLES2Context(handle gles2_client);
};
[Peer=NativeViewport]
interface NativeViewportClient {
void DidOpen();
-
- // Rather than send a uint64, we should send an opaque handle to a GL service.
- void DidCreateGLContext(uint64 gl);
};
}
diff --git a/mojo/services/native_viewport/native_viewport_impl.cc b/mojo/services/native_viewport/native_viewport_impl.cc
index cfd1070..80c1afa 100644
--- a/mojo/services/native_viewport/native_viewport_impl.cc
+++ b/mojo/services/native_viewport/native_viewport_impl.cc
@@ -4,13 +4,8 @@
#include "mojo/services/native_viewport/native_viewport_impl.h"
-#include <limits>
-
-#include "base/bind.h"
#include "base/message_loop/message_loop.h"
-#include "base/strings/stringprintf.h"
-#include "gpu/command_buffer/client/gl_in_process_context.h"
-#include "gpu/command_buffer/client/gles2_implementation.h"
+#include "mojo/services/gles2/gles2_impl.h"
#include "mojo/services/native_viewport/native_viewport.h"
#include "ui/events/event.h"
@@ -20,6 +15,7 @@ namespace services {
NativeViewportImpl::NativeViewportImpl(shell::Context* context,
ScopedMessagePipeHandle pipe)
: context_(context),
+ widget_(gfx::kNullAcceleratedWidget),
client_(pipe.Pass()) {
client_.SetPeer(this);
}
@@ -34,31 +30,32 @@ void NativeViewportImpl::Open() {
}
void NativeViewportImpl::Close() {
+ gles2_.reset();
DCHECK(native_viewport_);
native_viewport_->Close();
}
+void NativeViewportImpl::CreateGLES2Context(mojo::Handle gles2_client) {
+ ScopedMessagePipeHandle handle;
+ handle.reset(MessagePipeHandle(gles2_client.value()));
+ gles2_.reset(new GLES2Impl(handle.Pass()));
+ CreateGLES2ContextIfNeeded();
+}
+
+void NativeViewportImpl::CreateGLES2ContextIfNeeded() {
+ if (widget_ == gfx::kNullAcceleratedWidget || !gles2_)
+ return;
+ gles2_->CreateContext(widget_, native_viewport_->GetSize());
+}
+
bool NativeViewportImpl::OnEvent(ui::Event* event) {
return false;
}
void NativeViewportImpl::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) {
- gfx::Size size = native_viewport_->GetSize();
- gpu::GLInProcessContextAttribs attribs;
- gl_context_.reset(gpu::GLInProcessContext::CreateContext(
- false, widget, size, false, attribs, gfx::PreferDiscreteGpu));
- gl_context_->SetContextLostCallback(base::Bind(
- &NativeViewportImpl::OnGLContextLost, base::Unretained(this)));
-
- gpu::gles2::GLES2Interface* gl = gl_context_->GetImplementation();
- // TODO(abarth): Instead of drawing green, we want to send the context over
- // pipe_ somehow.
- uint64_t encoded_gl = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(gl));
- client_->DidCreateGLContext(encoded_gl);
-}
-
-void NativeViewportImpl::OnGLContextLost() {
+ widget_ = widget;
+ CreateGLES2ContextIfNeeded();
}
void NativeViewportImpl::OnResized(const gfx::Size& size) {
diff --git a/mojo/services/native_viewport/native_viewport_impl.h b/mojo/services/native_viewport/native_viewport_impl.h
index ace476b..9a90d91 100644
--- a/mojo/services/native_viewport/native_viewport_impl.h
+++ b/mojo/services/native_viewport/native_viewport_impl.h
@@ -18,6 +18,7 @@ class GLInProcessContext;
namespace mojo {
namespace services {
+class GLES2Impl;
class NativeViewportImpl : public NativeViewportStub,
public NativeViewportDelegate {
@@ -28,6 +29,7 @@ class NativeViewportImpl : public NativeViewportStub,
virtual void Open() OVERRIDE;
virtual void Close() OVERRIDE;
+ virtual void CreateGLES2Context(mojo::Handle gles2_client) OVERRIDE;
private:
// Overridden from services::NativeViewportDelegate:
@@ -37,11 +39,12 @@ class NativeViewportImpl : public NativeViewportStub,
virtual bool OnEvent(ui::Event* event) OVERRIDE;
virtual void OnDestroyed() OVERRIDE;
- void OnGLContextLost();
+ void CreateGLES2ContextIfNeeded();
shell::Context* context_;
+ gfx::AcceleratedWidget widget_;
scoped_ptr<services::NativeViewport> native_viewport_;
- scoped_ptr<gpu::GLInProcessContext> gl_context_;
+ scoped_ptr<GLES2Impl> gles2_;
RemotePtr<NativeViewportClient> client_;