Tue, 06 Jan 2015 21:39:09 +0100
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_DRAWTARGETDUAL_H_ |
michael@0 | 7 | #define MOZILLA_GFX_DRAWTARGETDUAL_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include <vector> |
michael@0 | 10 | #include <sstream> |
michael@0 | 11 | |
michael@0 | 12 | #include "SourceSurfaceDual.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "2D.h" |
michael@0 | 15 | #include "Filters.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace gfx { |
michael@0 | 19 | |
michael@0 | 20 | #define FORWARD_FUNCTION(funcName) \ |
michael@0 | 21 | virtual void funcName() { mA->funcName(); mB->funcName(); } |
michael@0 | 22 | #define FORWARD_FUNCTION1(funcName, var1Type, var1Name) \ |
michael@0 | 23 | virtual void funcName(var1Type var1Name) { mA->funcName(var1Name); mB->funcName(var1Name); } |
michael@0 | 24 | |
michael@0 | 25 | /* This is a special type of DrawTarget. It duplicates all drawing calls |
michael@0 | 26 | * accross two drawtargets. An exception to this is when a snapshot of another |
michael@0 | 27 | * dual DrawTarget is used as the source for any surface data. In this case |
michael@0 | 28 | * the snapshot of the first source DrawTarget is used as a source for the call |
michael@0 | 29 | * to the first destination DrawTarget (mA) and the snapshot of the second |
michael@0 | 30 | * source DrawTarget is used at the source for the second destination |
michael@0 | 31 | * DrawTarget (mB). This class facilitates black-background/white-background |
michael@0 | 32 | * drawing for per-component alpha extraction for backends which do not support |
michael@0 | 33 | * native component alpha. |
michael@0 | 34 | */ |
michael@0 | 35 | class DrawTargetDual : public DrawTarget |
michael@0 | 36 | { |
michael@0 | 37 | public: |
michael@0 | 38 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetDual) |
michael@0 | 39 | DrawTargetDual(DrawTarget *aA, DrawTarget *aB) |
michael@0 | 40 | : mA(aA) |
michael@0 | 41 | , mB(aB) |
michael@0 | 42 | { |
michael@0 | 43 | mFormat = aA->GetFormat(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | virtual BackendType GetType() const { return mA->GetType(); } |
michael@0 | 47 | virtual TemporaryRef<SourceSurface> Snapshot() { return new SourceSurfaceDual(mA, mB); } |
michael@0 | 48 | virtual IntSize GetSize() { return mA->GetSize(); } |
michael@0 | 49 | |
michael@0 | 50 | FORWARD_FUNCTION(Flush) |
michael@0 | 51 | FORWARD_FUNCTION1(PushClip, const Path *, aPath) |
michael@0 | 52 | FORWARD_FUNCTION1(PushClipRect, const Rect &, aRect) |
michael@0 | 53 | FORWARD_FUNCTION(PopClip) |
michael@0 | 54 | FORWARD_FUNCTION1(ClearRect, const Rect &, aRect) |
michael@0 | 55 | |
michael@0 | 56 | virtual void SetTransform(const Matrix &aTransform) { |
michael@0 | 57 | mTransform = aTransform; |
michael@0 | 58 | mA->SetTransform(aTransform); |
michael@0 | 59 | mB->SetTransform(aTransform); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | virtual void DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect & aSource, |
michael@0 | 63 | const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions); |
michael@0 | 64 | |
michael@0 | 65 | virtual void DrawFilter(FilterNode *aNode, |
michael@0 | 66 | const Rect &aSourceRect, |
michael@0 | 67 | const Point &aDestPoint, |
michael@0 | 68 | const DrawOptions &aOptions = DrawOptions()) |
michael@0 | 69 | { |
michael@0 | 70 | mA->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions); |
michael@0 | 71 | mB->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | virtual void MaskSurface(const Pattern &aSource, |
michael@0 | 75 | SourceSurface *aMask, |
michael@0 | 76 | Point aOffset, |
michael@0 | 77 | const DrawOptions &aOptions = DrawOptions()); |
michael@0 | 78 | |
michael@0 | 79 | virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest, |
michael@0 | 80 | const Color &aColor, const Point &aOffset, |
michael@0 | 81 | Float aSigma, CompositionOp aOp); |
michael@0 | 82 | |
michael@0 | 83 | virtual void CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect, |
michael@0 | 84 | const IntPoint &aDestination); |
michael@0 | 85 | |
michael@0 | 86 | virtual void FillRect(const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions); |
michael@0 | 87 | |
michael@0 | 88 | virtual void StrokeRect(const Rect &aRect, const Pattern &aPattern, |
michael@0 | 89 | const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions); |
michael@0 | 90 | |
michael@0 | 91 | virtual void StrokeLine(const Point &aStart, const Point &aEnd, const Pattern &aPattern, |
michael@0 | 92 | const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions); |
michael@0 | 93 | |
michael@0 | 94 | virtual void Stroke(const Path *aPath, const Pattern &aPattern, |
michael@0 | 95 | const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions); |
michael@0 | 96 | |
michael@0 | 97 | virtual void Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aOptions); |
michael@0 | 98 | |
michael@0 | 99 | virtual void FillGlyphs(ScaledFont *aScaledFont, const GlyphBuffer &aBuffer, |
michael@0 | 100 | const Pattern &aPattern, const DrawOptions &aOptions, |
michael@0 | 101 | const GlyphRenderingOptions *aRenderingOptions); |
michael@0 | 102 | |
michael@0 | 103 | virtual void Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions); |
michael@0 | 104 | |
michael@0 | 105 | virtual TemporaryRef<SourceSurface> |
michael@0 | 106 | CreateSourceSurfaceFromData(unsigned char *aData, |
michael@0 | 107 | const IntSize &aSize, |
michael@0 | 108 | int32_t aStride, |
michael@0 | 109 | SurfaceFormat aFormat) const |
michael@0 | 110 | { |
michael@0 | 111 | return mA->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const |
michael@0 | 115 | { |
michael@0 | 116 | return mA->OptimizeSourceSurface(aSurface); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | virtual TemporaryRef<SourceSurface> |
michael@0 | 120 | CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const |
michael@0 | 121 | { |
michael@0 | 122 | return mA->CreateSourceSurfaceFromNativeSurface(aSurface); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | virtual TemporaryRef<DrawTarget> |
michael@0 | 126 | CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const; |
michael@0 | 127 | |
michael@0 | 128 | virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const |
michael@0 | 129 | { |
michael@0 | 130 | return mA->CreatePathBuilder(aFillRule); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | virtual TemporaryRef<GradientStops> |
michael@0 | 134 | CreateGradientStops(GradientStop *aStops, |
michael@0 | 135 | uint32_t aNumStops, |
michael@0 | 136 | ExtendMode aExtendMode = ExtendMode::CLAMP) const |
michael@0 | 137 | { |
michael@0 | 138 | return mA->CreateGradientStops(aStops, aNumStops, aExtendMode); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType) |
michael@0 | 142 | { |
michael@0 | 143 | return mA->CreateFilter(aType); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | virtual void *GetNativeSurface(NativeSurfaceType aType) |
michael@0 | 147 | { |
michael@0 | 148 | return nullptr; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | virtual bool IsDualDrawTarget() |
michael@0 | 152 | { |
michael@0 | 153 | return true; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | private: |
michael@0 | 157 | RefPtr<DrawTarget> mA; |
michael@0 | 158 | RefPtr<DrawTarget> mB; |
michael@0 | 159 | }; |
michael@0 | 160 | |
michael@0 | 161 | } |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | #endif /* MOZILLA_GFX_DRAWTARGETDUAL_H_ */ |