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