summaryrefslogtreecommitdiffstats
path: root/mojo/services/native_viewport/native_viewport_impl.cc
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-28 10:13:15 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-28 10:13:15 +0000
commit9bb669dd6178b407ee0c4f0cd776696b239ebe82 (patch)
treeea7bff834660aae9cd3348c95c1bc2406d949f2f /mojo/services/native_viewport/native_viewport_impl.cc
parent3a131e88f4f9d1cca96237a93323314cbe9520b6 (diff)
downloadchromium_src-9bb669dd6178b407ee0c4f0cd776696b239ebe82.zip
chromium_src-9bb669dd6178b407ee0c4f0cd776696b239ebe82.tar.gz
chromium_src-9bb669dd6178b407ee0c4f0cd776696b239ebe82.tar.bz2
[Mojo] Introduce gles2 service
This CL introduces a Mojo service for GLES2 and uses that service to better structure the sample_app's use of GL. The implementation of the service lives in mojo/services/gles2 and currently creates an in-process command buffer. The implementation of the client lives in public/bindings/gles2_client, which wires up the command buffer to gles2_c_lib. When using public/bindings/gles2_client, Mojo applications can now use GL via the normal C API. BUG=none Review URL: https://codereview.chromium.org/93163002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237756 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/services/native_viewport/native_viewport_impl.cc')
-rw-r--r--mojo/services/native_viewport/native_viewport_impl.cc39
1 files changed, 18 insertions, 21 deletions
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) {