gfx/2d/PathRecording.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/PathRecording.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,134 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_GFX_PATHRECORDING_H_
    1.10 +#define MOZILLA_GFX_PATHRECORDING_H_
    1.11 +
    1.12 +#include "2D.h"
    1.13 +#include <vector>
    1.14 +#include <ostream>
    1.15 +
    1.16 +namespace mozilla {
    1.17 +namespace gfx {
    1.18 +
    1.19 +struct PathOp
    1.20 +{
    1.21 +  enum OpType {
    1.22 +    OP_MOVETO = 0,
    1.23 +    OP_LINETO,
    1.24 +    OP_BEZIERTO,
    1.25 +    OP_QUADRATICBEZIERTO,
    1.26 +    OP_CLOSE
    1.27 +  };
    1.28 +
    1.29 +  OpType mType;
    1.30 +  Point mP1;
    1.31 +  Point mP2;
    1.32 +  Point mP3;
    1.33 +};
    1.34 +
    1.35 +const int32_t sPointCount[] = { 1, 1, 3, 2, 0, 0 };
    1.36 +
    1.37 +class PathRecording;
    1.38 +class DrawEventRecorderPrivate;
    1.39 +
    1.40 +class PathBuilderRecording : public PathBuilder
    1.41 +{
    1.42 +public:
    1.43 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderRecording)
    1.44 +  PathBuilderRecording(PathBuilder *aBuilder, FillRule aFillRule)
    1.45 +    : mPathBuilder(aBuilder), mFillRule(aFillRule)
    1.46 +  {
    1.47 +  }
    1.48 +
    1.49 +  /* Move the current point in the path, any figure currently being drawn will
    1.50 +   * be considered closed during fill operations, however when stroking the
    1.51 +   * closing line segment will not be drawn.
    1.52 +   */
    1.53 +  virtual void MoveTo(const Point &aPoint);
    1.54 +  /* Add a linesegment to the current figure */
    1.55 +  virtual void LineTo(const Point &aPoint);
    1.56 +  /* Add a cubic bezier curve to the current figure */
    1.57 +  virtual void BezierTo(const Point &aCP1,
    1.58 +                        const Point &aCP2,
    1.59 +                        const Point &aCP3);
    1.60 +  /* Add a quadratic bezier curve to the current figure */
    1.61 +  virtual void QuadraticBezierTo(const Point &aCP1,
    1.62 +                                 const Point &aCP2);
    1.63 +  /* Close the current figure, this will essentially generate a line segment
    1.64 +   * from the current point to the starting point for the current figure
    1.65 +   */
    1.66 +  virtual void Close();
    1.67 +
    1.68 +  /* Add an arc to the current figure */
    1.69 +  virtual void Arc(const Point &, float, float, float, bool) { }
    1.70 +
    1.71 +  /* Point the current subpath is at - or where the next subpath will start
    1.72 +   * if there is no active subpath.
    1.73 +   */
    1.74 +  virtual Point CurrentPoint() const;
    1.75 +
    1.76 +  virtual TemporaryRef<Path> Finish();
    1.77 +
    1.78 +private:
    1.79 +  friend class PathRecording;
    1.80 +
    1.81 +  RefPtr<PathBuilder> mPathBuilder;
    1.82 +  FillRule mFillRule;
    1.83 +  std::vector<PathOp> mPathOps;
    1.84 +};
    1.85 +
    1.86 +class PathRecording : public Path
    1.87 +{
    1.88 +public:
    1.89 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathRecording)
    1.90 +  PathRecording(Path *aPath, const std::vector<PathOp> aOps, FillRule aFillRule)
    1.91 +    : mPath(aPath), mPathOps(aOps), mFillRule(aFillRule)
    1.92 +  {
    1.93 +  }
    1.94 +
    1.95 +  ~PathRecording();
    1.96 +
    1.97 +  virtual BackendType GetBackendType() const { return BackendType::RECORDING; }
    1.98 +  virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
    1.99 +  virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
   1.100 +                                                             FillRule aFillRule = FillRule::FILL_WINDING) const;
   1.101 +  virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const
   1.102 +  { return mPath->ContainsPoint(aPoint, aTransform); }
   1.103 +  virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
   1.104 +                                   const Point &aPoint,
   1.105 +                                   const Matrix &aTransform) const
   1.106 +  { return mPath->StrokeContainsPoint(aStrokeOptions, aPoint, aTransform); }
   1.107 +  
   1.108 +  virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const
   1.109 +  { return mPath->GetBounds(aTransform); }
   1.110 +  
   1.111 +  virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
   1.112 +                                const Matrix &aTransform = Matrix()) const
   1.113 +  { return mPath->GetStrokedBounds(aStrokeOptions, aTransform); }
   1.114 +
   1.115 +  virtual void StreamToSink(PathSink *aSink) const { mPath->StreamToSink(aSink); }
   1.116 +
   1.117 +  virtual FillRule GetFillRule() const { return mFillRule; }
   1.118 +
   1.119 +  void StorePath(std::ostream &aStream) const;
   1.120 +  static void ReadPathToBuilder(std::istream &aStream, PathBuilder *aBuilder);
   1.121 +
   1.122 +private:
   1.123 +  friend class DrawTargetRecording;
   1.124 +  friend class RecordedPathCreation;
   1.125 +
   1.126 +  RefPtr<Path> mPath;
   1.127 +  std::vector<PathOp> mPathOps;
   1.128 +  FillRule mFillRule;
   1.129 +
   1.130 +  // Event recorders that have this path in their event stream.
   1.131 +  std::vector<DrawEventRecorderPrivate*> mStoredRecorders;
   1.132 +};
   1.133 +
   1.134 +}
   1.135 +}
   1.136 +
   1.137 +#endif /* MOZILLA_GFX_PATHRECORDING_H_ */

mercurial