gfx/2d/DrawTargetCairo.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/DrawTargetCairo.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,216 @@
     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_DRAWTARGET_CAIRO_H_
    1.10 +#define _MOZILLA_GFX_DRAWTARGET_CAIRO_H_
    1.11 +
    1.12 +#include "2D.h"
    1.13 +#include "cairo.h"
    1.14 +#include "PathCairo.h"
    1.15 +
    1.16 +#include <vector>
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace gfx {
    1.20 +
    1.21 +class SourceSurfaceCairo;
    1.22 +
    1.23 +class GradientStopsCairo : public GradientStops
    1.24 +{
    1.25 +  public:
    1.26 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GradientStopsCairo)
    1.27 +    GradientStopsCairo(GradientStop* aStops, uint32_t aNumStops,
    1.28 +                       ExtendMode aExtendMode)
    1.29 +     : mExtendMode(aExtendMode)
    1.30 +    {
    1.31 +      for (uint32_t i = 0; i < aNumStops; ++i) {
    1.32 +        mStops.push_back(aStops[i]);
    1.33 +      }
    1.34 +    }
    1.35 +
    1.36 +    virtual ~GradientStopsCairo() {}
    1.37 +
    1.38 +    const std::vector<GradientStop>& GetStops() const
    1.39 +    {
    1.40 +      return mStops;
    1.41 +    }
    1.42 +
    1.43 +    ExtendMode GetExtendMode() const
    1.44 +    {
    1.45 +      return mExtendMode;
    1.46 +    }
    1.47 +
    1.48 +    virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
    1.49 +
    1.50 +  private:
    1.51 +    std::vector<GradientStop> mStops;
    1.52 +    ExtendMode mExtendMode;
    1.53 +};
    1.54 +
    1.55 +class DrawTargetCairo : public DrawTarget
    1.56 +{
    1.57 +public:
    1.58 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetCairo)
    1.59 +  friend class BorrowedCairoContext;
    1.60 +
    1.61 +  DrawTargetCairo();
    1.62 +  virtual ~DrawTargetCairo();
    1.63 +
    1.64 +  virtual BackendType GetType() const { return BackendType::CAIRO; }
    1.65 +  virtual TemporaryRef<SourceSurface> Snapshot();
    1.66 +  virtual IntSize GetSize();
    1.67 +
    1.68 +  virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA);
    1.69 +
    1.70 +  virtual bool LockBits(uint8_t** aData, IntSize* aSize,
    1.71 +                        int32_t* aStride, SurfaceFormat* aFormat);
    1.72 +  virtual void ReleaseBits(uint8_t* aData);
    1.73 +
    1.74 +  virtual void Flush();
    1.75 +  virtual void DrawSurface(SourceSurface *aSurface,
    1.76 +                           const Rect &aDest,
    1.77 +                           const Rect &aSource,
    1.78 +                           const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
    1.79 +                           const DrawOptions &aOptions = DrawOptions());
    1.80 +  virtual void DrawFilter(FilterNode *aNode,
    1.81 +                          const Rect &aSourceRect,
    1.82 +                          const Point &aDestPoint,
    1.83 +                          const DrawOptions &aOptions = DrawOptions());
    1.84 +  virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
    1.85 +                                     const Point &aDest,
    1.86 +                                     const Color &aColor,
    1.87 +                                     const Point &aOffset,
    1.88 +                                     Float aSigma,
    1.89 +                                     CompositionOp aOperator);
    1.90 +
    1.91 +  virtual void ClearRect(const Rect &aRect);
    1.92 +
    1.93 +  virtual void CopySurface(SourceSurface *aSurface,
    1.94 +                           const IntRect &aSourceRect,
    1.95 +                           const IntPoint &aDestination);
    1.96 +  virtual void CopyRect(const IntRect &aSourceRect,
    1.97 +                        const IntPoint &aDestination);
    1.98 +
    1.99 +  virtual void FillRect(const Rect &aRect,
   1.100 +                        const Pattern &aPattern,
   1.101 +                        const DrawOptions &aOptions = DrawOptions());
   1.102 +  virtual void StrokeRect(const Rect &aRect,
   1.103 +                          const Pattern &aPattern,
   1.104 +                          const StrokeOptions &aStrokeOptions = StrokeOptions(),
   1.105 +                          const DrawOptions &aOptions = DrawOptions());
   1.106 +  virtual void StrokeLine(const Point &aStart,
   1.107 +                          const Point &aEnd,
   1.108 +                          const Pattern &aPattern,
   1.109 +                          const StrokeOptions &aStrokeOptions = StrokeOptions(),
   1.110 +                          const DrawOptions &aOptions = DrawOptions());
   1.111 +
   1.112 +  virtual void Stroke(const Path *aPath,
   1.113 +                      const Pattern &aPattern,
   1.114 +                      const StrokeOptions &aStrokeOptions = StrokeOptions(),
   1.115 +                      const DrawOptions &aOptions = DrawOptions());
   1.116 +
   1.117 +  virtual void Fill(const Path *aPath,
   1.118 +                    const Pattern &aPattern,
   1.119 +                    const DrawOptions &aOptions = DrawOptions());
   1.120 +
   1.121 +  virtual void FillGlyphs(ScaledFont *aFont,
   1.122 +                          const GlyphBuffer &aBuffer,
   1.123 +                          const Pattern &aPattern,
   1.124 +                          const DrawOptions &aOptions,
   1.125 +                          const GlyphRenderingOptions *aRenderingOptions = nullptr);
   1.126 +  virtual void Mask(const Pattern &aSource,
   1.127 +                    const Pattern &aMask,
   1.128 +                    const DrawOptions &aOptions = DrawOptions());
   1.129 +  virtual void MaskSurface(const Pattern &aSource,
   1.130 +                           SourceSurface *aMask,
   1.131 +                           Point aOffset,
   1.132 +                           const DrawOptions &aOptions = DrawOptions());
   1.133 +
   1.134 +  virtual void PushClip(const Path *aPath);
   1.135 +  virtual void PushClipRect(const Rect &aRect);
   1.136 +  virtual void PopClip();
   1.137 +
   1.138 +  virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
   1.139 +
   1.140 +  virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
   1.141 +                                                            const IntSize &aSize,
   1.142 +                                                            int32_t aStride,
   1.143 +                                                            SurfaceFormat aFormat) const;
   1.144 +  virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const;
   1.145 +  virtual TemporaryRef<SourceSurface>
   1.146 +    CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const;
   1.147 +  virtual TemporaryRef<DrawTarget>
   1.148 +    CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
   1.149 +  virtual TemporaryRef<DrawTarget>
   1.150 +    CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat,
   1.151 +                           float aSigma) const;
   1.152 +
   1.153 +  virtual TemporaryRef<GradientStops>
   1.154 +    CreateGradientStops(GradientStop *aStops,
   1.155 +                        uint32_t aNumStops,
   1.156 +                        ExtendMode aExtendMode = ExtendMode::CLAMP) const;
   1.157 +
   1.158 +  virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType);
   1.159 +
   1.160 +  virtual void *GetNativeSurface(NativeSurfaceType aType);
   1.161 +
   1.162 +  bool Init(cairo_surface_t* aSurface, const IntSize& aSize, SurfaceFormat* aFormat = nullptr);
   1.163 +  bool Init(const IntSize& aSize, SurfaceFormat aFormat);
   1.164 +  bool Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
   1.165 +
   1.166 +  virtual void SetTransform(const Matrix& aTransform);
   1.167 +
   1.168 +  // Call to set up aContext for drawing (with the current transform, etc).
   1.169 +  // Pass the path you're going to be using if you have one.
   1.170 +  // Implicitly calls WillChange(aPath).
   1.171 +  void PrepareForDrawing(cairo_t* aContext, const Path* aPath = nullptr);
   1.172 +
   1.173 +  static cairo_surface_t *GetDummySurface();
   1.174 +
   1.175 +private: // methods
   1.176 +  // Init cairo surface without doing a cairo_surface_reference() call.
   1.177 +  bool InitAlreadyReferenced(cairo_surface_t* aSurface, const IntSize& aSize, SurfaceFormat* aFormat = nullptr);
   1.178 +  enum DrawPatternType { DRAW_FILL, DRAW_STROKE };
   1.179 +  void DrawPattern(const Pattern& aPattern,
   1.180 +                   const StrokeOptions& aStrokeOptions,
   1.181 +                   const DrawOptions& aOptions,
   1.182 +                   DrawPatternType aDrawType,
   1.183 +                   bool aPathBoundsClip = false);
   1.184 +
   1.185 +  void CopySurfaceInternal(cairo_surface_t* aSurface,
   1.186 +                           const IntRect& aSource,
   1.187 +                           const IntPoint& aDest);
   1.188 +
   1.189 +  Rect GetUserSpaceClip();
   1.190 +
   1.191 +  // Call before you make any changes to the backing surface with which this
   1.192 +  // context is associated. Pass the path you're going to be using if you have
   1.193 +  // one.
   1.194 +  void WillChange(const Path* aPath = nullptr);
   1.195 +
   1.196 +  // Call if there is any reason to disassociate the snapshot from this draw
   1.197 +  // target; for example, because we're going to be destroyed.
   1.198 +  void MarkSnapshotIndependent();
   1.199 +
   1.200 +  // If the current operator is "source" then clear the destination before we
   1.201 +  // draw into it, to simulate the effect of an unbounded source operator.
   1.202 +  void ClearSurfaceForUnboundedSource(const CompositionOp &aOperator);
   1.203 +private: // data
   1.204 +  cairo_t* mContext;
   1.205 +  cairo_surface_t* mSurface;
   1.206 +  IntSize mSize;
   1.207 +
   1.208 +  uint8_t* mLockedBits;
   1.209 +
   1.210 +  // The latest snapshot of this surface. This needs to be told when this
   1.211 +  // target is modified. We keep it alive as a cache.
   1.212 +  RefPtr<SourceSurfaceCairo> mSnapshot;
   1.213 +  static cairo_surface_t *mDummySurface;
   1.214 +};
   1.215 +
   1.216 +}
   1.217 +}
   1.218 +
   1.219 +#endif // _MOZILLA_GFX_DRAWTARGET_CAIRO_H_

mercurial