LCOV - code coverage report
Current view: directory - gfx/2d - 2D.h (source / functions) Found Hit Coverage
Test: app.info Lines: 24 0 0.0 %
Date: 2012-06-02 Functions: 30 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  * ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Corporation code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Mozilla Foundation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Bas Schouten <bschouten@mozilla.com>
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #ifndef _MOZILLA_GFX_2D_H
      39                 : #define _MOZILLA_GFX_2D_H
      40                 : 
      41                 : #include "Point.h"
      42                 : #include "Rect.h"
      43                 : #include "Matrix.h"
      44                 : #include "UserData.h"
      45                 : // This RefPtr class isn't ideal for usage in Azure, as it doesn't allow T**
      46                 : // outparams using the &-operator. But it will have to do as there's no easy
      47                 : // solution.
      48                 : #include "mozilla/RefPtr.h"
      49                 : 
      50                 : struct _cairo_surface;
      51                 : typedef _cairo_surface cairo_surface_t;
      52                 : 
      53                 : struct _cairo_scaled_font;
      54                 : typedef _cairo_scaled_font cairo_scaled_font_t;
      55                 : 
      56                 : struct ID3D10Device1;
      57                 : struct ID3D10Texture2D;
      58                 : 
      59                 : namespace mozilla {
      60                 : namespace gfx {
      61                 : 
      62                 : class SourceSurface;
      63                 : class DataSourceSurface;
      64                 : class DrawTarget;
      65                 : 
      66                 : struct NativeSurface {
      67                 :   NativeSurfaceType mType;
      68                 :   SurfaceFormat mFormat;
      69                 :   void *mSurface;
      70                 : };
      71                 : 
      72                 : struct NativeFont {
      73                 :   NativeFontType mType;
      74                 :   void *mFont;
      75                 : };
      76                 : 
      77                 : /*
      78                 :  * This structure is used to send draw options that are universal to all drawing
      79                 :  * operations. It consists of the following:
      80                 :  *
      81                 :  * mAlpha         - Alpha value by which the mask generated by this operation is
      82                 :  *                  multiplied.
      83                 :  * mCompositionOp - The operator that indicates how the source and destination
      84                 :  *                  patterns are blended.
      85                 :  * mAntiAliasMode - The AntiAlias mode used for this drawing operation.
      86                 :  * mSnapping      - Whether this operation is snapped to pixel boundaries.
      87                 :  */
      88                 : struct DrawOptions {
      89                 :   DrawOptions(Float aAlpha = 1.0f,
      90                 :               CompositionOp aCompositionOp = OP_OVER,
      91                 :               AntialiasMode aAntialiasMode = AA_GRAY,
      92                 :               Snapping aSnapping = SNAP_NONE)
      93                 :     : mAlpha(aAlpha)
      94                 :     , mCompositionOp(aCompositionOp)
      95                 :     , mAntialiasMode(aAntialiasMode)
      96                 :     , mSnapping(aSnapping)
      97                 :   {}
      98                 : 
      99                 :   Float mAlpha;
     100                 :   CompositionOp mCompositionOp : 8;
     101                 :   AntialiasMode mAntialiasMode : 2;
     102                 :   Snapping mSnapping : 1;
     103                 : };
     104                 : 
     105                 : /*
     106                 :  * This structure is used to send stroke options that are used in stroking
     107                 :  * operations. It consists of the following:
     108                 :  *
     109                 :  * mLineWidth    - Width of the stroke in userspace.
     110                 :  * mLineJoin     - Join style used for joining lines.
     111                 :  * mLineCap      - Cap style used for capping lines.
     112                 :  * mMiterLimit   - Miter limit in units of linewidth
     113                 :  * mDashPattern  - Series of on/off userspace lengths defining dash.
     114                 :  *                 Owned by the caller; must live at least as long as
     115                 :  *                 this StrokeOptions.
     116                 :  *                 mDashPattern != null <=> mDashLength > 0.
     117                 :  * mDashLength   - Number of on/off lengths in mDashPattern.
     118                 :  * mDashOffset   - Userspace offset within mDashPattern at which stroking
     119                 :  *                 begins.
     120                 :  */
     121                 : struct StrokeOptions {
     122               0 :   StrokeOptions(Float aLineWidth = 1.0f,
     123                 :                 JoinStyle aLineJoin = JOIN_MITER_OR_BEVEL,
     124                 :                 CapStyle aLineCap = CAP_BUTT,
     125                 :                 Float aMiterLimit = 10.0f,
     126                 :                 size_t aDashLength = 0,
     127                 :                 const Float* aDashPattern = 0,
     128                 :                 Float aDashOffset = 0.f)
     129                 :     : mLineWidth(aLineWidth)
     130                 :     , mMiterLimit(aMiterLimit)
     131                 :     , mDashPattern(aDashLength > 0 ? aDashPattern : 0)
     132                 :     , mDashLength(aDashLength)
     133                 :     , mDashOffset(aDashOffset)
     134                 :     , mLineJoin(aLineJoin)
     135               0 :     , mLineCap(aLineCap)
     136                 :   {
     137               0 :     MOZ_ASSERT(aDashLength == 0 || aDashPattern);
     138               0 :   }
     139                 : 
     140                 :   Float mLineWidth;
     141                 :   Float mMiterLimit;
     142                 :   const Float* mDashPattern;
     143                 :   size_t mDashLength;
     144                 :   Float mDashOffset;
     145                 :   JoinStyle mLineJoin : 4;
     146                 :   CapStyle mLineCap : 3;
     147                 : };
     148                 : 
     149                 : /*
     150                 :  * This structure supplies additional options for calls to DrawSurface.
     151                 :  *
     152                 :  * mFilter - Filter used when resampling source surface region to the
     153                 :  *           destination region.
     154                 :  * aSamplingBounds - This indicates whether the implementation is allowed
     155                 :  *                   to sample pixels outside the source rectangle as
     156                 :  *                   specified in DrawSurface on the surface.
     157                 :  */
     158                 : struct DrawSurfaceOptions {
     159                 :   DrawSurfaceOptions(Filter aFilter = FILTER_LINEAR,
     160                 :                      SamplingBounds aSamplingBounds = SAMPLING_UNBOUNDED)
     161                 :     : mFilter(aFilter)
     162                 :     , mSamplingBounds(aSamplingBounds)
     163                 :   { }
     164                 : 
     165                 :   Filter mFilter : 3;
     166                 :   SamplingBounds mSamplingBounds : 1;
     167                 : };
     168                 : 
     169                 : /*
     170                 :  * This class is used to store gradient stops, it can only be used with a
     171                 :  * matching DrawTarget. Not adhering to this condition will make a draw call
     172                 :  * fail.
     173                 :  */
     174                 : class GradientStops : public RefCounted<GradientStops>
     175                 : {
     176                 : public:
     177               0 :   virtual ~GradientStops() {}
     178                 : 
     179                 :   virtual BackendType GetBackendType() const = 0;
     180                 : 
     181                 : protected:
     182               0 :   GradientStops() {}
     183                 : };
     184                 : 
     185                 : /*
     186                 :  * This is the base class for 'patterns'. Patterns describe the pixels used as
     187                 :  * the source for a masked composition operation that is done by the different
     188                 :  * drawing commands. These objects are not backend specific, however for
     189                 :  * example the gradient stops on a gradient pattern can be backend specific.
     190                 :  */
     191                 : class Pattern
     192                 : {
     193                 : public:
     194                 :   virtual ~Pattern() {}
     195                 : 
     196                 :   virtual PatternType GetType() const = 0;
     197                 : 
     198                 : protected:
     199                 :   Pattern() {}
     200                 : };
     201                 : 
     202                 : class ColorPattern : public Pattern
     203                 : {
     204                 : public:
     205                 :   ColorPattern(const Color &aColor)
     206                 :     : mColor(aColor)
     207                 :   {}
     208                 : 
     209                 :   virtual PatternType GetType() const { return PATTERN_COLOR; }
     210                 : 
     211                 :   Color mColor;
     212                 : };
     213                 : 
     214                 : /*
     215                 :  * This class is used for Linear Gradient Patterns, the gradient stops are
     216                 :  * stored in a separate object and are backend dependent. This class itself
     217                 :  * may be used on the stack.
     218                 :  */
     219                 : class LinearGradientPattern : public Pattern
     220                 : {
     221                 : public:
     222                 :   /*
     223                 :    * aBegin Start of the linear gradient
     224                 :    * aEnd End of the linear gradient - NOTE: In the case of a zero length
     225                 :    *      gradient it will act as the color of the last stop.
     226                 :    * aStops GradientStops object for this gradient, this should match the
     227                 :    *        backend type of the draw target this pattern will be used with.
     228                 :    * aMatrix A matrix that transforms the pattern into user space
     229                 :    */
     230                 :   LinearGradientPattern(const Point &aBegin,
     231                 :                         const Point &aEnd,
     232                 :                         GradientStops *aStops,
     233                 :                         const Matrix &aMatrix = Matrix())
     234                 :     : mBegin(aBegin)
     235                 :     , mEnd(aEnd)
     236                 :     , mStops(aStops)
     237                 :     , mMatrix(aMatrix)
     238                 :   {
     239                 :   }
     240                 : 
     241                 :   virtual PatternType GetType() const { return PATTERN_LINEAR_GRADIENT; }
     242                 : 
     243                 :   Point mBegin;
     244                 :   Point mEnd;
     245                 :   RefPtr<GradientStops> mStops;
     246                 :   Matrix mMatrix;
     247                 : };
     248                 : 
     249                 : /*
     250                 :  * This class is used for Radial Gradient Patterns, the gradient stops are
     251                 :  * stored in a separate object and are backend dependent. This class itself
     252                 :  * may be used on the stack.
     253                 :  */
     254                 : class RadialGradientPattern : public Pattern
     255                 : {
     256                 : public:
     257                 :   /*
     258                 :    * aBegin Start of the linear gradient
     259                 :    * aEnd End of the linear gradient
     260                 :    * aStops GradientStops object for this gradient, this should match the
     261                 :    *        backend type of the draw target this pattern will be used with.
     262                 :    * aMatrix A matrix that transforms the pattern into user space
     263                 :    */
     264                 :   RadialGradientPattern(const Point &aCenter1,
     265                 :                         const Point &aCenter2,
     266                 :                         Float aRadius1,
     267                 :                         Float aRadius2,
     268                 :                         GradientStops *aStops,
     269                 :                         const Matrix &aMatrix = Matrix())
     270                 :     : mCenter1(aCenter1)
     271                 :     , mCenter2(aCenter2)
     272                 :     , mRadius1(aRadius1)
     273                 :     , mRadius2(aRadius2)
     274                 :     , mStops(aStops)
     275                 :     , mMatrix(aMatrix)
     276                 :   {
     277                 :   }
     278                 : 
     279                 :   virtual PatternType GetType() const { return PATTERN_RADIAL_GRADIENT; }
     280                 : 
     281                 :   Point mCenter1;
     282                 :   Point mCenter2;
     283                 :   Float mRadius1;
     284                 :   Float mRadius2;
     285                 :   RefPtr<GradientStops> mStops;
     286                 :   Matrix mMatrix;
     287                 : };
     288                 : 
     289                 : /*
     290                 :  * This class is used for Surface Patterns, they wrap a surface and a
     291                 :  * repetition mode for the surface. This may be used on the stack.
     292                 :  */
     293                 : class SurfacePattern : public Pattern
     294                 : {
     295                 : public:
     296                 :   /*
     297                 :    * aSourceSurface Surface to use for drawing
     298                 :    * aExtendMode This determines how the image is extended outside the bounds
     299                 :    *             of the image.
     300                 :    * aMatrix A matrix that transforms the pattern into user space
     301                 :    * aFilter Resampling filter used for resampling the image.
     302                 :    */
     303                 :   SurfacePattern(SourceSurface *aSourceSurface, ExtendMode aExtendMode,
     304                 :                  const Matrix &aMatrix = Matrix(), Filter aFilter = FILTER_LINEAR)
     305                 :     : mSurface(aSourceSurface)
     306                 :     , mExtendMode(aExtendMode)
     307                 :     , mFilter(aFilter)
     308                 :     , mMatrix(aMatrix)
     309                 :   {}
     310                 : 
     311                 :   virtual PatternType GetType() const { return PATTERN_SURFACE; }
     312                 : 
     313                 :   RefPtr<SourceSurface> mSurface;
     314                 :   ExtendMode mExtendMode;
     315                 :   Filter mFilter;
     316                 :   Matrix mMatrix;
     317                 : };
     318                 : 
     319                 : /*
     320                 :  * This is the base class for source surfaces. These objects are surfaces
     321                 :  * which may be used as a source in a SurfacePattern of a DrawSurface call.
     322                 :  * They cannot be drawn to directly.
     323                 :  */
     324                 : class SourceSurface : public RefCounted<SourceSurface>
     325               0 : {
     326                 : public:
     327               0 :   virtual ~SourceSurface() {}
     328                 : 
     329                 :   virtual SurfaceType GetType() const = 0;
     330                 :   virtual IntSize GetSize() const = 0;
     331                 :   virtual SurfaceFormat GetFormat() const = 0;
     332                 : 
     333                 :   /*
     334                 :    * This function will get a DataSourceSurface for this surface, a
     335                 :    * DataSourceSurface's data can be accessed directly.
     336                 :    */
     337                 :   virtual TemporaryRef<DataSourceSurface> GetDataSurface() = 0;
     338                 : };
     339                 : 
     340                 : class DataSourceSurface : public SourceSurface
     341               0 : {
     342                 : public:
     343               0 :   virtual SurfaceType GetType() const { return SURFACE_DATA; }
     344                 :   /* Get the raw bitmap data of the surface */
     345                 :   virtual unsigned char *GetData() = 0;
     346                 :   /*
     347                 :    * Stride of the surface, distance in bytes between the start of the image
     348                 :    * data belonging to row y and row y+1. This may be negative.
     349                 :    */
     350                 :   virtual int32_t Stride() = 0;
     351                 : 
     352                 :   /*
     353                 :    * This function is called after modifying the data on the source surface
     354                 :    * directly through the data pointer.
     355                 :    */
     356               0 :   virtual void MarkDirty() {}
     357                 : 
     358               0 :   virtual TemporaryRef<DataSourceSurface> GetDataSurface() { RefPtr<DataSourceSurface> temp = this; return temp.forget(); }
     359                 : };
     360                 : 
     361                 : /* This is an abstract object that accepts path segments. */
     362                 : class PathSink : public RefCounted<PathSink>
     363               0 : {
     364                 : public:
     365               0 :   virtual ~PathSink() {}
     366                 : 
     367                 :   /* Move the current point in the path, any figure currently being drawn will
     368                 :    * be considered closed during fill operations, however when stroking the
     369                 :    * closing line segment will not be drawn.
     370                 :    */
     371                 :   virtual void MoveTo(const Point &aPoint) = 0;
     372                 :   /* Add a linesegment to the current figure */
     373                 :   virtual void LineTo(const Point &aPoint) = 0;
     374                 :   /* Add a cubic bezier curve to the current figure */
     375                 :   virtual void BezierTo(const Point &aCP1,
     376                 :                         const Point &aCP2,
     377                 :                         const Point &aCP3) = 0;
     378                 :   /* Add a quadratic bezier curve to the current figure */
     379                 :   virtual void QuadraticBezierTo(const Point &aCP1,
     380                 :                                  const Point &aCP2) = 0;
     381                 :   /* Close the current figure, this will essentially generate a line segment
     382                 :    * from the current point to the starting point for the current figure
     383                 :    */
     384                 :   virtual void Close() = 0;
     385                 :   /* Add an arc to the current figure */
     386                 :   virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle,
     387                 :                    float aEndAngle, bool aAntiClockwise = false) = 0;
     388                 :   /* Point the current subpath is at - or where the next subpath will start
     389                 :    * if there is no active subpath.
     390                 :    */
     391                 :   virtual Point CurrentPoint() const = 0;
     392                 : };
     393                 : 
     394                 : class PathBuilder;
     395                 : 
     396                 : /* The path class is used to create (sets of) figures of any shape that can be
     397                 :  * filled or stroked to a DrawTarget
     398                 :  */
     399                 : class Path : public RefCounted<Path>
     400               0 : {
     401                 : public:
     402               0 :   virtual ~Path() {}
     403                 :   
     404                 :   virtual BackendType GetBackendType() const = 0;
     405                 : 
     406                 :   /* This returns a PathBuilder object that contains a copy of the contents of
     407                 :    * this path and is still writable.
     408                 :    */
     409                 :   virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FILL_WINDING) const = 0;
     410                 :   virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
     411                 :                                                              FillRule aFillRule = FILL_WINDING) const = 0;
     412                 : 
     413                 :   /* This function checks if a point lies within a path. It allows passing a
     414                 :    * transform that will transform the path to the coordinate space in which
     415                 :    * aPoint is given.
     416                 :    */
     417                 :   virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const = 0;
     418                 : 
     419                 :   /* This functions gets the bounds of this path. These bounds are not
     420                 :    * guaranteed to be tight. A transform may be specified that gives the bounds
     421                 :    * after application of the transform.
     422                 :    */
     423                 :   virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const = 0;
     424                 : 
     425                 :   /* This function gets the bounds of the stroke of this path using the
     426                 :    * specified strokeoptions. These bounds are not guaranteed to be tight.
     427                 :    * A transform may be specified that gives the bounds after application of
     428                 :    * the transform.
     429                 :    */
     430                 :   virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
     431                 :                                 const Matrix &aTransform = Matrix()) const = 0;
     432                 : 
     433                 :   /* This gets the fillrule this path's builder was created with. This is not
     434                 :    * mutable.
     435                 :    */
     436                 :   virtual FillRule GetFillRule() const = 0;
     437                 : };
     438                 : 
     439                 : /* The PathBuilder class allows path creation. Once finish is called on the
     440                 :  * pathbuilder it may no longer be written to.
     441                 :  */
     442                 : class PathBuilder : public PathSink
     443               0 : {
     444                 : public:
     445                 :   /* Finish writing to the path and return a Path object that can be used for
     446                 :    * drawing. Future use of the builder results in a crash!
     447                 :    */
     448                 :   virtual TemporaryRef<Path> Finish() = 0;
     449                 : };
     450                 : 
     451                 : struct Glyph
     452                 : {
     453                 :   uint32_t mIndex;
     454                 :   Point mPosition;
     455                 : };
     456                 : 
     457                 : /* This class functions as a glyph buffer that can be drawn to a DrawTarget.
     458                 :  * XXX - This should probably contain the guts of gfxTextRun in the future as
     459                 :  * roc suggested. But for now it's a simple container for a glyph vector.
     460                 :  */
     461                 : struct GlyphBuffer
     462                 : {
     463                 :   // A pointer to a buffer of glyphs. Managed by the caller.
     464                 :   const Glyph *mGlyphs;
     465                 :   // Number of glyphs mGlyphs points to.
     466                 :   uint32_t mNumGlyphs;
     467                 : };
     468                 : 
     469                 : /* This class is an abstraction of a backend/platform specific font object
     470                 :  * at a particular size. It is passed into text drawing calls to describe
     471                 :  * the font used for the drawing call.
     472                 :  */
     473                 : class ScaledFont : public RefCounted<ScaledFont>
     474                 : {
     475                 : public:
     476               0 :   virtual ~ScaledFont() {}
     477                 : 
     478                 :   virtual FontType GetType() const = 0;
     479                 : 
     480                 :   /* This allows getting a path that describes the outline of a set of glyphs.
     481                 :    * A target is passed in so that the guarantee is made the returned path
     482                 :    * can be used with any DrawTarget that has the same backend as the one
     483                 :    * passed in.
     484                 :    */
     485                 :   virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget) = 0;
     486                 : 
     487                 : protected:
     488               0 :   ScaledFont() {}
     489                 : };
     490                 : 
     491                 : /* This is the main class used for all the drawing. It is created through the
     492                 :  * factory and accepts drawing commands. The results of drawing to a target
     493                 :  * may be used either through a Snapshot or by flushing the target and directly
     494                 :  * accessing the backing store a DrawTarget was created with.
     495                 :  */
     496                 : class DrawTarget : public RefCounted<DrawTarget>
     497                 : {
     498                 : public:
     499               0 :   DrawTarget() : mTransformDirty(false) {}
     500               0 :   virtual ~DrawTarget() {}
     501                 : 
     502                 :   virtual BackendType GetType() const = 0;
     503                 :   /**
     504                 :    * Returns a SourceSurface which is a snapshot of the current contents of the DrawTarget.
     505                 :    * Multiple calls to Snapshot() without any drawing operations in between will
     506                 :    * normally return the same SourceSurface object.
     507                 :    */
     508                 :   virtual TemporaryRef<SourceSurface> Snapshot() = 0;
     509                 :   virtual IntSize GetSize() = 0;
     510                 : 
     511                 :   /* Ensure that the DrawTarget backend has flushed all drawing operations to
     512                 :    * this draw target. This must be called before using the backing surface of
     513                 :    * this draw target outside of GFX 2D code.
     514                 :    */
     515                 :   virtual void Flush() = 0;
     516                 : 
     517                 :   /*
     518                 :    * Draw a surface to the draw target. Possibly doing partial drawing or
     519                 :    * applying scaling. No sampling happens outside the source.
     520                 :    *
     521                 :    * aSurface Source surface to draw
     522                 :    * aDest Destination rectangle that this drawing operation should draw to
     523                 :    * aSource Source rectangle in aSurface coordinates, this area of aSurface
     524                 :    *         will be stretched to the size of aDest.
     525                 :    * aOptions General draw options that are applied to the operation
     526                 :    * aSurfOptions DrawSurface options that are applied
     527                 :    */
     528                 :   virtual void DrawSurface(SourceSurface *aSurface,
     529                 :                            const Rect &aDest,
     530                 :                            const Rect &aSource,
     531                 :                            const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
     532                 :                            const DrawOptions &aOptions = DrawOptions()) = 0;
     533                 : 
     534                 :   /*
     535                 :    * Blend a surface to the draw target with a shadow. The shadow is drawn as a
     536                 :    * gaussian blur using a specified sigma. The shadow is clipped to the size
     537                 :    * of the input surface, so the input surface should contain a transparent
     538                 :    * border the size of the approximate coverage of the blur (3 * aSigma).
     539                 :    * NOTE: This function works in device space!
     540                 :    *
     541                 :    * aSurface Source surface to draw.
     542                 :    * aDest Destination point that this drawing operation should draw to.
     543                 :    * aColor Color of the drawn shadow
     544                 :    * aOffset Offset of the shadow
     545                 :    * aSigma Sigma used for the guassian filter kernel
     546                 :    * aOperator Composition operator used
     547                 :    */
     548                 :   virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
     549                 :                                      const Point &aDest,
     550                 :                                      const Color &aColor,
     551                 :                                      const Point &aOffset,
     552                 :                                      Float aSigma,
     553                 :                                      CompositionOp aOperator) = 0;
     554                 : 
     555                 :   /* 
     556                 :    * Clear a rectangle on the draw target to transparent black. This will
     557                 :    * respect the clipping region and transform.
     558                 :    *
     559                 :    * aRect Rectangle to clear
     560                 :    */
     561                 :   virtual void ClearRect(const Rect &aRect) = 0;
     562                 : 
     563                 :   /*
     564                 :    * This is essentially a 'memcpy' between two surfaces. It moves a pixel
     565                 :    * aligned area from the source surface unscaled directly onto the
     566                 :    * drawtarget. This ignores both transform and clip.
     567                 :    *
     568                 :    * aSurface Surface to copy from
     569                 :    * aSourceRect Source rectangle to be copied
     570                 :    * aDest Destination point to copy the surface to
     571                 :    */
     572                 :   virtual void CopySurface(SourceSurface *aSurface,
     573                 :                            const IntRect &aSourceRect,
     574                 :                            const IntPoint &aDestination) = 0;
     575                 : 
     576                 :   /*
     577                 :    * Fill a rectangle on the DrawTarget with a certain source pattern.
     578                 :    *
     579                 :    * aRect Rectangle that forms the mask of this filling operation
     580                 :    * aPattern Pattern that forms the source of this filling operation
     581                 :    * aOptions Options that are applied to this operation
     582                 :    */
     583                 :   virtual void FillRect(const Rect &aRect,
     584                 :                         const Pattern &aPattern,
     585                 :                         const DrawOptions &aOptions = DrawOptions()) = 0;
     586                 : 
     587                 :   /*
     588                 :    * Stroke a rectangle on the DrawTarget with a certain source pattern.
     589                 :    *
     590                 :    * aRect Rectangle that forms the mask of this stroking operation
     591                 :    * aPattern Pattern that forms the source of this stroking operation
     592                 :    * aOptions Options that are applied to this operation
     593                 :    */
     594                 :   virtual void StrokeRect(const Rect &aRect,
     595                 :                           const Pattern &aPattern,
     596                 :                           const StrokeOptions &aStrokeOptions = StrokeOptions(),
     597                 :                           const DrawOptions &aOptions = DrawOptions()) = 0;
     598                 : 
     599                 :   /*
     600                 :    * Stroke a line on the DrawTarget with a certain source pattern.
     601                 :    *
     602                 :    * aStart Starting point of the line
     603                 :    * aEnd End point of the line
     604                 :    * aPattern Pattern that forms the source of this stroking operation
     605                 :    * aOptions Options that are applied to this operation
     606                 :    */
     607                 :   virtual void StrokeLine(const Point &aStart,
     608                 :                           const Point &aEnd,
     609                 :                           const Pattern &aPattern,
     610                 :                           const StrokeOptions &aStrokeOptions = StrokeOptions(),
     611                 :                           const DrawOptions &aOptions = DrawOptions()) = 0;
     612                 : 
     613                 :   /*
     614                 :    * Stroke a path on the draw target with a certain source pattern.
     615                 :    *
     616                 :    * aPath Path that is to be stroked
     617                 :    * aPattern Pattern that should be used for the stroke
     618                 :    * aStrokeOptions Stroke options used for this operation
     619                 :    * aOptions Draw options used for this operation
     620                 :    */
     621                 :   virtual void Stroke(const Path *aPath,
     622                 :                       const Pattern &aPattern,
     623                 :                       const StrokeOptions &aStrokeOptions = StrokeOptions(),
     624                 :                       const DrawOptions &aOptions = DrawOptions()) = 0;
     625                 :   
     626                 :   /*
     627                 :    * Fill a path on the draw target with a certain source pattern.
     628                 :    *
     629                 :    * aPath Path that is to be filled
     630                 :    * aPattern Pattern that should be used for the fill
     631                 :    * aOptions Draw options used for this operation
     632                 :    */
     633                 :   virtual void Fill(const Path *aPath,
     634                 :                     const Pattern &aPattern,
     635                 :                     const DrawOptions &aOptions = DrawOptions()) = 0;
     636                 : 
     637                 :   /*
     638                 :    * Fill a series of clyphs on the draw target with a certain source pattern.
     639                 :    */
     640                 :   virtual void FillGlyphs(ScaledFont *aFont,
     641                 :                           const GlyphBuffer &aBuffer,
     642                 :                           const Pattern &aPattern,
     643                 :                           const DrawOptions &aOptions = DrawOptions()) = 0;
     644                 : 
     645                 :   /*
     646                 :    * This takes a source pattern and a mask, and composites the source pattern
     647                 :    * onto the destination surface using the alpha channel of the mask pattern
     648                 :    * as a mask for the operation.
     649                 :    *
     650                 :    * aSource Source pattern
     651                 :    * aMask Mask pattern
     652                 :    * aOptions Drawing options
     653                 :    */
     654                 :   virtual void Mask(const Pattern &aSource,
     655                 :                     const Pattern &aMask,
     656                 :                     const DrawOptions &aOptions = DrawOptions()) = 0;
     657                 : 
     658                 :   /*
     659                 :    * Push a clip to the DrawTarget.
     660                 :    *
     661                 :    * aPath The path to clip to
     662                 :    */
     663                 :   virtual void PushClip(const Path *aPath) = 0;
     664                 : 
     665                 :   /*
     666                 :    * Push an axis-aligned rectangular clip to the DrawTarget. This rectangle
     667                 :    * is specified in user space.
     668                 :    *
     669                 :    * aRect The rect to clip to
     670                 :    */
     671                 :   virtual void PushClipRect(const Rect &aRect) = 0;
     672                 : 
     673                 :   /* Pop a clip from the DrawTarget. A pop without a corresponding push will
     674                 :    * be ignored.
     675                 :    */
     676                 :   virtual void PopClip() = 0;
     677                 : 
     678                 :   /*
     679                 :    * Create a SourceSurface optimized for use with this DrawTarget from
     680                 :    * existing bitmap data in memory.
     681                 :    *
     682                 :    * The SourceSurface does not take ownership of aData, and may be freed at any time.
     683                 :    */
     684                 :   virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
     685                 :                                                                   const IntSize &aSize,
     686                 :                                                                   int32_t aStride,
     687                 :                                                                   SurfaceFormat aFormat) const = 0;
     688                 : 
     689                 :   /*
     690                 :    * Create a SourceSurface optimized for use with this DrawTarget from
     691                 :    * an arbitrary other SourceSurface. This may return aSourceSurface or some
     692                 :    * other existing surface.
     693                 :    */
     694                 :   virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const = 0;
     695                 : 
     696                 :   /*
     697                 :    * Create a SourceSurface for a type of NativeSurface. This may fail if the
     698                 :    * draw target does not know how to deal with the type of NativeSurface passed
     699                 :    * in.
     700                 :    */
     701                 :   virtual TemporaryRef<SourceSurface>
     702                 :     CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const = 0;
     703                 : 
     704                 :   /*
     705                 :    * Create a DrawTarget whose snapshot is optimized for use with this DrawTarget.
     706                 :    */
     707                 :   virtual TemporaryRef<DrawTarget>
     708                 :     CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const = 0;
     709                 : 
     710                 :   /*
     711                 :    * Create a path builder with the specified fillmode.
     712                 :    *
     713                 :    * We need the fill mode up front because of Direct2D.
     714                 :    * ID2D1SimplifiedGeometrySink requires the fill mode
     715                 :    * to be set before calling BeginFigure().
     716                 :    */
     717                 :   virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FILL_WINDING) const = 0;
     718                 : 
     719                 :   /*
     720                 :    * Create a GradientStops object that holds information about a set of
     721                 :    * gradient stops, this object is required for linear or radial gradient
     722                 :    * patterns to represent the color stops in the gradient.
     723                 :    *
     724                 :    * aStops An array of gradient stops
     725                 :    * aNumStops Number of stops in the array aStops
     726                 :    * aExtendNone This describes how to extend the stop color outside of the
     727                 :    *             gradient area.
     728                 :    */
     729                 :   virtual TemporaryRef<GradientStops>
     730                 :     CreateGradientStops(GradientStop *aStops,
     731                 :                         uint32_t aNumStops,
     732                 :                         ExtendMode aExtendMode = EXTEND_CLAMP) const = 0;
     733                 : 
     734                 :   const Matrix &GetTransform() const { return mTransform; }
     735                 : 
     736                 :   /*
     737                 :    * Set a transform on the surface, this transform is applied at drawing time
     738                 :    * to both the mask and source of the operation.
     739                 :    */
     740               0 :   virtual void SetTransform(const Matrix &aTransform)
     741               0 :     { mTransform = aTransform; mTransformDirty = true; }
     742                 : 
     743                 :   SurfaceFormat GetFormat() { return mFormat; }
     744                 : 
     745                 :   /* Tries to get a native surface for a DrawTarget, this may fail if the
     746                 :    * draw target cannot convert to this surface type.
     747                 :    */
     748               0 :   virtual void *GetNativeSurface(NativeSurfaceType aType) { return NULL; }
     749                 : 
     750                 :   void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) {
     751                 :     mUserData.Add(key, userData, destroy);
     752                 :   }
     753                 :   void *GetUserData(UserDataKey *key) {
     754                 :     return mUserData.Get(key);
     755                 :   }
     756                 : protected:
     757                 :   UserData mUserData;
     758                 :   Matrix mTransform;
     759                 :   bool mTransformDirty : 1;
     760                 : 
     761                 :   SurfaceFormat mFormat;
     762                 : };
     763                 : 
     764                 : class Factory
     765                 : {
     766                 : public:
     767                 :   static TemporaryRef<DrawTarget> CreateDrawTargetForCairoSurface(cairo_surface_t* aSurface);
     768                 : 
     769                 :   static TemporaryRef<DrawTarget>
     770                 :     CreateDrawTarget(BackendType aBackend, const IntSize &aSize, SurfaceFormat aFormat);
     771                 :   
     772                 :   static TemporaryRef<DrawTarget>
     773                 :     CreateDrawTargetForData(BackendType aBackend, unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
     774                 : 
     775                 :   static TemporaryRef<ScaledFont>
     776                 :     CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSize);
     777                 : 
     778                 :   /*
     779                 :    * This creates a scaled font with an associated cairo_scaled_font_t, and
     780                 :    * must be used when using the Cairo backend. The NativeFont and
     781                 :    * cairo_scaled_font_t* parameters must correspond to the same font.
     782                 :    */
     783                 :   static TemporaryRef<ScaledFont>
     784                 :     CreateScaledFontWithCairo(const NativeFont &aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont);
     785                 : 
     786                 :   /*
     787                 :    * This creates a simple data source surface for a certain size. It allocates
     788                 :    * new memory for the surface. This memory is freed when the surface is
     789                 :    * destroyed.
     790                 :    */
     791                 :   static TemporaryRef<DataSourceSurface>
     792                 :     CreateDataSourceSurface(const IntSize &aSize, SurfaceFormat aFormat);
     793                 :   
     794                 :   /*
     795                 :    * This creates a simple data source surface for some existing data. It will
     796                 :    * wrap this data and the data for this source surface. The caller is
     797                 :    * responsible for deallocating the memory only after destruction of the
     798                 :    * surface.
     799                 :    */
     800                 :   static TemporaryRef<DataSourceSurface>
     801                 :     CreateDataSourceSurfaceFromData(unsigned char *aData, int32_t aStride,
     802                 :                                     const IntSize &aSize, SurfaceFormat aFormat);
     803                 : 
     804                 : #ifdef WIN32
     805                 :   static TemporaryRef<DrawTarget> CreateDrawTargetForD3D10Texture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat);
     806                 :   static void SetDirect3D10Device(ID3D10Device1 *aDevice);
     807                 :   static ID3D10Device1 *GetDirect3D10Device();
     808                 : 
     809                 : private:
     810                 :   static ID3D10Device1 *mD3D10Device;
     811                 : #endif
     812                 : };
     813                 : 
     814                 : }
     815                 : }
     816                 : 
     817                 : #endif // _MOZILLA_GFX_2D_H

Generated by: LCOV version 1.7