gfxXlibSurface.h (4089B)
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 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/Xlib.h> 12 #include "X11UndefineNone.h" 13 14 #include "GLXLibrary.h" 15 #include "mozilla/gfx/XlibDisplay.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 #define XLIB_IMAGE_SIDE_SIZE_LIMIT 0x7fff 23 24 class gfxXlibSurface final : public gfxASurface { 25 public: 26 // construct a wrapper around the specified drawable with dpy/visual. 27 // Will use XGetGeometry to query the window/pixmap size. 28 gfxXlibSurface(Display* dpy, Drawable drawable, Visual* visual); 29 30 // construct a wrapper around the specified drawable with dpy/visual, 31 // and known width/height. 32 gfxXlibSurface(Display* dpy, Drawable drawable, Visual* visual, 33 const mozilla::gfx::IntSize& size); 34 gfxXlibSurface(const std::shared_ptr<mozilla::gfx::XlibDisplay>& dpy, 35 Drawable drawable, Visual* visual, 36 const mozilla::gfx::IntSize& size); 37 38 explicit gfxXlibSurface(cairo_surface_t* csurf); 39 40 // create a new Pixmap and wrapper surface. 41 // |relatedDrawable| provides a hint to the server for determining whether 42 // the pixmap should be in video or system memory. It must be on 43 // |screen| (if specified). 44 static already_AddRefed<gfxXlibSurface> Create( 45 ::Screen* screen, Visual* visual, const mozilla::gfx::IntSize& size, 46 Drawable relatedDrawable = X11None); 47 static already_AddRefed<gfxXlibSurface> Create( 48 const std::shared_ptr<mozilla::gfx::XlibDisplay>& display, 49 ::Screen* screen, Visual* visual, const mozilla::gfx::IntSize& size, 50 Drawable relatedDrawable = X11None); 51 static cairo_surface_t* CreateCairoSurface( 52 ::Screen* screen, Visual* visual, const mozilla::gfx::IntSize& size, 53 Drawable relatedDrawable = X11None); 54 55 virtual ~gfxXlibSurface(); 56 57 void Finish() override; 58 59 const mozilla::gfx::IntSize GetSize() const override; 60 61 Display* XDisplay() { return *mDisplay; } 62 ::Screen* XScreen(); 63 Drawable XDrawable() { return mDrawable; } 64 65 static int DepthOfVisual(const ::Screen* screen, const Visual* visual); 66 static Visual* FindVisual(::Screen* screen, gfxImageFormat format); 67 static bool GetColormapAndVisual(cairo_surface_t* aXlibSurface, 68 Colormap* colormap, Visual** visual); 69 70 // take ownership of a passed-in Pixmap, calling XFreePixmap on it 71 // when the gfxXlibSurface is destroyed. 72 void TakePixmap(); 73 74 // Release ownership of this surface's Pixmap. This is only valid 75 // on gfxXlibSurfaces for which the user called TakePixmap(), or 76 // on those created by a Create() factory method. 77 Drawable ReleasePixmap(); 78 79 // Find a visual and colormap pair suitable for rendering to this surface. 80 bool GetColormapAndVisual(Colormap* colormap, Visual** visual); 81 82 // Return true if cairo will take its slow path when this surface is used 83 // in a pattern with EXTEND_PAD. As a workaround for XRender's RepeatPad 84 // not being implemented correctly on old X servers, cairo avoids XRender 85 // and instead reads back to perform EXTEND_PAD with pixman. Cairo does 86 // this for servers older than xorg-server 1.7. 87 bool IsPadSlow() { 88 // The test here matches that for buggy_pad_reflect in 89 // _cairo_xlib_device_create. 90 return VendorRelease(mDisplay->get()) >= 60700000 || 91 VendorRelease(mDisplay->get()) < 10699000; 92 } 93 94 protected: 95 // if TakePixmap() has been called on this 96 bool mPixmapTaken; 97 98 std::shared_ptr<mozilla::gfx::XlibDisplay> mDisplay; 99 Drawable mDrawable; 100 101 const mozilla::gfx::IntSize DoSizeQuery(); 102 }; 103 104 #endif /* GFX_XLIBSURFACE_H */