|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef GFX_XLIBSURFACE_H |
|
7 #define GFX_XLIBSURFACE_H |
|
8 |
|
9 #include "gfxASurface.h" |
|
10 |
|
11 #include <X11/extensions/Xrender.h> |
|
12 #include <X11/Xlib.h> |
|
13 |
|
14 #if defined(GL_PROVIDER_GLX) |
|
15 #include "GLXLibrary.h" |
|
16 #endif |
|
17 |
|
18 #include "nsSize.h" |
|
19 |
|
20 class gfxXlibSurface : public gfxASurface { |
|
21 public: |
|
22 // construct a wrapper around the specified drawable with dpy/visual. |
|
23 // Will use XGetGeometry to query the window/pixmap size. |
|
24 gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual); |
|
25 |
|
26 // construct a wrapper around the specified drawable with dpy/visual, |
|
27 // and known width/height. |
|
28 gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfxIntSize& size); |
|
29 |
|
30 // construct a wrapper around the specified drawable with dpy/format, |
|
31 // and known width/height. |
|
32 gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format, |
|
33 const gfxIntSize& size); |
|
34 |
|
35 gfxXlibSurface(cairo_surface_t *csurf); |
|
36 |
|
37 // create a new Pixmap and wrapper surface. |
|
38 // |relatedDrawable| provides a hint to the server for determining whether |
|
39 // the pixmap should be in video or system memory. It must be on |
|
40 // |screen| (if specified). |
|
41 static already_AddRefed<gfxXlibSurface> |
|
42 Create(Screen *screen, Visual *visual, const gfxIntSize& size, |
|
43 Drawable relatedDrawable = None); |
|
44 static cairo_surface_t * |
|
45 CreateCairoSurface(Screen *screen, Visual *visual, const gfxIntSize& size, |
|
46 Drawable relatedDrawable = None); |
|
47 static already_AddRefed<gfxXlibSurface> |
|
48 Create(Screen* screen, XRenderPictFormat *format, const gfxIntSize& size, |
|
49 Drawable relatedDrawable = None); |
|
50 |
|
51 virtual ~gfxXlibSurface(); |
|
52 |
|
53 virtual already_AddRefed<gfxASurface> |
|
54 CreateSimilarSurface(gfxContentType aType, const gfxIntSize& aSize); |
|
55 virtual void Finish() MOZ_OVERRIDE; |
|
56 |
|
57 virtual const gfxIntSize GetSize() const; |
|
58 |
|
59 Display* XDisplay() { return mDisplay; } |
|
60 Screen* XScreen(); |
|
61 Drawable XDrawable() { return mDrawable; } |
|
62 XRenderPictFormat* XRenderFormat(); |
|
63 |
|
64 static int DepthOfVisual(const Screen* screen, const Visual* visual); |
|
65 static Visual* FindVisual(Screen* screen, gfxImageFormat format); |
|
66 static XRenderPictFormat *FindRenderFormat(Display *dpy, gfxImageFormat format); |
|
67 static bool GetColormapAndVisual(cairo_surface_t* aXlibSurface, Colormap* colormap, Visual **visual); |
|
68 |
|
69 // take ownership of a passed-in Pixmap, calling XFreePixmap on it |
|
70 // when the gfxXlibSurface is destroyed. |
|
71 void TakePixmap(); |
|
72 |
|
73 // Release ownership of this surface's Pixmap. This is only valid |
|
74 // on gfxXlibSurfaces for which the user called TakePixmap(), or |
|
75 // on those created by a Create() factory method. |
|
76 Drawable ReleasePixmap(); |
|
77 |
|
78 // Find a visual and colormap pair suitable for rendering to this surface. |
|
79 bool GetColormapAndVisual(Colormap* colormap, Visual **visual); |
|
80 |
|
81 // This surface is a wrapper around X pixmaps, which are stored in the X |
|
82 // server, not the main application. |
|
83 virtual gfxMemoryLocation GetMemoryLocation() const; |
|
84 |
|
85 #if defined(GL_PROVIDER_GLX) |
|
86 GLXPixmap GetGLXPixmap(); |
|
87 #endif |
|
88 |
|
89 // Return true if cairo will take its slow path when this surface is used |
|
90 // in a pattern with EXTEND_PAD. As a workaround for XRender's RepeatPad |
|
91 // not being implemented correctly on old X servers, cairo avoids XRender |
|
92 // and instead reads back to perform EXTEND_PAD with pixman. Cairo does |
|
93 // this for servers older than xorg-server 1.7. |
|
94 bool IsPadSlow() { |
|
95 // The test here matches that for buggy_pad_reflect in |
|
96 // _cairo_xlib_device_create. |
|
97 return VendorRelease(mDisplay) >= 60700000 || |
|
98 VendorRelease(mDisplay) < 10699000; |
|
99 } |
|
100 |
|
101 protected: |
|
102 // if TakePixmap() has been called on this |
|
103 bool mPixmapTaken; |
|
104 |
|
105 Display *mDisplay; |
|
106 Drawable mDrawable; |
|
107 |
|
108 const gfxIntSize DoSizeQuery(); |
|
109 |
|
110 #if defined(GL_PROVIDER_GLX) |
|
111 GLXPixmap mGLXPixmap; |
|
112 #endif |
|
113 }; |
|
114 |
|
115 #endif /* GFX_XLIBSURFACE_H */ |