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

Unified Diff: mojo/services/native_viewport/native_viewport_x11.cc

Issue 48323005: Add a basic NativeViewportX11 for Mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make GL work Created 7 years, 1 month 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
« no previous file with comments | « mojo/mojo.gyp ('k') | mojo/shell/desktop/mojo_main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/native_viewport/native_viewport_x11.cc
diff --git a/mojo/services/native_viewport/native_viewport_x11.cc b/mojo/services/native_viewport/native_viewport_x11.cc
index df4f5d951bb6c9a12524d41807c953430f94b37d..e0c23ce1202926d361a96ba7dd6b25419da350d9 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);
};
« no previous file with comments | « mojo/mojo.gyp ('k') | mojo/shell/desktop/mojo_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698