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

mercurial