gfx/2d/DrawTargetCairo.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.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 _MOZILLA_GFX_DRAWTARGET_CAIRO_H_
michael@0 7 #define _MOZILLA_GFX_DRAWTARGET_CAIRO_H_
michael@0 8
michael@0 9 #include "2D.h"
michael@0 10 #include "cairo.h"
michael@0 11 #include "PathCairo.h"
michael@0 12
michael@0 13 #include <vector>
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace gfx {
michael@0 17
michael@0 18 class SourceSurfaceCairo;
michael@0 19
michael@0 20 class GradientStopsCairo : public GradientStops
michael@0 21 {
michael@0 22 public:
michael@0 23 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GradientStopsCairo)
michael@0 24 GradientStopsCairo(GradientStop* aStops, uint32_t aNumStops,
michael@0 25 ExtendMode aExtendMode)
michael@0 26 : mExtendMode(aExtendMode)
michael@0 27 {
michael@0 28 for (uint32_t i = 0; i < aNumStops; ++i) {
michael@0 29 mStops.push_back(aStops[i]);
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 virtual ~GradientStopsCairo() {}
michael@0 34
michael@0 35 const std::vector<GradientStop>& GetStops() const
michael@0 36 {
michael@0 37 return mStops;
michael@0 38 }
michael@0 39
michael@0 40 ExtendMode GetExtendMode() const
michael@0 41 {
michael@0 42 return mExtendMode;
michael@0 43 }
michael@0 44
michael@0 45 virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
michael@0 46
michael@0 47 private:
michael@0 48 std::vector<GradientStop> mStops;
michael@0 49 ExtendMode mExtendMode;
michael@0 50 };
michael@0 51
michael@0 52 class DrawTargetCairo : public DrawTarget
michael@0 53 {
michael@0 54 public:
michael@0 55 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetCairo)
michael@0 56 friend class BorrowedCairoContext;
michael@0 57
michael@0 58 DrawTargetCairo();
michael@0 59 virtual ~DrawTargetCairo();
michael@0 60
michael@0 61 virtual BackendType GetType() const { return BackendType::CAIRO; }
michael@0 62 virtual TemporaryRef<SourceSurface> Snapshot();
michael@0 63 virtual IntSize GetSize();
michael@0 64
michael@0 65 virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA);
michael@0 66
michael@0 67 virtual bool LockBits(uint8_t** aData, IntSize* aSize,
michael@0 68 int32_t* aStride, SurfaceFormat* aFormat);
michael@0 69 virtual void ReleaseBits(uint8_t* aData);
michael@0 70
michael@0 71 virtual void Flush();
michael@0 72 virtual void DrawSurface(SourceSurface *aSurface,
michael@0 73 const Rect &aDest,
michael@0 74 const Rect &aSource,
michael@0 75 const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
michael@0 76 const DrawOptions &aOptions = DrawOptions());
michael@0 77 virtual void DrawFilter(FilterNode *aNode,
michael@0 78 const Rect &aSourceRect,
michael@0 79 const Point &aDestPoint,
michael@0 80 const DrawOptions &aOptions = DrawOptions());
michael@0 81 virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
michael@0 82 const Point &aDest,
michael@0 83 const Color &aColor,
michael@0 84 const Point &aOffset,
michael@0 85 Float aSigma,
michael@0 86 CompositionOp aOperator);
michael@0 87
michael@0 88 virtual void ClearRect(const Rect &aRect);
michael@0 89
michael@0 90 virtual void CopySurface(SourceSurface *aSurface,
michael@0 91 const IntRect &aSourceRect,
michael@0 92 const IntPoint &aDestination);
michael@0 93 virtual void CopyRect(const IntRect &aSourceRect,
michael@0 94 const IntPoint &aDestination);
michael@0 95
michael@0 96 virtual void FillRect(const Rect &aRect,
michael@0 97 const Pattern &aPattern,
michael@0 98 const DrawOptions &aOptions = DrawOptions());
michael@0 99 virtual void StrokeRect(const Rect &aRect,
michael@0 100 const Pattern &aPattern,
michael@0 101 const StrokeOptions &aStrokeOptions = StrokeOptions(),
michael@0 102 const DrawOptions &aOptions = DrawOptions());
michael@0 103 virtual void StrokeLine(const Point &aStart,
michael@0 104 const Point &aEnd,
michael@0 105 const Pattern &aPattern,
michael@0 106 const StrokeOptions &aStrokeOptions = StrokeOptions(),
michael@0 107 const DrawOptions &aOptions = DrawOptions());
michael@0 108
michael@0 109 virtual void Stroke(const Path *aPath,
michael@0 110 const Pattern &aPattern,
michael@0 111 const StrokeOptions &aStrokeOptions = StrokeOptions(),
michael@0 112 const DrawOptions &aOptions = DrawOptions());
michael@0 113
michael@0 114 virtual void Fill(const Path *aPath,
michael@0 115 const Pattern &aPattern,
michael@0 116 const DrawOptions &aOptions = DrawOptions());
michael@0 117
michael@0 118 virtual void FillGlyphs(ScaledFont *aFont,
michael@0 119 const GlyphBuffer &aBuffer,
michael@0 120 const Pattern &aPattern,
michael@0 121 const DrawOptions &aOptions,
michael@0 122 const GlyphRenderingOptions *aRenderingOptions = nullptr);
michael@0 123 virtual void Mask(const Pattern &aSource,
michael@0 124 const Pattern &aMask,
michael@0 125 const DrawOptions &aOptions = DrawOptions());
michael@0 126 virtual void MaskSurface(const Pattern &aSource,
michael@0 127 SourceSurface *aMask,
michael@0 128 Point aOffset,
michael@0 129 const DrawOptions &aOptions = DrawOptions());
michael@0 130
michael@0 131 virtual void PushClip(const Path *aPath);
michael@0 132 virtual void PushClipRect(const Rect &aRect);
michael@0 133 virtual void PopClip();
michael@0 134
michael@0 135 virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
michael@0 136
michael@0 137 virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
michael@0 138 const IntSize &aSize,
michael@0 139 int32_t aStride,
michael@0 140 SurfaceFormat aFormat) const;
michael@0 141 virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const;
michael@0 142 virtual TemporaryRef<SourceSurface>
michael@0 143 CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const;
michael@0 144 virtual TemporaryRef<DrawTarget>
michael@0 145 CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
michael@0 146 virtual TemporaryRef<DrawTarget>
michael@0 147 CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat,
michael@0 148 float aSigma) const;
michael@0 149
michael@0 150 virtual TemporaryRef<GradientStops>
michael@0 151 CreateGradientStops(GradientStop *aStops,
michael@0 152 uint32_t aNumStops,
michael@0 153 ExtendMode aExtendMode = ExtendMode::CLAMP) const;
michael@0 154
michael@0 155 virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType);
michael@0 156
michael@0 157 virtual void *GetNativeSurface(NativeSurfaceType aType);
michael@0 158
michael@0 159 bool Init(cairo_surface_t* aSurface, const IntSize& aSize, SurfaceFormat* aFormat = nullptr);
michael@0 160 bool Init(const IntSize& aSize, SurfaceFormat aFormat);
michael@0 161 bool Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
michael@0 162
michael@0 163 virtual void SetTransform(const Matrix& aTransform);
michael@0 164
michael@0 165 // Call to set up aContext for drawing (with the current transform, etc).
michael@0 166 // Pass the path you're going to be using if you have one.
michael@0 167 // Implicitly calls WillChange(aPath).
michael@0 168 void PrepareForDrawing(cairo_t* aContext, const Path* aPath = nullptr);
michael@0 169
michael@0 170 static cairo_surface_t *GetDummySurface();
michael@0 171
michael@0 172 private: // methods
michael@0 173 // Init cairo surface without doing a cairo_surface_reference() call.
michael@0 174 bool InitAlreadyReferenced(cairo_surface_t* aSurface, const IntSize& aSize, SurfaceFormat* aFormat = nullptr);
michael@0 175 enum DrawPatternType { DRAW_FILL, DRAW_STROKE };
michael@0 176 void DrawPattern(const Pattern& aPattern,
michael@0 177 const StrokeOptions& aStrokeOptions,
michael@0 178 const DrawOptions& aOptions,
michael@0 179 DrawPatternType aDrawType,
michael@0 180 bool aPathBoundsClip = false);
michael@0 181
michael@0 182 void CopySurfaceInternal(cairo_surface_t* aSurface,
michael@0 183 const IntRect& aSource,
michael@0 184 const IntPoint& aDest);
michael@0 185
michael@0 186 Rect GetUserSpaceClip();
michael@0 187
michael@0 188 // Call before you make any changes to the backing surface with which this
michael@0 189 // context is associated. Pass the path you're going to be using if you have
michael@0 190 // one.
michael@0 191 void WillChange(const Path* aPath = nullptr);
michael@0 192
michael@0 193 // Call if there is any reason to disassociate the snapshot from this draw
michael@0 194 // target; for example, because we're going to be destroyed.
michael@0 195 void MarkSnapshotIndependent();
michael@0 196
michael@0 197 // If the current operator is "source" then clear the destination before we
michael@0 198 // draw into it, to simulate the effect of an unbounded source operator.
michael@0 199 void ClearSurfaceForUnboundedSource(const CompositionOp &aOperator);
michael@0 200 private: // data
michael@0 201 cairo_t* mContext;
michael@0 202 cairo_surface_t* mSurface;
michael@0 203 IntSize mSize;
michael@0 204
michael@0 205 uint8_t* mLockedBits;
michael@0 206
michael@0 207 // The latest snapshot of this surface. This needs to be told when this
michael@0 208 // target is modified. We keep it alive as a cache.
michael@0 209 RefPtr<SourceSurfaceCairo> mSnapshot;
michael@0 210 static cairo_surface_t *mDummySurface;
michael@0 211 };
michael@0 212
michael@0 213 }
michael@0 214 }
michael@0 215
michael@0 216 #endif // _MOZILLA_GFX_DRAWTARGET_CAIRO_H_

mercurial