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

Side by Side Diff: ui/gfx/gl/gl_context_glx.cc

Issue 7021014: GLContext no longer holds a pointer to a GLSurface. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 extern "C" { 5 extern "C" {
6 #include <X11/Xlib.h> 6 #include <X11/Xlib.h>
7 } 7 }
8 8
9 #include "ui/gfx/gl/gl_context_glx.h" 9 #include "ui/gfx/gl/gl_context_glx.h"
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
12 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" 13 #include "third_party/mesa/MesaLib/include/GL/osmesa.h"
13 #include "ui/gfx/gl/gl_bindings.h" 14 #include "ui/gfx/gl/gl_bindings.h"
14 #include "ui/gfx/gl/gl_implementation.h" 15 #include "ui/gfx/gl/gl_implementation.h"
15 #include "ui/gfx/gl/gl_surface_glx.h" 16 #include "ui/gfx/gl/gl_surface_glx.h"
16 17
17 namespace gfx { 18 namespace gfx {
18 19
19 namespace { 20 namespace {
20 21
21 bool IsCompositingWindowManagerActive(Display* display) { 22 bool IsCompositingWindowManagerActive(Display* display) {
22 // The X macro "None" has been undefined by gl_bindings.h. 23 // The X macro "None" has been undefined by gl_bindings.h.
23 const int kNone = 0; 24 const int kNone = 0;
24 static Atom net_wm_cm_s0 = kNone; 25 static Atom net_wm_cm_s0 = kNone;
25 if (net_wm_cm_s0 == kNone) { 26 if (net_wm_cm_s0 == kNone) {
26 net_wm_cm_s0 = XInternAtom(display, "_NET_WM_CM_S0", True); 27 net_wm_cm_s0 = XInternAtom(display, "_NET_WM_CM_S0", True);
27 } 28 }
28 if (net_wm_cm_s0 == kNone) { 29 if (net_wm_cm_s0 == kNone) {
29 return false; 30 return false;
30 } 31 }
31 return XGetSelectionOwner(display, net_wm_cm_s0) != kNone; 32 return XGetSelectionOwner(display, net_wm_cm_s0) != kNone;
32 } 33 }
33 34
34 } // namespace anonymous 35 } // namespace anonymous
35 36
36 GLContextGLX::GLContextGLX(GLSurfaceGLX* surface) 37 GLContextGLX::GLContextGLX()
37 : surface_(surface), 38 : context_(NULL) {
38 context_(NULL) {
39 } 39 }
40 40
41 GLContextGLX::~GLContextGLX() { 41 GLContextGLX::~GLContextGLX() {
42 Destroy(); 42 Destroy();
43 } 43 }
44 44
45 bool GLContextGLX::Initialize(GLContext* shared_context) { 45 bool GLContextGLX::Initialize(GLContext* shared_context,
46 GLSurface* compatible_surface) {
47 GLSurfaceGLX* surface_glx = static_cast<GLSurfaceGLX*>(compatible_surface);
46 context_ = glXCreateNewContext( 48 context_ = glXCreateNewContext(
47 GLSurfaceGLX::GetDisplay(), 49 GLSurfaceGLX::GetDisplay(),
48 static_cast<GLXFBConfig>(surface_->GetConfig()), 50 static_cast<GLXFBConfig>(surface_glx->GetConfig()),
49 GLX_RGBA_TYPE, 51 GLX_RGBA_TYPE,
50 static_cast<GLXContext>( 52 static_cast<GLXContext>(
51 shared_context ? shared_context->GetHandle() : NULL), 53 shared_context ? shared_context->GetHandle() : NULL),
52 True); 54 True);
53 if (!context_) { 55 if (!context_) {
54 LOG(ERROR) << "Couldn't create GL context."; 56 LOG(ERROR) << "Couldn't create GL context.";
55 Destroy(); 57 Destroy();
56 return false; 58 return false;
57 } 59 }
58 60
59 return true; 61 return true;
60 } 62 }
61 63
62 void GLContextGLX::Destroy() { 64 void GLContextGLX::Destroy() {
63 if (context_) { 65 if (context_) {
64 glXDestroyContext(GLSurfaceGLX::GetDisplay(), 66 glXDestroyContext(GLSurfaceGLX::GetDisplay(),
65 static_cast<GLXContext>(context_)); 67 static_cast<GLXContext>(context_));
66 context_ = NULL; 68 context_ = NULL;
67 } 69 }
68 } 70 }
69 71
70 bool GLContextGLX::MakeCurrent() { 72 bool GLContextGLX::MakeCurrent(GLSurface* surface) {
71 if (IsCurrent()) { 73 DCHECK(context_);
74 if (IsCurrent(surface))
72 return true; 75 return true;
73 }
74 76
75 if (!glXMakeContextCurrent( 77 if (!glXMakeContextCurrent(
76 GLSurfaceGLX::GetDisplay(), 78 GLSurfaceGLX::GetDisplay(),
77 reinterpret_cast<GLXDrawable>(surface_->GetHandle()), 79 reinterpret_cast<GLXDrawable>(surface->GetHandle()),
78 reinterpret_cast<GLXDrawable>(surface_->GetHandle()), 80 reinterpret_cast<GLXDrawable>(surface->GetHandle()),
79 static_cast<GLXContext>(context_))) { 81 static_cast<GLXContext>(context_))) {
80 Destroy(); 82 Destroy();
81 LOG(ERROR) << "Couldn't make context current."; 83 LOG(ERROR) << "Couldn't make context current.";
82 return false; 84 return false;
83 } 85 }
84 86
85 return true; 87 return true;
86 } 88 }
87 89
88 bool GLContextGLX::IsCurrent() { 90 void GLContextGLX::ReleaseCurrent(GLSurface* surface) {
89 // TODO(apatrick): When surface is split from context, cannot use surface_ 91 if (!IsCurrent(surface))
90 // here. 92 return;
91 return glXGetCurrentDrawable() == 93
92 reinterpret_cast<GLXDrawable>(surface_->GetHandle()) && 94 glXMakeContextCurrent(GLSurfaceGLX::GetDisplay(), 0, 0, NULL);
93 glXGetCurrentContext() == static_cast<GLXContext>(context_);
94 } 95 }
95 96
96 bool GLContextGLX::IsOffscreen() { 97 bool GLContextGLX::IsCurrent(GLSurface* surface) {
97 // TODO(apatrick): remove this from GLContext interface. 98 if (glXGetCurrentContext() != static_cast<GLXContext>(context_))
98 return surface_->IsOffscreen(); 99 return false;
99 }
100 100
101 bool GLContextGLX::SwapBuffers() { 101 if (surface) {
102 // TODO(apatrick): remove this from GLContext interface. 102 if (glXGetCurrentDrawable() !=
103 return surface_->SwapBuffers(); 103 reinterpret_cast<GLXDrawable>(surface->GetHandle())) {
104 } 104 return false;
105 }
106 }
105 107
106 gfx::Size GLContextGLX::GetSize() { 108 return true;
107 // TODO(apatrick): remove this from GLContext interface.
108 return surface_->GetSize();
109 } 109 }
110 110
111 void* GLContextGLX::GetHandle() { 111 void* GLContextGLX::GetHandle() {
112 return context_; 112 return context_;
113 } 113 }
114 114
115 void GLContextGLX::SetSwapInterval(int interval) { 115 void GLContextGLX::SetSwapInterval(int interval) {
116 DCHECK(IsCurrent()); 116 DCHECK(IsCurrent(NULL));
117 if (HasExtension("GLX_EXT_swap_control") && glXSwapIntervalEXT) { 117 if (HasExtension("GLX_EXT_swap_control") && glXSwapIntervalEXT) {
118 // Only enable vsync if we aren't using a compositing window 118 // Only enable vsync if we aren't using a compositing window
119 // manager. At the moment, compositing window managers don't 119 // manager. At the moment, compositing window managers don't
120 // respect this setting anyway (tearing still occurs) and it 120 // respect this setting anyway (tearing still occurs) and it
121 // dramatically increases latency. 121 // dramatically increases latency.
122 if (!IsCompositingWindowManagerActive(GLSurfaceGLX::GetDisplay())) { 122 if (!IsCompositingWindowManagerActive(GLSurfaceGLX::GetDisplay())) {
123 glXSwapIntervalEXT( 123 glXSwapIntervalEXT(
124 GLSurfaceGLX::GetDisplay(), 124 GLSurfaceGLX::GetDisplay(),
125 reinterpret_cast<GLXDrawable>(surface_->GetHandle()), 125 glXGetCurrentDrawable(),
126 interval); 126 interval);
127 } 127 }
128 } 128 }
129 } 129 }
130 130
131 std::string GLContextGLX::GetExtensions() { 131 std::string GLContextGLX::GetExtensions() {
132 DCHECK(IsCurrent()); 132 DCHECK(IsCurrent(NULL));
133 const char* extensions = glXQueryExtensionsString( 133 const char* extensions = glXQueryExtensionsString(
134 GLSurfaceGLX::GetDisplay(), 134 GLSurfaceGLX::GetDisplay(),
135 0); 135 0);
136 if (extensions) { 136 if (extensions) {
137 return GLContext::GetExtensions() + " " + extensions; 137 return GLContext::GetExtensions() + " " + extensions;
138 } 138 }
139 139
140 return GLContext::GetExtensions(); 140 return GLContext::GetExtensions();
141 } 141 }
142 142
143 } // namespace gfx 143 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698