diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-05 13:45:02 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-05 13:45:02 +0000 |
commit | 423683913b3f751872c45546ed786fb96897387f (patch) | |
tree | 3d6ba5c876d401c96d70f15fdaa73a6dc0b69797 /mojo | |
parent | fdef2ba4d537537757ce6aa220a7c412bac59015 (diff) | |
download | chromium_src-423683913b3f751872c45546ed786fb96897387f.zip chromium_src-423683913b3f751872c45546ed786fb96897387f.tar.gz chromium_src-423683913b3f751872c45546ed786fb96897387f.tar.bz2 |
Add a basic NativeViewportX11 for Mojo
This CL adds a basic implementation of NativeViewport for X11. It puts a window
on screen and initializes GL for that window.
One disadvantage of this CL is that it requires use_aura to be set to 1 in
GYP_DEFINES.
R=ben@chromium.org
Review URL: https://codereview.chromium.org/48323005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232960 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/mojo.gyp | 1 | ||||
-rw-r--r-- | mojo/services/native_viewport/native_viewport_x11.cc | 63 | ||||
-rw-r--r-- | mojo/shell/desktop/mojo_main.cc | 3 |
3 files changed, 65 insertions, 2 deletions
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp index afda2d0..2f40b17 100644 --- a/mojo/mojo.gyp +++ b/mojo/mojo.gyp @@ -176,6 +176,7 @@ 'type': 'executable', 'dependencies': [ '../base/base.gyp:base', + '../ui/gl/gl.gyp:gl', '../url/url.gyp:url_lib', 'mojo_shell_lib', 'mojo_system', diff --git a/mojo/services/native_viewport/native_viewport_x11.cc b/mojo/services/native_viewport/native_viewport_x11.cc index df4f5d9..e0c23ce 100644 --- a/mojo/services/native_viewport/native_viewport_x11.cc +++ b/mojo/services/native_viewport/native_viewport_x11.cc @@ -4,15 +4,61 @@ #include "mojo/services/native_viewport/native_viewport.h" +#include <X11/Xlib.h> + +#include "base/bind.h" +#include "base/logging.h" +#include "base/message_loop/message_loop.h" +#include "base/message_loop/message_pump_x11.h" +#include "gpu/command_buffer/client/gl_in_process_context.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/x/x11_types.h" + namespace mojo { namespace services { -class NativeViewportX11 : public NativeViewport { +class NativeViewportX11 : public NativeViewport, + public base::MessagePumpDispatcher { public: NativeViewportX11(NativeViewportDelegate* delegate) - : delegate_(delegate) { + : delegate_(delegate), + bounds_(10, 10, 500, 500) { + XDisplay* display = gfx::GetXDisplay(); + XSetWindowAttributes swa; + memset(&swa, 0, sizeof(swa)); + swa.override_redirect = False; + window_ = XCreateWindow( + display, + DefaultRootWindow(display), + bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), + 0, // border width + CopyFromParent, // depth + InputOutput, + CopyFromParent, // visual + CWBackPixmap | CWOverrideRedirect, &swa); + + base::MessagePumpX11::Current()->AddDispatcherForWindow(this, window_); + base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); + + XMapWindow(display, window_); + XFlush(display); + + gpu::GLInProcessContextAttribs attribs; + gl_context_.reset(gpu::GLInProcessContext::CreateContext( + false, window_, bounds_.size(), false, + attribs, gfx::PreferDiscreteGpu)); + gl_context_->SetContextLostCallback(base::Bind( + &NativeViewportX11::OnGLContextLost, base::Unretained(this))); + + delegate_->OnGLContextAvailable(gl_context_->GetImplementation()); } + virtual ~NativeViewportX11() { + base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); + base::MessagePumpX11::Current()->RemoveDispatcherForWindow(window_); + + XDestroyWindow(gfx::GetXDisplay(), window_); } private: @@ -22,7 +68,20 @@ class NativeViewportX11 : public NativeViewport { delegate_->OnDestroyed(); } + // Overridden from base::MessagePumpDispatcher: + virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE { + return true; + } + + void OnGLContextLost() { + gl_context_.reset(); + delegate_->OnGLContextLost(); + } + NativeViewportDelegate* delegate_; + gfx::Rect bounds_; + XID window_; + scoped_ptr<gpu::GLInProcessContext> gl_context_; DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); }; diff --git a/mojo/shell/desktop/mojo_main.cc b/mojo/shell/desktop/mojo_main.cc index bf1f973..991997b 100644 --- a/mojo/shell/desktop/mojo_main.cc +++ b/mojo/shell/desktop/mojo_main.cc @@ -7,11 +7,14 @@ #include "base/command_line.h" #include "base/message_loop/message_loop.h" #include "mojo/shell/run.h" +#include "ui/gl/gl_surface.h" int main(int argc, char** argv) { base::AtExitManager at_exit; CommandLine::Init(argc, argv); + gfx::GLSurface::InitializeOneOff(); + base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); mojo::shell::Context context; |