gfx/2d/PathCairo.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_PATH_CAIRO_H_
     7 #define MOZILLA_GFX_PATH_CAIRO_H_
     9 #include "2D.h"
    10 #include "cairo.h"
    11 #include <vector>
    13 namespace mozilla {
    14 namespace gfx {
    16 class DrawTargetCairo;
    17 class PathCairo;
    19 class PathBuilderCairo : public PathBuilder
    20 {
    21 public:
    22   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo)
    23   PathBuilderCairo(FillRule aFillRule);
    25   virtual void MoveTo(const Point &aPoint);
    26   virtual void LineTo(const Point &aPoint);
    27   virtual void BezierTo(const Point &aCP1,
    28                         const Point &aCP2,
    29                         const Point &aCP3);
    30   virtual void QuadraticBezierTo(const Point &aCP1,
    31                                  const Point &aCP2);
    32   virtual void Close();
    33   virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle,
    34                    float aEndAngle, bool aAntiClockwise = false);
    35   virtual Point CurrentPoint() const;
    36   virtual TemporaryRef<Path> Finish();
    38 private: // data
    39   friend class PathCairo;
    41   FillRule mFillRule;
    42   std::vector<cairo_path_data_t> mPathData;
    43   // It's easiest to track this here, parsing the path data to find the current
    44   // point is a little tricky.
    45   Point mCurrentPoint;
    46   Point mBeginPoint;
    47 };
    49 class PathCairo : public Path
    50 {
    51 public:
    52   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo)
    53   PathCairo(FillRule aFillRule, std::vector<cairo_path_data_t> &aPathData, const Point &aCurrentPoint);
    54   PathCairo(cairo_t *aContext);
    55   ~PathCairo();
    57   virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
    59   virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
    60   virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
    61                                                              FillRule aFillRule = FillRule::FILL_WINDING) const;
    63   virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const;
    65   virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
    66                                    const Point &aPoint,
    67                                    const Matrix &aTransform) const;
    69   virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const;
    71   virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
    72                                 const Matrix &aTransform = Matrix()) const;
    74   virtual void StreamToSink(PathSink *aSink) const;
    76   virtual FillRule GetFillRule() const { return mFillRule; }
    78   void SetPathOnContext(cairo_t *aContext) const;
    80   void AppendPathToBuilder(PathBuilderCairo *aBuilder, const Matrix *aTransform = nullptr) const;
    81 private:
    82   void EnsureContainingContext() const;
    84   FillRule mFillRule;
    85   std::vector<cairo_path_data_t> mPathData;
    86   mutable cairo_t *mContainingContext;
    87   Point mCurrentPoint;
    88 };
    90 }
    91 }
    93 #endif /* MOZILLA_GFX_PATH_CAIRO_H_ */

mercurial