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

Side by Side Diff: mojo/services/native_viewport/native_viewport_x11.cc

Issue 59383011: Factor common code into native_viewport_controller.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows build 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/services/native_viewport/native_viewport_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/services/native_viewport/native_viewport.h" 5 #include "mojo/services/native_viewport/native_viewport.h"
6 6
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 8
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_pump_x11.h" 10 #include "base/message_loop/message_pump_x11.h"
13 #include "gpu/command_buffer/client/gl_in_process_context.h"
14 #include "gpu/command_buffer/client/gles2_implementation.h"
15 #include "ui/gfx/rect.h" 11 #include "ui/gfx/rect.h"
16 #include "ui/gfx/x/x11_types.h" 12 #include "ui/gfx/x/x11_types.h"
17 13
18 namespace mojo { 14 namespace mojo {
19 namespace services { 15 namespace services {
20 16
21 class NativeViewportX11 : public NativeViewport, 17 class NativeViewportX11 : public NativeViewport,
22 public base::MessagePumpDispatcher { 18 public base::MessagePumpDispatcher {
23 public: 19 public:
24 NativeViewportX11(NativeViewportDelegate* delegate) 20 NativeViewportX11(NativeViewportDelegate* delegate)
(...skipping 12 matching lines...) Expand all
37 InputOutput, 33 InputOutput,
38 CopyFromParent, // visual 34 CopyFromParent, // visual
39 CWBackPixmap | CWOverrideRedirect, &swa); 35 CWBackPixmap | CWOverrideRedirect, &swa);
40 36
41 base::MessagePumpX11::Current()->AddDispatcherForWindow(this, window_); 37 base::MessagePumpX11::Current()->AddDispatcherForWindow(this, window_);
42 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); 38 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this);
43 39
44 XMapWindow(display, window_); 40 XMapWindow(display, window_);
45 XFlush(display); 41 XFlush(display);
46 42
47 gpu::GLInProcessContextAttribs attribs; 43 delegate_->OnAcceleratedWidgetAvailable(window_);
48 gl_context_.reset(gpu::GLInProcessContext::CreateContext(
49 false, window_, bounds_.size(), false,
50 attribs, gfx::PreferDiscreteGpu));
51 gl_context_->SetContextLostCallback(base::Bind(
52 &NativeViewportX11::OnGLContextLost, base::Unretained(this)));
53
54 delegate_->OnGLContextAvailable(gl_context_->GetImplementation());
55 } 44 }
56 45
57 virtual ~NativeViewportX11() { 46 virtual ~NativeViewportX11() {
58 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); 47 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this);
59 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(window_); 48 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(window_);
60 49
61 XDestroyWindow(gfx::GetXDisplay(), window_); 50 XDestroyWindow(gfx::GetXDisplay(), window_);
62 } 51 }
63 52
64 private: 53 private:
65 // Overridden from NativeViewport: 54 // Overridden from NativeViewport:
55 virtual gfx::Size GetSize() OVERRIDE {
56 return bounds_.size();
57 }
66 virtual void Close() OVERRIDE { 58 virtual void Close() OVERRIDE {
67 // TODO(beng): perform this in response to XWindow destruction. 59 // TODO(beng): perform this in response to XWindow destruction.
68 delegate_->OnDestroyed(); 60 delegate_->OnDestroyed();
69 } 61 }
70 62
71 // Overridden from base::MessagePumpDispatcher: 63 // Overridden from base::MessagePumpDispatcher:
72 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE { 64 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE {
73 return true; 65 return true;
74 } 66 }
75 67
76 void OnGLContextLost() {
77 gl_context_.reset();
78 delegate_->OnGLContextLost();
79 }
80
81 NativeViewportDelegate* delegate_; 68 NativeViewportDelegate* delegate_;
82 gfx::Rect bounds_; 69 gfx::Rect bounds_;
83 XID window_; 70 XID window_;
84 scoped_ptr<gpu::GLInProcessContext> gl_context_;
85 71
86 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); 72 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11);
87 }; 73 };
88 74
89 // static 75 // static
90 scoped_ptr<NativeViewport> NativeViewport::Create( 76 scoped_ptr<NativeViewport> NativeViewport::Create(
91 shell::Context* context, 77 shell::Context* context,
92 NativeViewportDelegate* delegate) { 78 NativeViewportDelegate* delegate) {
93 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass(); 79 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass();
94 } 80 }
95 81
96 } // namespace services 82 } // namespace services
97 } // namespace mojo 83 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/native_viewport_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698