gfx/thebes/gfxXlibSurface.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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/. */
     6 #ifndef GFX_XLIBSURFACE_H
     7 #define GFX_XLIBSURFACE_H
     9 #include "gfxASurface.h"
    11 #include <X11/extensions/Xrender.h>
    12 #include <X11/Xlib.h>
    14 #if defined(GL_PROVIDER_GLX)
    15 #include "GLXLibrary.h"
    16 #endif
    18 #include "nsSize.h"
    20 class gfxXlibSurface : public gfxASurface {
    21 public:
    22     // construct a wrapper around the specified drawable with dpy/visual.
    23     // Will use XGetGeometry to query the window/pixmap size.
    24     gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual);
    26     // construct a wrapper around the specified drawable with dpy/visual,
    27     // and known width/height.
    28     gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfxIntSize& size);
    30     // construct a wrapper around the specified drawable with dpy/format,
    31     // and known width/height.
    32     gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format,
    33                    const gfxIntSize& size);
    35     gfxXlibSurface(cairo_surface_t *csurf);
    37     // create a new Pixmap and wrapper surface.
    38     // |relatedDrawable| provides a hint to the server for determining whether
    39     // the pixmap should be in video or system memory.  It must be on
    40     // |screen| (if specified).
    41     static already_AddRefed<gfxXlibSurface>
    42     Create(Screen *screen, Visual *visual, const gfxIntSize& size,
    43            Drawable relatedDrawable = None);
    44     static cairo_surface_t *
    45     CreateCairoSurface(Screen *screen, Visual *visual, const gfxIntSize& size,
    46                        Drawable relatedDrawable = None);
    47     static already_AddRefed<gfxXlibSurface>
    48     Create(Screen* screen, XRenderPictFormat *format, const gfxIntSize& size,
    49            Drawable relatedDrawable = None);
    51     virtual ~gfxXlibSurface();
    53     virtual already_AddRefed<gfxASurface>
    54     CreateSimilarSurface(gfxContentType aType, const gfxIntSize& aSize);
    55     virtual void Finish() MOZ_OVERRIDE;
    57     virtual const gfxIntSize GetSize() const;
    59     Display* XDisplay() { return mDisplay; }
    60     Screen* XScreen();
    61     Drawable XDrawable() { return mDrawable; }
    62     XRenderPictFormat* XRenderFormat();
    64     static int DepthOfVisual(const Screen* screen, const Visual* visual);
    65     static Visual* FindVisual(Screen* screen, gfxImageFormat format);
    66     static XRenderPictFormat *FindRenderFormat(Display *dpy, gfxImageFormat format);
    67     static bool GetColormapAndVisual(cairo_surface_t* aXlibSurface, Colormap* colormap, Visual **visual);
    69     // take ownership of a passed-in Pixmap, calling XFreePixmap on it
    70     // when the gfxXlibSurface is destroyed.
    71     void TakePixmap();
    73     // Release ownership of this surface's Pixmap.  This is only valid
    74     // on gfxXlibSurfaces for which the user called TakePixmap(), or
    75     // on those created by a Create() factory method.
    76     Drawable ReleasePixmap();
    78     // Find a visual and colormap pair suitable for rendering to this surface.
    79     bool GetColormapAndVisual(Colormap* colormap, Visual **visual);
    81     // This surface is a wrapper around X pixmaps, which are stored in the X
    82     // server, not the main application.
    83     virtual gfxMemoryLocation GetMemoryLocation() const;
    85 #if defined(GL_PROVIDER_GLX)
    86     GLXPixmap GetGLXPixmap();
    87 #endif
    89     // Return true if cairo will take its slow path when this surface is used
    90     // in a pattern with EXTEND_PAD.  As a workaround for XRender's RepeatPad
    91     // not being implemented correctly on old X servers, cairo avoids XRender
    92     // and instead reads back to perform EXTEND_PAD with pixman.  Cairo does
    93     // this for servers older than xorg-server 1.7.
    94     bool IsPadSlow() {
    95         // The test here matches that for buggy_pad_reflect in
    96         // _cairo_xlib_device_create.
    97         return VendorRelease(mDisplay) >= 60700000 ||
    98             VendorRelease(mDisplay) < 10699000;
    99     }
   101 protected:
   102     // if TakePixmap() has been called on this
   103     bool mPixmapTaken;
   105     Display *mDisplay;
   106     Drawable mDrawable;
   108     const gfxIntSize DoSizeQuery();
   110 #if defined(GL_PROVIDER_GLX)
   111     GLXPixmap mGLXPixmap;
   112 #endif
   113 };
   115 #endif /* GFX_XLIBSURFACE_H */

mercurial