|
Lines 28-263
Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h_sec1
|
| 28 |
|
28 |
|
| 29 |
#if USE(ACCELERATED_COMPOSITING) && HAVE(GLX) |
29 |
#if USE(ACCELERATED_COMPOSITING) && HAVE(GLX) |
| 30 |
|
30 |
|
| 31 |
#include "GLPlatformSurface.h" |
31 |
#include "GLXWindowResources.h" |
| 32 |
#if USE(GRAPHICS_SURFACE) |
32 |
|
| 33 |
#include <X11/extensions/Xcomposite.h> |
|
|
| 34 |
#include <X11/extensions/Xrender.h> |
| 35 |
#endif |
| 36 |
#include <wtf/Noncopyable.h> |
33 |
#include <wtf/Noncopyable.h> |
| 37 |
#include <wtf/RefCounted.h> |
|
|
| 38 |
|
34 |
|
| 39 |
namespace WebCore { |
35 |
namespace WebCore { |
| 40 |
|
36 |
|
| 41 |
class SharedX11Resources : public WTF::RefCountedBase { |
|
|
| 42 |
WTF_MAKE_NONCOPYABLE(SharedX11Resources); |
| 43 |
|
| 44 |
public: |
| 45 |
static PassRefPtr<SharedX11Resources> create() |
| 46 |
{ |
| 47 |
if (!m_staticSharedResource) |
| 48 |
m_staticSharedResource = new SharedX11Resources(); |
| 49 |
else |
| 50 |
m_staticSharedResource->ref(); |
| 51 |
|
| 52 |
return adoptRef(m_staticSharedResource); |
| 53 |
} |
| 54 |
|
| 55 |
void deref() |
| 56 |
{ |
| 57 |
if (derefBase()) { |
| 58 |
m_staticSharedResource = 0; |
| 59 |
delete this; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
Window getXWindow() |
| 64 |
{ |
| 65 |
if (!m_window) { |
| 66 |
Display* dpy = display(); |
| 67 |
XSetWindowAttributes attributes; |
| 68 |
attributes.override_redirect = true; |
| 69 |
m_window = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), -1, -1, 1, 1, 0, BlackPixel(dpy, 0), WhitePixel(dpy, 0)); |
| 70 |
// From http://tronche.com/gui/x/xlib/window/attributes/ |
| 71 |
XChangeWindowAttributes(dpy, m_window, CWOverrideRedirect, &attributes); |
| 72 |
XMapWindow(dpy, m_window); |
| 73 |
} |
| 74 |
|
| 75 |
return m_window; |
| 76 |
} |
| 77 |
|
| 78 |
Display* display() |
| 79 |
{ |
| 80 |
if (!m_display) |
| 81 |
m_display = XOpenDisplay(0); |
| 82 |
|
| 83 |
return m_display; |
| 84 |
} |
| 85 |
|
| 86 |
XVisualInfo* visualInfo() |
| 87 |
{ |
| 88 |
if (!m_VisualInfo) |
| 89 |
surfaceContextConfig(); |
| 90 |
|
| 91 |
return m_VisualInfo; |
| 92 |
} |
| 93 |
|
| 94 |
GLXFBConfig createConfig(const int attributes[]) |
| 95 |
{ |
| 96 |
int numReturned; |
| 97 |
m_VisualInfo = 0; |
| 98 |
GLXFBConfig* temp = glXChooseFBConfig(display(), DefaultScreen(display()), attributes, &numReturned); |
| 99 |
|
| 100 |
if (!numReturned) |
| 101 |
return 0; |
| 102 |
|
| 103 |
GLXFBConfig selectedConfig = 0; |
| 104 |
bool found = false; |
| 105 |
|
| 106 |
for (int i = 0; i < numReturned; ++i) { |
| 107 |
m_VisualInfo = glXGetVisualFromFBConfig(display(), temp[i]); |
| 108 |
if (!m_VisualInfo) |
| 109 |
continue; |
| 110 |
#if USE(GRAPHICS_SURFACE) |
37 |
#if USE(GRAPHICS_SURFACE) |
| 111 |
if (m_supportsXRenderExtension) { |
38 |
class GLXTransportSurface : public X11OffScreenWindow { |
| 112 |
XRenderPictFormat* format = XRenderFindVisualFormat(display(), m_VisualInfo->visual); |
|
|
| 113 |
if (format && format->direct.alphaMask > 0) { |
| 114 |
selectedConfig = temp[i]; |
| 115 |
found = true; |
| 116 |
break; |
| 117 |
} |
| 118 |
} else if (m_VisualInfo->depth == 32) { |
| 119 |
#else |
| 120 |
if (m_VisualInfo->depth == 32) { |
| 121 |
#endif |
| 122 |
selectedConfig = temp[i]; |
| 123 |
found = true; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
// Did not find any visual supporting alpha, select the first available config. |
| 128 |
if (!found) { |
| 129 |
selectedConfig = temp[0]; |
| 130 |
m_VisualInfo = glXGetVisualFromFBConfig(m_display, temp[0]); |
| 131 |
} |
| 132 |
|
| 133 |
XFree(temp); |
| 134 |
|
| 135 |
return selectedConfig; |
| 136 |
} |
| 137 |
|
| 138 |
GLXFBConfig pBufferContextConfig() |
| 139 |
{ |
| 140 |
if (!m_pbufferfbConfig) { |
| 141 |
static const int attributes[] = { |
| 142 |
GLX_LEVEL, 0, |
| 143 |
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, |
| 144 |
GLX_RENDER_TYPE, GLX_RGBA_BIT, |
| 145 |
GLX_RED_SIZE, 1, |
| 146 |
GLX_GREEN_SIZE, 1, |
| 147 |
GLX_BLUE_SIZE, 1, |
| 148 |
GLX_DOUBLEBUFFER, GL_FALSE, |
| 149 |
None |
| 150 |
}; |
| 151 |
|
| 152 |
int numReturned; |
| 153 |
GLXFBConfig* temp = glXChooseFBConfig(display(), DefaultScreen(display()), attributes, &numReturned); |
| 154 |
if (numReturned) |
| 155 |
m_pbufferfbConfig = temp[0]; |
| 156 |
XFree(temp); |
| 157 |
} |
| 158 |
|
| 159 |
return m_pbufferfbConfig; |
| 160 |
} |
| 161 |
|
| 162 |
GLXFBConfig surfaceContextConfig() |
| 163 |
{ |
| 164 |
if (!m_surfaceContextfbConfig) { |
| 165 |
static int attributes[] = { |
| 166 |
GLX_LEVEL, 0, |
| 167 |
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, |
| 168 |
GLX_RENDER_TYPE, GLX_RGBA_BIT, |
| 169 |
GLX_RED_SIZE, 1, |
| 170 |
GLX_GREEN_SIZE, 1, |
| 171 |
GLX_BLUE_SIZE, 1, |
| 172 |
GLX_ALPHA_SIZE, 1, |
| 173 |
GLX_DEPTH_SIZE, 1, |
| 174 |
GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, |
| 175 |
GLX_DOUBLEBUFFER, True, |
| 176 |
None |
| 177 |
}; |
| 178 |
#if USE(GRAPHICS_SURFACE) |
| 179 |
int eventBasep, errorBasep; |
| 180 |
m_supportsXRenderExtension = XRenderQueryExtension(display(), &eventBasep, &errorBasep); |
| 181 |
#endif |
| 182 |
m_surfaceContextfbConfig = createConfig(attributes); |
| 183 |
} |
| 184 |
|
| 185 |
return m_surfaceContextfbConfig; |
| 186 |
} |
| 187 |
|
| 188 |
bool isXRenderExtensionSupported() |
| 189 |
{ |
| 190 |
return m_supportsXRenderExtension; |
| 191 |
} |
| 192 |
|
| 193 |
private: |
| 194 |
SharedX11Resources() |
| 195 |
: m_supportsXRenderExtension(false) |
| 196 |
, m_markForDeletion(false) |
| 197 |
, m_window(0) |
| 198 |
, m_display(0) |
| 199 |
, m_pbufferfbConfig(0) |
| 200 |
, m_surfaceContextfbConfig(0) |
| 201 |
, m_VisualInfo(0) |
| 202 |
{ |
| 203 |
} |
| 204 |
|
| 205 |
~SharedX11Resources() |
| 206 |
{ |
| 207 |
if (!m_display) |
| 208 |
return; |
| 209 |
|
| 210 |
if (m_window) { |
| 211 |
XUnmapWindow(m_display, m_window); |
| 212 |
XDestroyWindow(m_display, m_window); |
| 213 |
m_window = 0; |
| 214 |
} |
| 215 |
|
| 216 |
if (m_pbufferfbConfig) |
| 217 |
m_pbufferfbConfig = 0; |
| 218 |
|
| 219 |
if (m_surfaceContextfbConfig) |
| 220 |
m_surfaceContextfbConfig = 0; |
| 221 |
|
| 222 |
if (m_VisualInfo) { |
| 223 |
XFree(m_VisualInfo); |
| 224 |
m_VisualInfo = 0; |
| 225 |
} |
| 226 |
|
| 227 |
XCloseDisplay(m_display); |
| 228 |
m_display = 0; |
| 229 |
} |
| 230 |
|
| 231 |
static SharedX11Resources* m_staticSharedResource; |
| 232 |
bool m_supportsXRenderExtension; |
| 233 |
bool m_markForDeletion; |
| 234 |
Window m_window; |
| 235 |
Display* m_display; |
| 236 |
GLXFBConfig m_pbufferfbConfig; |
| 237 |
GLXFBConfig m_surfaceContextfbConfig; |
| 238 |
XVisualInfo* m_VisualInfo; |
| 239 |
}; |
| 240 |
|
| 241 |
class GLXSurface : public GLPlatformSurface { |
| 242 |
WTF_MAKE_NONCOPYABLE(GLXSurface); |
| 243 |
|
| 244 |
public: |
| 245 |
GLXSurface(); |
| 246 |
virtual ~GLXSurface(); |
| 247 |
|
| 248 |
protected: |
| 249 |
XVisualInfo* visualInfo(); |
| 250 |
Window xWindow(); |
| 251 |
GLXFBConfig pBufferConfiguration(); |
| 252 |
GLXFBConfig transportSurfaceConfiguration(); |
| 253 |
bool isXRenderExtensionSupported(); |
| 254 |
|
| 255 |
private: |
| 256 |
RefPtr<SharedX11Resources> m_sharedResources; |
| 257 |
}; |
| 258 |
|
| 259 |
#if USE(GRAPHICS_SURFACE) |
| 260 |
class GLXTransportSurface : public GLXSurface { |
| 261 |
WTF_MAKE_NONCOPYABLE(GLXTransportSurface); |
39 |
WTF_MAKE_NONCOPYABLE(GLXTransportSurface); |
| 262 |
|
40 |
|
| 263 |
public: |
41 |
public: |
|
Lines 265-286
public:
Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h_sec2
|
| 265 |
virtual ~GLXTransportSurface(); |
43 |
virtual ~GLXTransportSurface(); |
| 266 |
PlatformSurfaceConfig configuration(); |
44 |
PlatformSurfaceConfig configuration(); |
| 267 |
void swapBuffers(); |
45 |
void swapBuffers(); |
| 268 |
void setGeometry(const IntRect& newRect); |
|
|
| 269 |
void destroy(); |
46 |
void destroy(); |
| 270 |
|
47 |
|
| 271 |
private: |
48 |
private: |
| 272 |
void initialize(); |
49 |
void initialize(); |
| 273 |
void freeResources(); |
|
|
| 274 |
}; |
50 |
}; |
| 275 |
#endif |
51 |
#endif |
| 276 |
|
52 |
|
| 277 |
class GLXPBuffer : public GLXSurface { |
53 |
class GLXPBuffer : public X11OffScreenWindow { |
| 278 |
WTF_MAKE_NONCOPYABLE(GLXPBuffer); |
54 |
WTF_MAKE_NONCOPYABLE(GLXPBuffer); |
| 279 |
|
55 |
|
| 280 |
public: |
56 |
public: |
| 281 |
GLXPBuffer(); |
57 |
GLXPBuffer(); |
| 282 |
virtual ~GLXPBuffer(); |
58 |
virtual ~GLXPBuffer(); |
| 283 |
PlatformSurfaceConfig configuration(); |
59 |
PlatformSurfaceConfig configuration(); |
|
|
60 |
void setGeometry(const IntRect&); |
| 284 |
void destroy(); |
61 |
void destroy(); |
| 285 |
|
62 |
|
| 286 |
private: |
63 |
private: |