Mozilla2:GFXSurface: Difference between revisions

Update to support seperate surfaces
(notes on cairo difference)
(Update to support seperate surfaces)
Line 1: Line 1:
== Class Surface ==
== Class Surface ==
We need a surface to draw on to.  We need to be able to specifiy what type of surface to create -- for instance a Win32 surface or an image surface.
We need a surface to draw on to.  There will need to be multiple surface implementations such as win32, mac, linux, image, pdf, etc.
 
One thing I've done here that is different from cairo is that I've basically merged cairo_t and cairo_surface_t together here.  If someone sees a reason why we need that seperation, we can do that here as well.


=== API ===
=== API ===
  class Surface {
  class ASurface {
  public:
  public:
    Surface();
    ~Surface();
     // <insert refcount stuff here>
     // <insert refcount stuff here>
   
   
     // 0 = ARGB -- raw buffer.. wont be changed.. good for storing data.
     virtual cairo_surface_t *CairoSurface();
     // 1 = "native" -- data will be possibily changed as you set bits
     virtual int Format() const;
     // and will have to be converted back to ARGB
     virtual long Width() const;
     int format;
     virtual long Height() const;
   
   
     // raw access
     // raw access
     // will convert to ARGB32 pre-multiplied data if required
     // will convert to ARGB32 pre-multiplied data if required
     SurfaceData* Lock();
     virtual SurfaceData* Lock(long x, long y, long width, long height);
   
   
     // when unlock() is called, the data will be written back.
     // when unlock() is called, the data will be written back.
     // lock() must be called before calling this method.
     // lock() must be called before calling this method.
     void Unlock(SurfaceData* data);
     virtual void Unlock(SurfaceData* data);
    // state
    void Save();
    void Restore();
    // drawing
    void NewPath();
    void ClosePath();
    void Stroke();
    void Fill();
   
    void MoveTo(double x, double y);
    void LineTo(double x, double y);
    void CurveTo(double x1, double y1,
                  double x2, double y2,
                  double x3, double y3);
    void Arc(double xc, double yc,
              double radius,
              double angle1, double angle2);
    void Rectangle(double x, double y, double width, double height);
    void Polygon(const Point[] points, uint32 numPoints);
    // transform stuff
    void Translate(double x, double y);
    void Scale(double x, double y);
    void Rotate(double angle);
    void SetMatrix(Matrix* matrix);
    const Matrix& Matrix();
    // properties
    void SetColor(const RGBA& c);
    const RGBA& Color() const;
    void SetDash(double* dashes, int ndash, double offset);
    //void getDash() const;
    void SetLineWidth(double width);
    double LineWidth() const;
    // define enum for operators (clear, src, dst, etc)
    void SetOperator(int op);
    int Operator() const;
    // define line caps (butt, round, square)
    void SetLineCap(int cap);
    int LineCap() const;
    void SetMiterLimit(double limit);
    double MiterLimit() const;
    // clipping
    // patterns
    // fonts?
  };
  };


Line 94: Line 26:
  class SurfaceData {
  class SurfaceData {
  private:
  private:
     unsigned long width;
     long width;
     unsigned long height;
     long height;
     unsigned long stride;
     unsigned long stride;
     long length;
     long length;
Line 104: Line 36:
                 unsigned char *_data) :
                 unsigned char *_data) :
         width(_width), height(_height),
         width(_width), height(_height),
         stride(_stride), length(_length), data(_data) {}
         stride(_stride), length(_length), data(_data) {}
   
   
     unsigned long width()  const { return width; }
     long Width()  const { return width; }
     unsigned long height() const { return height; }
     long Height() const { return height; }
     unsigned long stride() const { return stride; }
     long Stride() const { return stride; }
     long length() const { return length; }
     long Length() const { return length; }
     unsigned char *data() { return data; }
     unsigned char *Data() { return data; }
  };
  };
569

edits