gfx/2d/DrawTargetDual.cpp

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 #include "DrawTargetDual.h"
     7 #include "Tools.h"
     9 namespace mozilla {
    10 namespace gfx {
    12 class DualSurface
    13 {
    14 public:
    15   inline DualSurface(SourceSurface *aSurface)
    16   {
    17     if (aSurface->GetType() != SurfaceType::DUAL_DT) {
    18       mA = mB = aSurface;
    19       return;
    20     }
    22     SourceSurfaceDual *ssDual =
    23       static_cast<SourceSurfaceDual*>(aSurface);
    24     mA = ssDual->mA;
    25     mB = ssDual->mB;
    26   }
    28   SourceSurface *mA;
    29   SourceSurface *mB;
    30 };
    32 /* This only needs to split patterns up for SurfacePatterns. Only in that
    33  * case can we be dealing with a 'dual' source (SourceSurfaceDual) and do
    34  * we need to pass separate patterns into our destination DrawTargets.
    35  */
    36 class DualPattern
    37 {
    38 public:
    39   inline DualPattern(const Pattern &aPattern)
    40     : mPatternsInitialized(false)
    41   {
    42     if (aPattern.GetType() != PatternType::SURFACE) {
    43       mA = mB = &aPattern;
    44       return;
    45     }
    47     const SurfacePattern *surfPat =
    48       static_cast<const SurfacePattern*>(&aPattern);
    50     if (surfPat->mSurface->GetType() != SurfaceType::DUAL_DT) {
    51       mA = mB = &aPattern;
    52       return;
    53     }
    55     const SourceSurfaceDual *ssDual =
    56       static_cast<const SourceSurfaceDual*>(surfPat->mSurface.get());
    57     mA = new (mSurfPatA.addr()) SurfacePattern(ssDual->mA, surfPat->mExtendMode,
    58                                                surfPat->mMatrix, surfPat->mFilter);
    59     mB = new (mSurfPatB.addr()) SurfacePattern(ssDual->mB, surfPat->mExtendMode,
    60                                                surfPat->mMatrix, surfPat->mFilter);
    61     mPatternsInitialized = true;
    62   }
    64   inline ~DualPattern()
    65   {
    66     if (mPatternsInitialized) {
    67       mA->~Pattern();
    68       mB->~Pattern();
    69     }
    70   }
    72   ClassStorage<SurfacePattern> mSurfPatA;
    73   ClassStorage<SurfacePattern> mSurfPatB;
    75   const Pattern *mA;
    76   const Pattern *mB;
    78   bool mPatternsInitialized;
    79 };
    81 void
    82 DrawTargetDual::DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect &aSource,
    83                             const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions)
    84 {
    85   DualSurface surface(aSurface);
    86   mA->DrawSurface(surface.mA, aDest, aSource, aSurfOptions, aOptions);
    87   mB->DrawSurface(surface.mB, aDest, aSource, aSurfOptions, aOptions);
    88 }
    90 void
    91 DrawTargetDual::DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest,
    92                                       const Color &aColor, const Point &aOffset,
    93                                       Float aSigma, CompositionOp aOp)
    94 {
    95   DualSurface surface(aSurface);
    96   mA->DrawSurfaceWithShadow(surface.mA, aDest, aColor, aOffset, aSigma, aOp);
    97   mB->DrawSurfaceWithShadow(surface.mB, aDest, aColor, aOffset, aSigma, aOp);
    98 }
   100 void
   101 DrawTargetDual::MaskSurface(const Pattern &aSource,
   102                            SourceSurface *aMask,
   103                            Point aOffset,
   104                            const DrawOptions &aOptions)
   105 {
   106   DualPattern source(aSource);
   107   DualSurface mask(aMask);
   108   mA->MaskSurface(*source.mA, mask.mA, aOffset, aOptions);
   109   mB->MaskSurface(*source.mB, mask.mB, aOffset, aOptions);
   110 }
   112 void
   113 DrawTargetDual::CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect,
   114                             const IntPoint &aDestination)
   115 {
   116   DualSurface surface(aSurface);
   117   mA->CopySurface(surface.mA, aSourceRect, aDestination);
   118   mB->CopySurface(surface.mB, aSourceRect, aDestination);
   119 }
   121 void
   122 DrawTargetDual::FillRect(const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions)
   123 {
   124   DualPattern pattern(aPattern);
   125   mA->FillRect(aRect, *pattern.mA, aOptions);
   126   mB->FillRect(aRect, *pattern.mB, aOptions);
   127 }
   129 void
   130 DrawTargetDual::StrokeRect(const Rect &aRect, const Pattern &aPattern,
   131                            const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions)
   132 {
   133   DualPattern pattern(aPattern);
   134   mA->StrokeRect(aRect, *pattern.mA, aStrokeOptions, aOptions);
   135   mB->StrokeRect(aRect, *pattern.mB, aStrokeOptions, aOptions);
   136 }
   138 void
   139 DrawTargetDual::StrokeLine(const Point &aStart, const Point &aEnd, const Pattern &aPattern,
   140                            const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions)
   141 {
   142   DualPattern pattern(aPattern);
   143   mA->StrokeLine(aStart, aEnd, *pattern.mA, aStrokeOptions, aOptions);
   144   mB->StrokeLine(aStart, aEnd, *pattern.mB, aStrokeOptions, aOptions);
   145 }
   147 void
   148 DrawTargetDual::Stroke(const Path *aPath, const Pattern &aPattern,
   149                        const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions)
   150 {
   151   DualPattern pattern(aPattern);
   152   mA->Stroke(aPath, *pattern.mA, aStrokeOptions, aOptions);
   153   mB->Stroke(aPath, *pattern.mB, aStrokeOptions, aOptions);
   154 }
   156 void
   157 DrawTargetDual::Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aOptions)
   158 {
   159   DualPattern pattern(aPattern);
   160   mA->Fill(aPath, *pattern.mA, aOptions);
   161   mB->Fill(aPath, *pattern.mB, aOptions);
   162 }
   164 void
   165 DrawTargetDual::FillGlyphs(ScaledFont *aScaledFont, const GlyphBuffer &aBuffer,
   166                            const Pattern &aPattern, const DrawOptions &aOptions,
   167                            const GlyphRenderingOptions *aRenderingOptions)
   168 {
   169   DualPattern pattern(aPattern);
   170   mA->FillGlyphs(aScaledFont, aBuffer, *pattern.mA, aOptions, aRenderingOptions);
   171   mB->FillGlyphs(aScaledFont, aBuffer, *pattern.mB, aOptions, aRenderingOptions);
   172 }
   174 void
   175 DrawTargetDual::Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions)
   176 {
   177   DualPattern source(aSource);
   178   DualPattern mask(aMask);
   179   mA->Mask(*source.mA, *mask.mA, aOptions);
   180   mB->Mask(*source.mB, *mask.mB, aOptions);
   181 }
   183 TemporaryRef<DrawTarget>
   184 DrawTargetDual::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
   185 {
   186   RefPtr<DrawTarget> dtA = mA->CreateSimilarDrawTarget(aSize, aFormat);
   187   RefPtr<DrawTarget> dtB = mB->CreateSimilarDrawTarget(aSize, aFormat);
   189   return new DrawTargetDual(dtA, dtB);
   190 }
   192 }
   193 }

mercurial