gfx/2d/PathRecording.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_PATHRECORDING_H_
     7 #define MOZILLA_GFX_PATHRECORDING_H_
     9 #include "2D.h"
    10 #include <vector>
    11 #include <ostream>
    13 namespace mozilla {
    14 namespace gfx {
    16 struct PathOp
    17 {
    18   enum OpType {
    19     OP_MOVETO = 0,
    20     OP_LINETO,
    21     OP_BEZIERTO,
    22     OP_QUADRATICBEZIERTO,
    23     OP_CLOSE
    24   };
    26   OpType mType;
    27   Point mP1;
    28   Point mP2;
    29   Point mP3;
    30 };
    32 const int32_t sPointCount[] = { 1, 1, 3, 2, 0, 0 };
    34 class PathRecording;
    35 class DrawEventRecorderPrivate;
    37 class PathBuilderRecording : public PathBuilder
    38 {
    39 public:
    40   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderRecording)
    41   PathBuilderRecording(PathBuilder *aBuilder, FillRule aFillRule)
    42     : mPathBuilder(aBuilder), mFillRule(aFillRule)
    43   {
    44   }
    46   /* Move the current point in the path, any figure currently being drawn will
    47    * be considered closed during fill operations, however when stroking the
    48    * closing line segment will not be drawn.
    49    */
    50   virtual void MoveTo(const Point &aPoint);
    51   /* Add a linesegment to the current figure */
    52   virtual void LineTo(const Point &aPoint);
    53   /* Add a cubic bezier curve to the current figure */
    54   virtual void BezierTo(const Point &aCP1,
    55                         const Point &aCP2,
    56                         const Point &aCP3);
    57   /* Add a quadratic bezier curve to the current figure */
    58   virtual void QuadraticBezierTo(const Point &aCP1,
    59                                  const Point &aCP2);
    60   /* Close the current figure, this will essentially generate a line segment
    61    * from the current point to the starting point for the current figure
    62    */
    63   virtual void Close();
    65   /* Add an arc to the current figure */
    66   virtual void Arc(const Point &, float, float, float, bool) { }
    68   /* Point the current subpath is at - or where the next subpath will start
    69    * if there is no active subpath.
    70    */
    71   virtual Point CurrentPoint() const;
    73   virtual TemporaryRef<Path> Finish();
    75 private:
    76   friend class PathRecording;
    78   RefPtr<PathBuilder> mPathBuilder;
    79   FillRule mFillRule;
    80   std::vector<PathOp> mPathOps;
    81 };
    83 class PathRecording : public Path
    84 {
    85 public:
    86   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathRecording)
    87   PathRecording(Path *aPath, const std::vector<PathOp> aOps, FillRule aFillRule)
    88     : mPath(aPath), mPathOps(aOps), mFillRule(aFillRule)
    89   {
    90   }
    92   ~PathRecording();
    94   virtual BackendType GetBackendType() const { return BackendType::RECORDING; }
    95   virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
    96   virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
    97                                                              FillRule aFillRule = FillRule::FILL_WINDING) const;
    98   virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const
    99   { return mPath->ContainsPoint(aPoint, aTransform); }
   100   virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
   101                                    const Point &aPoint,
   102                                    const Matrix &aTransform) const
   103   { return mPath->StrokeContainsPoint(aStrokeOptions, aPoint, aTransform); }
   105   virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const
   106   { return mPath->GetBounds(aTransform); }
   108   virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
   109                                 const Matrix &aTransform = Matrix()) const
   110   { return mPath->GetStrokedBounds(aStrokeOptions, aTransform); }
   112   virtual void StreamToSink(PathSink *aSink) const { mPath->StreamToSink(aSink); }
   114   virtual FillRule GetFillRule() const { return mFillRule; }
   116   void StorePath(std::ostream &aStream) const;
   117   static void ReadPathToBuilder(std::istream &aStream, PathBuilder *aBuilder);
   119 private:
   120   friend class DrawTargetRecording;
   121   friend class RecordedPathCreation;
   123   RefPtr<Path> mPath;
   124   std::vector<PathOp> mPathOps;
   125   FillRule mFillRule;
   127   // Event recorders that have this path in their event stream.
   128   std::vector<DrawEventRecorderPrivate*> mStoredRecorders;
   129 };
   131 }
   132 }
   134 #endif /* MOZILLA_GFX_PATHRECORDING_H_ */

mercurial