core/Path.h
author Bas Schouten <bschouten@mozilla.com>
Wed, 02 Mar 2011 01:25:46 +0100
changeset 0 115d4e1f71cb2972d88db0a5a4995ca876b1206e
child 1 dcb76d9e25123a41868f28e4fea938b58ef9e62f
permissions -rw-r--r--
Bunch of code initially written, still sloppy and all.

#pragma once

#include "RefCountable.h"
#include "Point.h"
#include "RefPtr.h"

#include <vector>

namespace mozilla {
namespace render2d {

enum PathOperation {
  MOVE_TO = 0,
  LINE_TO,
  CURVE_TO,
  CLOSE
};

struct Crossing
{
  Point2D mCrossing;
  int mSegment1;
  int mSegment2;
};

struct PathSegment {
  PathOperation op;
  Point2D mPoints[3];
};

class SimplePathSink : public RefCountable
{
public:
  virtual void MoveTo(const Point2D &aPoint) = 0;
  virtual void LineTo(const Point2D &aPoint) = 0;
};

class PathSink : public SimplePathSink
{
public:
  virtual void CurveTo(const Point2D &aCP2,
                       const Point2D &aCP3,
                       const Point2D &aCP4) = 0;
};

class GeneralPathSink;
class PathAnalysis;

class Path : public RefCountable
{
public:
  Path();
  ~Path();

  RefPtr<PathSink> BeginWriting();

  void Flatten(SimplePathSink *aSink, Float aTolerance = 0.001);

  void Analyze();

  std::vector<Crossing> GetCrossings();

protected:
  friend class GeneralPathSink;


  void FlattenBezier(const Point2D &aCP1,
                     const Point2D &aCP2,
                     const Point2D &aCP3,
                     const Point2D &aCP4,
                     SimplePathSink *aSink,
                     Float aTolerance);

  void FlattenBezierCurveSegmentSSE(const Point2D &aCP1,
                                    const Point2D &aCP2,
                                    const Point2D &aCP3,
                                    const Point2D &aCP4,
                                    SimplePathSink *aSink,
                                    Float aTolerance);
  void FlattenBezierCurveSegment(const Point2D &aCP1,
                                 const Point2D &aCP2,
                                 const Point2D &aCP3,
                                 const Point2D &aCP4,
                                 SimplePathSink *aSink,
                                 Float aTolerance);

  std::vector<PathSegment> mSegments;
  RefPtr<PathAnalysis> mAnalysis;
};

}
}