LCOV - code coverage report
Current view: top level - gfx/2d - DrawTargetWrapAndRecord.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 9 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * vim: set ts=8 sts=2 et sw=2 tw=80:
       3             :  * This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef MOZILLA_GFX_DRAWTARGETWRAPANDRECORD_H_
       8             : #define MOZILLA_GFX_DRAWTARGETWRAPANDRECORD_H_
       9             : 
      10             : #include "2D.h"
      11             : #include "DrawEventRecorder.h"
      12             : 
      13             : namespace mozilla {
      14             : namespace gfx {
      15             : 
      16             : class DrawTargetWrapAndRecord : public DrawTarget
      17             : {
      18             : public:
      19           0 :   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetWrapAndRecord, override)
      20             :   DrawTargetWrapAndRecord(DrawEventRecorder *aRecorder, DrawTarget *aDT, bool aHasData = false);
      21             : 
      22             :   ~DrawTargetWrapAndRecord();
      23             : 
      24           0 :   virtual DrawTargetType GetType() const override { return mFinalDT->GetType(); }
      25           0 :   virtual BackendType GetBackendType() const override { return mFinalDT->GetBackendType(); }
      26           0 :   virtual bool IsRecording() const override { return true; }
      27             : 
      28             :   virtual already_AddRefed<SourceSurface> Snapshot() override;
      29             :   virtual already_AddRefed<SourceSurface> IntoLuminanceSource(LuminanceType aLuminanceType, float aOpacity) override;
      30             : 
      31             :   virtual void DetachAllSnapshots() override;
      32             : 
      33           0 :   virtual IntSize GetSize() override { return mFinalDT->GetSize(); }
      34             : 
      35             :   /* Ensure that the DrawTarget backend has flushed all drawing operations to
      36             :    * this draw target. This must be called before using the backing surface of
      37             :    * this draw target outside of GFX 2D code.
      38             :    */
      39           0 :   virtual void Flush() override { mFinalDT->Flush(); }
      40             : 
      41             :   /*
      42             :    * Draw a surface to the draw target. Possibly doing partial drawing or
      43             :    * applying scaling. No sampling happens outside the source.
      44             :    *
      45             :    * aSurface Source surface to draw
      46             :    * aDest Destination rectangle that this drawing operation should draw to
      47             :    * aSource Source rectangle in aSurface coordinates, this area of aSurface
      48             :    *         will be stretched to the size of aDest.
      49             :    * aOptions General draw options that are applied to the operation
      50             :    * aSurfOptions DrawSurface options that are applied
      51             :    */
      52             :   virtual void DrawSurface(SourceSurface *aSurface,
      53             :                            const Rect &aDest,
      54             :                            const Rect &aSource,
      55             :                            const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
      56             :                            const DrawOptions &aOptions = DrawOptions()) override;
      57             : 
      58             :   virtual void DrawFilter(FilterNode *aNode,
      59             :                           const Rect &aSourceRect,
      60             :                           const Point &aDestPoint,
      61             :                           const DrawOptions &aOptions = DrawOptions()) override;
      62             : 
      63             :   /*
      64             :    * Blend a surface to the draw target with a shadow. The shadow is drawn as a
      65             :    * gaussian blur using a specified sigma. The shadow is clipped to the size
      66             :    * of the input surface, so the input surface should contain a transparent
      67             :    * border the size of the approximate coverage of the blur (3 * aSigma).
      68             :    * NOTE: This function works in device space!
      69             :    *
      70             :    * aSurface Source surface to draw.
      71             :    * aDest Destination point that this drawing operation should draw to.
      72             :    * aColor Color of the drawn shadow
      73             :    * aOffset Offset of the shadow
      74             :    * aSigma Sigma used for the guassian filter kernel
      75             :    * aOperator Composition operator used
      76             :    */
      77             :   virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
      78             :                                      const Point &aDest,
      79             :                                      const Color &aColor,
      80             :                                      const Point &aOffset,
      81             :                                      Float aSigma,
      82             :                                      CompositionOp aOperator) override;
      83             : 
      84             :   /* 
      85             :    * Clear a rectangle on the draw target to transparent black. This will
      86             :    * respect the clipping region and transform.
      87             :    *
      88             :    * aRect Rectangle to clear
      89             :    */
      90             :   virtual void ClearRect(const Rect &aRect) override;
      91             : 
      92             :   /*
      93             :    * This is essentially a 'memcpy' between two surfaces. It moves a pixel
      94             :    * aligned area from the source surface unscaled directly onto the
      95             :    * drawtarget. This ignores both transform and clip.
      96             :    *
      97             :    * aSurface Surface to copy from
      98             :    * aSourceRect Source rectangle to be copied
      99             :    * aDest Destination point to copy the surface to
     100             :    */
     101             :   virtual void CopySurface(SourceSurface *aSurface,
     102             :                            const IntRect &aSourceRect,
     103             :                            const IntPoint &aDestination) override;
     104             : 
     105             :   /*
     106             :    * Fill a rectangle on the DrawTarget with a certain source pattern.
     107             :    *
     108             :    * aRect Rectangle that forms the mask of this filling operation
     109             :    * aPattern Pattern that forms the source of this filling operation
     110             :    * aOptions Options that are applied to this operation
     111             :    */
     112             :   virtual void FillRect(const Rect &aRect,
     113             :                         const Pattern &aPattern,
     114             :                         const DrawOptions &aOptions = DrawOptions()) override;
     115             : 
     116             :   /*
     117             :    * Stroke a rectangle on the DrawTarget with a certain source pattern.
     118             :    *
     119             :    * aRect Rectangle that forms the mask of this stroking operation
     120             :    * aPattern Pattern that forms the source of this stroking operation
     121             :    * aOptions Options that are applied to this operation
     122             :    */
     123             :   virtual void StrokeRect(const Rect &aRect,
     124             :                           const Pattern &aPattern,
     125             :                           const StrokeOptions &aStrokeOptions = StrokeOptions(),
     126             :                           const DrawOptions &aOptions = DrawOptions()) override;
     127             : 
     128             :   /*
     129             :    * Stroke a line on the DrawTarget with a certain source pattern.
     130             :    *
     131             :    * aStart Starting point of the line
     132             :    * aEnd End point of the line
     133             :    * aPattern Pattern that forms the source of this stroking operation
     134             :    * aOptions Options that are applied to this operation
     135             :    */
     136             :   virtual void StrokeLine(const Point &aStart,
     137             :                           const Point &aEnd,
     138             :                           const Pattern &aPattern,
     139             :                           const StrokeOptions &aStrokeOptions = StrokeOptions(),
     140             :                           const DrawOptions &aOptions = DrawOptions()) override;
     141             : 
     142             :   /*
     143             :    * Stroke a path on the draw target with a certain source pattern.
     144             :    *
     145             :    * aPath Path that is to be stroked
     146             :    * aPattern Pattern that should be used for the stroke
     147             :    * aStrokeOptions Stroke options used for this operation
     148             :    * aOptions Draw options used for this operation
     149             :    */
     150             :   virtual void Stroke(const Path *aPath,
     151             :                       const Pattern &aPattern,
     152             :                       const StrokeOptions &aStrokeOptions = StrokeOptions(),
     153             :                       const DrawOptions &aOptions = DrawOptions()) override;
     154             :   
     155             :   /*
     156             :    * Fill a path on the draw target with a certain source pattern.
     157             :    *
     158             :    * aPath Path that is to be filled
     159             :    * aPattern Pattern that should be used for the fill
     160             :    * aOptions Draw options used for this operation
     161             :    */
     162             :   virtual void Fill(const Path *aPath,
     163             :                     const Pattern &aPattern,
     164             :                     const DrawOptions &aOptions = DrawOptions()) override;
     165             : 
     166             :   /*
     167             :    * Fill a series of clyphs on the draw target with a certain source pattern.
     168             :    */
     169             :   virtual void FillGlyphs(ScaledFont *aFont,
     170             :                           const GlyphBuffer &aBuffer,
     171             :                           const Pattern &aPattern,
     172             :                           const DrawOptions &aOptions = DrawOptions(),
     173             :                           const GlyphRenderingOptions *aRenderingOptions = nullptr) override;
     174             : 
     175             :   /*
     176             :    * This takes a source pattern and a mask, and composites the source pattern
     177             :    * onto the destination surface using the alpha channel of the mask pattern
     178             :    * as a mask for the operation.
     179             :    *
     180             :    * aSource Source pattern
     181             :    * aMask Mask pattern
     182             :    * aOptions Drawing options
     183             :    */
     184             :   virtual void Mask(const Pattern &aSource,
     185             :                     const Pattern &aMask,
     186             :                     const DrawOptions &aOptions = DrawOptions()) override;
     187             : 
     188             :   virtual void MaskSurface(const Pattern &aSource,
     189             :                            SourceSurface *aMask,
     190             :                            Point aOffset,
     191             :                            const DrawOptions &aOptions = DrawOptions()) override;
     192             : 
     193             :   /*
     194             :    * Push a clip to the DrawTarget.
     195             :    *
     196             :    * aPath The path to clip to
     197             :    */
     198             :   virtual void PushClip(const Path *aPath) override;
     199             : 
     200             :   /*
     201             :    * Push an axis-aligned rectangular clip to the DrawTarget. This rectangle
     202             :    * is specified in user space.
     203             :    *
     204             :    * aRect The rect to clip to
     205             :    */
     206             :   virtual void PushClipRect(const Rect &aRect) override;
     207             : 
     208             :   /* Pop a clip from the DrawTarget. A pop without a corresponding push will
     209             :    * be ignored.
     210             :    */
     211             :   virtual void PopClip() override;
     212             : 
     213             :   /**
     214             :    * Push a 'layer' to the DrawTarget, a layer is a temporary surface that all
     215             :    * drawing will be redirected to, this is used for example to support group
     216             :    * opacity or the masking of groups. Clips must be balanced within a layer,
     217             :    * i.e. between a matching PushLayer/PopLayer pair there must be as many
     218             :    * PushClip(Rect) calls as there are PopClip calls.
     219             :    *
     220             :    * @param aOpaque Whether the layer will be opaque
     221             :    * @param aOpacity Opacity of the layer
     222             :    * @param aMask Mask applied to the layer
     223             :    * @param aMaskTransform Transform applied to the layer mask
     224             :    * @param aBounds Optional bounds in device space to which the layer is
     225             :    *                limited in size.
     226             :    * @param aCopyBackground Whether to copy the background into the layer, this
     227             :    *                        is only supported when aOpaque is true.
     228             :    */
     229             :   virtual void PushLayer(bool aOpaque, Float aOpacity,
     230             :                          SourceSurface* aMask,
     231             :                          const Matrix& aMaskTransform,
     232             :                          const IntRect& aBounds = IntRect(),
     233             :                          bool aCopyBackground = false) override;
     234             : 
     235             :   /**
     236             :    * This balances a call to PushLayer and proceeds to blend the layer back
     237             :    * onto the background. This blend will blend the temporary surface back
     238             :    * onto the target in device space using POINT sampling and operator over.
     239             :    */
     240             :   virtual void PopLayer() override;
     241             : 
     242             :   /*
     243             :    * Create a SourceSurface optimized for use with this DrawTarget from
     244             :    * existing bitmap data in memory.
     245             :    *
     246             :    * The SourceSurface does not take ownership of aData, and may be freed at any time.
     247             :    */
     248             :   virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
     249             :                                                                   const IntSize &aSize,
     250             :                                                                   int32_t aStride,
     251             :                                                                   SurfaceFormat aFormat) const override;
     252             : 
     253             :   /*
     254             :    * Create a SourceSurface optimized for use with this DrawTarget from
     255             :    * an arbitrary other SourceSurface. This may return aSourceSurface or some
     256             :    * other existing surface.
     257             :    */
     258             :   virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override;
     259             : 
     260             :   /*
     261             :    * Create a SourceSurface for a type of NativeSurface. This may fail if the
     262             :    * draw target does not know how to deal with the type of NativeSurface passed
     263             :    * in.
     264             :    */
     265             :   virtual already_AddRefed<SourceSurface>
     266             :     CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override;
     267             : 
     268             :   /*
     269             :    * Create a DrawTarget whose snapshot is optimized for use with this DrawTarget.
     270             :    */
     271             :   virtual already_AddRefed<DrawTarget>
     272             :     CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override;
     273             : 
     274             :   /*
     275             :    * Create a path builder with the specified fillmode.
     276             :    *
     277             :    * We need the fill mode up front because of Direct2D.
     278             :    * ID2D1SimplifiedGeometrySink requires the fill mode
     279             :    * to be set before calling BeginFigure().
     280             :    */
     281             :   virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override;
     282             : 
     283             :   /*
     284             :    * Create a GradientStops object that holds information about a set of
     285             :    * gradient stops, this object is required for linear or radial gradient
     286             :    * patterns to represent the color stops in the gradient.
     287             :    *
     288             :    * aStops An array of gradient stops
     289             :    * aNumStops Number of stops in the array aStops
     290             :    * aExtendNone This describes how to extend the stop color outside of the
     291             :    *             gradient area.
     292             :    */
     293             :   virtual already_AddRefed<GradientStops>
     294             :     CreateGradientStops(GradientStop *aStops,
     295             :                         uint32_t aNumStops,
     296             :                         ExtendMode aExtendMode = ExtendMode::CLAMP) const override;
     297             : 
     298             :   virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override;
     299             : 
     300             :   /*
     301             :    * Set a transform on the surface, this transform is applied at drawing time
     302             :    * to both the mask and source of the operation.
     303             :    */
     304             :   virtual void SetTransform(const Matrix &aTransform) override;
     305             : 
     306             :   /* Tries to get a native surface for a DrawTarget, this may fail if the
     307             :    * draw target cannot convert to this surface type.
     308             :    */
     309           0 :   virtual void *GetNativeSurface(NativeSurfaceType aType) override { return mFinalDT->GetNativeSurface(aType); }
     310             : 
     311           0 :   virtual bool IsCurrentGroupOpaque() override {
     312           0 :     return mFinalDT->IsCurrentGroupOpaque();
     313             :   }
     314             : 
     315             : private:
     316             :   /**
     317             :    * Used for creating a DrawTargetWrapAndRecord for a CreateSimilarDrawTarget call.
     318             :    * We have to call CreateSimilarDrawTarget on mFinalDT up front and pass it in
     319             :    * as it can fail.
     320             :    *
     321             :    * @param aDT DrawTargetWrapAndRecord on which CreateSimilarDrawTarget was called
     322             :    * @param aSimilarDT Similar DrawTarget created from aDT.mFinalDT.
     323             :    */
     324             :   DrawTargetWrapAndRecord(const DrawTargetWrapAndRecord *aDT,
     325             :                       DrawTarget *aSimilarDT);
     326             : 
     327             :   Path *GetPathForPathRecording(const Path *aPath) const;
     328             :   already_AddRefed<PathRecording> EnsurePathStored(const Path *aPath);
     329             :   void EnsurePatternDependenciesStored(const Pattern &aPattern);
     330             : 
     331             :   RefPtr<DrawEventRecorderPrivate> mRecorder;
     332             :   RefPtr<DrawTarget> mFinalDT;
     333             : };
     334             : 
     335             : } // namespace gfx
     336             : } // namespace mozilla
     337             : 
     338             : #endif /* MOZILLA_GFX_DRAWTARGETWRAPANDRECORD_H_ */

Generated by: LCOV version 1.13