1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Oracle Corporation code.
16 : *
17 : * The Initial Developer of the Original Code is Oracle Corporation.
18 : * Portions created by the Initial Developer are Copyright (C) 2005
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Stuart Parmenter <pavlov@pavlov.net>
23 : * Vladimir Vukicevic <vladimir@pobox.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef GFX_XLIBSURFACE_H
40 : #define GFX_XLIBSURFACE_H
41 :
42 : #include "gfxASurface.h"
43 :
44 : #include <X11/extensions/Xrender.h>
45 : #include <X11/Xlib.h>
46 :
47 : #if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
48 : #include "GLXLibrary.h"
49 : #endif
50 :
51 : class THEBES_API gfxXlibSurface : public gfxASurface {
52 : public:
53 : // construct a wrapper around the specified drawable with dpy/visual.
54 : // Will use XGetGeometry to query the window/pixmap size.
55 : gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual);
56 :
57 : // construct a wrapper around the specified drawable with dpy/visual,
58 : // and known width/height.
59 : gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfxIntSize& size);
60 :
61 : // construct a wrapper around the specified drawable with dpy/format,
62 : // and known width/height.
63 : gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format,
64 : const gfxIntSize& size);
65 :
66 : gfxXlibSurface(cairo_surface_t *csurf);
67 :
68 : // create a new Pixmap and wrapper surface.
69 : // |relatedDrawable| provides a hint to the server for determining whether
70 : // the pixmap should be in video or system memory. It must be on
71 : // |screen| (if specified).
72 : static already_AddRefed<gfxXlibSurface>
73 : Create(Screen *screen, Visual *visual, const gfxIntSize& size,
74 : Drawable relatedDrawable = None);
75 : static already_AddRefed<gfxXlibSurface>
76 : Create(Screen* screen, XRenderPictFormat *format, const gfxIntSize& size,
77 : Drawable relatedDrawable = None);
78 :
79 : virtual ~gfxXlibSurface();
80 :
81 : virtual already_AddRefed<gfxASurface>
82 : CreateSimilarSurface(gfxContentType aType, const gfxIntSize& aSize);
83 :
84 : virtual const gfxIntSize GetSize() const { return mSize; }
85 :
86 : Display* XDisplay() { return mDisplay; }
87 : Screen* XScreen();
88 0 : Drawable XDrawable() { return mDrawable; }
89 : XRenderPictFormat* XRenderFormat();
90 :
91 : static int DepthOfVisual(const Screen* screen, const Visual* visual);
92 : static Visual* FindVisual(Screen* screen, gfxImageFormat format);
93 : static XRenderPictFormat *FindRenderFormat(Display *dpy, gfxImageFormat format);
94 :
95 : // take ownership of a passed-in Pixmap, calling XFreePixmap on it
96 : // when the gfxXlibSurface is destroyed.
97 : void TakePixmap();
98 :
99 : // Release ownership of this surface's Pixmap. This is only valid
100 : // on gfxXlibSurfaces for which the user called TakePixmap(), or
101 : // on those created by a Create() factory method.
102 : Drawable ReleasePixmap();
103 :
104 : // Find a visual and colormap pair suitable for rendering to this surface.
105 : bool GetColormapAndVisual(Colormap* colormap, Visual **visual);
106 :
107 : // This surface is a wrapper around X pixmaps, which are stored in the X
108 : // server, not the main application.
109 : virtual gfxASurface::MemoryLocation GetMemoryLocation() const;
110 :
111 : #if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
112 : GLXPixmap GetGLXPixmap();
113 : #endif
114 :
115 : protected:
116 : // if TakePixmap() has been called on this
117 : bool mPixmapTaken;
118 :
119 : Display *mDisplay;
120 : Drawable mDrawable;
121 :
122 : void DoSizeQuery();
123 :
124 : gfxIntSize mSize;
125 :
126 : #if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
127 : GLXPixmap mGLXPixmap;
128 : #endif
129 : };
130 :
131 : #endif /* GFX_XLIBSURFACE_H */
|