1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxXlibSurface.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef GFX_XLIBSURFACE_H 1.10 +#define GFX_XLIBSURFACE_H 1.11 + 1.12 +#include "gfxASurface.h" 1.13 + 1.14 +#include <X11/extensions/Xrender.h> 1.15 +#include <X11/Xlib.h> 1.16 + 1.17 +#if defined(GL_PROVIDER_GLX) 1.18 +#include "GLXLibrary.h" 1.19 +#endif 1.20 + 1.21 +#include "nsSize.h" 1.22 + 1.23 +class gfxXlibSurface : public gfxASurface { 1.24 +public: 1.25 + // construct a wrapper around the specified drawable with dpy/visual. 1.26 + // Will use XGetGeometry to query the window/pixmap size. 1.27 + gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual); 1.28 + 1.29 + // construct a wrapper around the specified drawable with dpy/visual, 1.30 + // and known width/height. 1.31 + gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfxIntSize& size); 1.32 + 1.33 + // construct a wrapper around the specified drawable with dpy/format, 1.34 + // and known width/height. 1.35 + gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format, 1.36 + const gfxIntSize& size); 1.37 + 1.38 + gfxXlibSurface(cairo_surface_t *csurf); 1.39 + 1.40 + // create a new Pixmap and wrapper surface. 1.41 + // |relatedDrawable| provides a hint to the server for determining whether 1.42 + // the pixmap should be in video or system memory. It must be on 1.43 + // |screen| (if specified). 1.44 + static already_AddRefed<gfxXlibSurface> 1.45 + Create(Screen *screen, Visual *visual, const gfxIntSize& size, 1.46 + Drawable relatedDrawable = None); 1.47 + static cairo_surface_t * 1.48 + CreateCairoSurface(Screen *screen, Visual *visual, const gfxIntSize& size, 1.49 + Drawable relatedDrawable = None); 1.50 + static already_AddRefed<gfxXlibSurface> 1.51 + Create(Screen* screen, XRenderPictFormat *format, const gfxIntSize& size, 1.52 + Drawable relatedDrawable = None); 1.53 + 1.54 + virtual ~gfxXlibSurface(); 1.55 + 1.56 + virtual already_AddRefed<gfxASurface> 1.57 + CreateSimilarSurface(gfxContentType aType, const gfxIntSize& aSize); 1.58 + virtual void Finish() MOZ_OVERRIDE; 1.59 + 1.60 + virtual const gfxIntSize GetSize() const; 1.61 + 1.62 + Display* XDisplay() { return mDisplay; } 1.63 + Screen* XScreen(); 1.64 + Drawable XDrawable() { return mDrawable; } 1.65 + XRenderPictFormat* XRenderFormat(); 1.66 + 1.67 + static int DepthOfVisual(const Screen* screen, const Visual* visual); 1.68 + static Visual* FindVisual(Screen* screen, gfxImageFormat format); 1.69 + static XRenderPictFormat *FindRenderFormat(Display *dpy, gfxImageFormat format); 1.70 + static bool GetColormapAndVisual(cairo_surface_t* aXlibSurface, Colormap* colormap, Visual **visual); 1.71 + 1.72 + // take ownership of a passed-in Pixmap, calling XFreePixmap on it 1.73 + // when the gfxXlibSurface is destroyed. 1.74 + void TakePixmap(); 1.75 + 1.76 + // Release ownership of this surface's Pixmap. This is only valid 1.77 + // on gfxXlibSurfaces for which the user called TakePixmap(), or 1.78 + // on those created by a Create() factory method. 1.79 + Drawable ReleasePixmap(); 1.80 + 1.81 + // Find a visual and colormap pair suitable for rendering to this surface. 1.82 + bool GetColormapAndVisual(Colormap* colormap, Visual **visual); 1.83 + 1.84 + // This surface is a wrapper around X pixmaps, which are stored in the X 1.85 + // server, not the main application. 1.86 + virtual gfxMemoryLocation GetMemoryLocation() const; 1.87 + 1.88 +#if defined(GL_PROVIDER_GLX) 1.89 + GLXPixmap GetGLXPixmap(); 1.90 +#endif 1.91 + 1.92 + // Return true if cairo will take its slow path when this surface is used 1.93 + // in a pattern with EXTEND_PAD. As a workaround for XRender's RepeatPad 1.94 + // not being implemented correctly on old X servers, cairo avoids XRender 1.95 + // and instead reads back to perform EXTEND_PAD with pixman. Cairo does 1.96 + // this for servers older than xorg-server 1.7. 1.97 + bool IsPadSlow() { 1.98 + // The test here matches that for buggy_pad_reflect in 1.99 + // _cairo_xlib_device_create. 1.100 + return VendorRelease(mDisplay) >= 60700000 || 1.101 + VendorRelease(mDisplay) < 10699000; 1.102 + } 1.103 + 1.104 +protected: 1.105 + // if TakePixmap() has been called on this 1.106 + bool mPixmapTaken; 1.107 + 1.108 + Display *mDisplay; 1.109 + Drawable mDrawable; 1.110 + 1.111 + const gfxIntSize DoSizeQuery(); 1.112 + 1.113 +#if defined(GL_PROVIDER_GLX) 1.114 + GLXPixmap mGLXPixmap; 1.115 +#endif 1.116 +}; 1.117 + 1.118 +#endif /* GFX_XLIBSURFACE_H */