/work/obj-fuzz/dist/include/gfxXlibSurface.h
Line | Count | Source (jump to first uncovered line) |
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 | | #include "X11UndefineNone.h" |
14 | | |
15 | | #include "GLXLibrary.h" |
16 | | |
17 | | #include "nsSize.h" |
18 | | |
19 | | // Although the dimension parameters in the xCreatePixmapReq wire protocol are |
20 | | // 16-bit unsigned integers, the server's CreatePixmap returns BadAlloc if |
21 | | // either dimension cannot be represented by a 16-bit *signed* integer. |
22 | 0 | #define XLIB_IMAGE_SIDE_SIZE_LIMIT 0x7fff |
23 | | |
24 | | |
25 | | class gfxXlibSurface final : public gfxASurface { |
26 | | public: |
27 | | // construct a wrapper around the specified drawable with dpy/visual. |
28 | | // Will use XGetGeometry to query the window/pixmap size. |
29 | | gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual); |
30 | | |
31 | | // construct a wrapper around the specified drawable with dpy/visual, |
32 | | // and known width/height. |
33 | | gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const mozilla::gfx::IntSize& size); |
34 | | |
35 | | // construct a wrapper around the specified drawable with dpy/format, |
36 | | // and known width/height. |
37 | | gfxXlibSurface(::Screen *screen, Drawable drawable, XRenderPictFormat *format, |
38 | | const mozilla::gfx::IntSize& size); |
39 | | |
40 | | explicit gfxXlibSurface(cairo_surface_t *csurf); |
41 | | |
42 | | // create a new Pixmap and wrapper surface. |
43 | | // |relatedDrawable| provides a hint to the server for determining whether |
44 | | // the pixmap should be in video or system memory. It must be on |
45 | | // |screen| (if specified). |
46 | | static already_AddRefed<gfxXlibSurface> |
47 | | Create(::Screen *screen, Visual *visual, const mozilla::gfx::IntSize& size, |
48 | | Drawable relatedDrawable = X11None); |
49 | | static cairo_surface_t * |
50 | | CreateCairoSurface(::Screen *screen, Visual *visual, const mozilla::gfx::IntSize& size, |
51 | | Drawable relatedDrawable = X11None); |
52 | | static already_AddRefed<gfxXlibSurface> |
53 | | Create(::Screen* screen, XRenderPictFormat *format, const mozilla::gfx::IntSize& size, |
54 | | Drawable relatedDrawable = X11None); |
55 | | |
56 | | virtual ~gfxXlibSurface(); |
57 | | |
58 | | virtual already_AddRefed<gfxASurface> |
59 | | CreateSimilarSurface(gfxContentType aType, |
60 | | const mozilla::gfx::IntSize& aSize) override; |
61 | | virtual void Finish() override; |
62 | | |
63 | | virtual const mozilla::gfx::IntSize GetSize() const override; |
64 | | |
65 | 0 | Display* XDisplay() { return mDisplay; } |
66 | | ::Screen* XScreen(); |
67 | 0 | Drawable XDrawable() { return mDrawable; } |
68 | | XRenderPictFormat* XRenderFormat(); |
69 | | |
70 | | static int DepthOfVisual(const ::Screen* screen, const Visual* visual); |
71 | | static Visual* FindVisual(::Screen* screen, gfxImageFormat format); |
72 | | static XRenderPictFormat *FindRenderFormat(Display *dpy, gfxImageFormat format); |
73 | | static bool GetColormapAndVisual(cairo_surface_t* aXlibSurface, Colormap* colormap, Visual **visual); |
74 | | |
75 | | // take ownership of a passed-in Pixmap, calling XFreePixmap on it |
76 | | // when the gfxXlibSurface is destroyed. |
77 | | void TakePixmap(); |
78 | | |
79 | | // Release ownership of this surface's Pixmap. This is only valid |
80 | | // on gfxXlibSurfaces for which the user called TakePixmap(), or |
81 | | // on those created by a Create() factory method. |
82 | | Drawable ReleasePixmap(); |
83 | | |
84 | | // Find a visual and colormap pair suitable for rendering to this surface. |
85 | | bool GetColormapAndVisual(Colormap* colormap, Visual **visual); |
86 | | |
87 | | GLXPixmap GetGLXPixmap(); |
88 | | // Binds a GLXPixmap backed by this context's surface. |
89 | | // Primarily for use in sharing surfaces. |
90 | | void BindGLXPixmap(GLXPixmap aPixmap); |
91 | | |
92 | | // Return true if cairo will take its slow path when this surface is used |
93 | | // in a pattern with EXTEND_PAD. As a workaround for XRender's RepeatPad |
94 | | // not being implemented correctly on old X servers, cairo avoids XRender |
95 | | // and instead reads back to perform EXTEND_PAD with pixman. Cairo does |
96 | | // this for servers older than xorg-server 1.7. |
97 | 0 | bool IsPadSlow() { |
98 | 0 | // The test here matches that for buggy_pad_reflect in |
99 | 0 | // _cairo_xlib_device_create. |
100 | 0 | return VendorRelease(mDisplay) >= 60700000 || |
101 | 0 | VendorRelease(mDisplay) < 10699000; |
102 | 0 | } |
103 | | |
104 | | protected: |
105 | | // if TakePixmap() has been called on this |
106 | | bool mPixmapTaken; |
107 | | |
108 | | Display *mDisplay; |
109 | | Drawable mDrawable; |
110 | | |
111 | | const mozilla::gfx::IntSize DoSizeQuery(); |
112 | | |
113 | | GLXPixmap mGLXPixmap; |
114 | | }; |
115 | | |
116 | | #endif /* GFX_XLIBSURFACE_H */ |