LCOV - code coverage report
Current view: top level - gfx/thebes - gfxDrawable.h (source / functions) Hit Total Coverage
Test: output.info Lines: 9 13 69.2 %
Date: 2017-07-14 16:53:18 Functions: 12 18 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef GFX_DRAWABLE_H
       7             : #define GFX_DRAWABLE_H
       8             : 
       9             : #include "gfxRect.h"
      10             : #include "gfxMatrix.h"
      11             : #include "gfxTypes.h"
      12             : #include "mozilla/gfx/2D.h"
      13             : #include "mozilla/gfx/Types.h"
      14             : #include "nsISupportsImpl.h"
      15             : 
      16             : class gfxContext;
      17             : class gfxPattern;
      18             : 
      19             : /**
      20             :  * gfxDrawable
      21             :  * An Interface representing something that has an intrinsic size and can draw
      22             :  * itself repeatedly.
      23             :  */
      24             : class gfxDrawable {
      25         504 :     NS_INLINE_DECL_REFCOUNTING(gfxDrawable)
      26             : public:
      27             :     typedef mozilla::gfx::AntialiasMode AntialiasMode;
      28             :     typedef mozilla::gfx::CompositionOp CompositionOp;
      29             :     typedef mozilla::gfx::DrawTarget DrawTarget;
      30             : 
      31         126 :     explicit gfxDrawable(const mozilla::gfx::IntSize aSize)
      32         126 :      : mSize(aSize) {}
      33             : 
      34             :     /**
      35             :      * Draw into aContext filling aFillRect, possibly repeating, using aSamplingFilter.
      36             :      * aTransform is a userspace to "image"space matrix. For example, if Draw
      37             :      * draws using a gfxPattern, this is the matrix that should be set on the
      38             :      * pattern prior to rendering it.
      39             :      *  @return whether drawing was successful
      40             :      */
      41             :     virtual bool Draw(gfxContext* aContext,
      42             :                         const gfxRect& aFillRect,
      43             :                         mozilla::gfx::ExtendMode aExtendMode,
      44             :                         const mozilla::gfx::SamplingFilter aSamplingFilter,
      45             :                         gfxFloat aOpacity = 1.0,
      46             :                         const gfxMatrix& aTransform = gfxMatrix()) = 0;
      47             : 
      48           0 :     virtual bool DrawWithSamplingRect(DrawTarget* aDrawTarget,
      49             :                                       CompositionOp aOp,
      50             :                                       AntialiasMode aAntialiasMode,
      51             :                                       const gfxRect& aFillRect,
      52             :                                       const gfxRect& aSamplingRect,
      53             :                                       mozilla::gfx::ExtendMode aExtendMode,
      54             :                                       const mozilla::gfx::SamplingFilter aSamplingFilter,
      55             :                                       gfxFloat aOpacity = 1.0)
      56             :     {
      57           0 :         return false;
      58             :     }
      59             : 
      60           0 :     virtual mozilla::gfx::IntSize Size() { return mSize; }
      61             : 
      62             : protected:
      63             :     // Protected destructor, to discourage deletion outside of Release():
      64         126 :     virtual ~gfxDrawable() {}
      65             : 
      66             :     const mozilla::gfx::IntSize mSize;
      67             : };
      68             : 
      69             : /**
      70             :  * gfxSurfaceDrawable
      71             :  * A convenience implementation of gfxDrawable for surfaces.
      72             :  */
      73             : class gfxSurfaceDrawable : public gfxDrawable {
      74             : public:
      75             :     gfxSurfaceDrawable(mozilla::gfx::SourceSurface* aSurface, const mozilla::gfx::IntSize aSize,
      76             :                        const gfxMatrix aTransform = gfxMatrix());
      77         324 :     virtual ~gfxSurfaceDrawable() {}
      78             : 
      79             :     virtual bool Draw(gfxContext* aContext,
      80             :                         const gfxRect& aFillRect,
      81             :                         mozilla::gfx::ExtendMode aExtendMode,
      82             :                         const mozilla::gfx::SamplingFilter aSamplingFilter,
      83             :                         gfxFloat aOpacity = 1.0,
      84             :                         const gfxMatrix& aTransform = gfxMatrix());
      85             : 
      86             :     virtual bool DrawWithSamplingRect(DrawTarget* aDrawTarget,
      87             :                                       CompositionOp aOp,
      88             :                                       AntialiasMode aAntialiasMode,
      89             :                                       const gfxRect& aFillRect,
      90             :                                       const gfxRect& aSamplingRect,
      91             :                                       mozilla::gfx::ExtendMode aExtendMode,
      92             :                                       const mozilla::gfx::SamplingFilter aSamplingFilter,
      93             :                                       gfxFloat aOpacity = 1.0);
      94             : 
      95             : protected:
      96             :     void DrawInternal(DrawTarget* aDrawTarget,
      97             :                       CompositionOp aOp,
      98             :                       AntialiasMode aAntialiasMode,
      99             :                       const gfxRect& aFillRect,
     100             :                       const mozilla::gfx::IntRect& aSamplingRect,
     101             :                       mozilla::gfx::ExtendMode aExtendMode,
     102             :                       const mozilla::gfx::SamplingFilter aSamplingFilter,
     103             :                       gfxFloat aOpacity,
     104             :                       const gfxMatrix& aTransform = gfxMatrix());
     105             : 
     106             :     RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
     107             :     const gfxMatrix mTransform;
     108             : };
     109             : 
     110             : /**
     111             :  * gfxDrawingCallback
     112             :  * A simple drawing functor.
     113             :  */
     114          18 : class gfxDrawingCallback {
     115          72 :     NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback)
     116             : protected:
     117             :     // Protected destructor, to discourage deletion outside of Release():
     118          18 :     virtual ~gfxDrawingCallback() {}
     119             : 
     120             : public:
     121             :     /**
     122             :      * Draw into aContext filling aFillRect using aSamplingFilter.
     123             :      * aTransform is a userspace to "image"space matrix. For example, if Draw
     124             :      * draws using a gfxPattern, this is the matrix that should be set on the
     125             :      * pattern prior to rendering it.
     126             :      *  @return whether drawing was successful
     127             :      */
     128             :     virtual bool operator()(gfxContext* aContext,
     129             :                             const gfxRect& aFillRect,
     130             :                             const mozilla::gfx::SamplingFilter aSamplingFilter,
     131             :                             const gfxMatrix& aTransform = gfxMatrix()) = 0;
     132             : 
     133             : };
     134             : 
     135             : /**
     136             :  * gfxCallbackDrawable
     137             :  * A convenience implementation of gfxDrawable for callbacks.
     138             :  */
     139             : class gfxCallbackDrawable : public gfxDrawable {
     140             : public:
     141             :     gfxCallbackDrawable(gfxDrawingCallback* aCallback, const mozilla::gfx::IntSize aSize);
     142          54 :     virtual ~gfxCallbackDrawable() {}
     143             : 
     144             :     virtual bool Draw(gfxContext* aContext,
     145             :                       const gfxRect& aFillRect,
     146             :                       mozilla::gfx::ExtendMode aExtendMode,
     147             :                       const mozilla::gfx::SamplingFilter aSamplingFilter,
     148             :                       gfxFloat aOpacity = 1.0,
     149             :                       const gfxMatrix& aTransform = gfxMatrix());
     150             : 
     151             : protected:
     152             :     already_AddRefed<gfxSurfaceDrawable>
     153             :     MakeSurfaceDrawable(gfxContext* aContext,
     154             :                         mozilla::gfx::SamplingFilter aSamplingFilter =
     155             :                         mozilla::gfx::SamplingFilter::LINEAR);
     156             : 
     157             :     RefPtr<gfxDrawingCallback> mCallback;
     158             :     RefPtr<gfxSurfaceDrawable> mSurfaceDrawable;
     159             : };
     160             : 
     161             : /**
     162             :  * gfxPatternDrawable
     163             :  * A convenience implementation of gfxDrawable for patterns.
     164             :  */
     165           0 : class gfxPatternDrawable : public gfxDrawable {
     166             : public:
     167             :     gfxPatternDrawable(gfxPattern* aPattern,
     168             :                        const mozilla::gfx::IntSize aSize);
     169             :     virtual ~gfxPatternDrawable();
     170             : 
     171             :     virtual bool Draw(gfxContext* aContext,
     172             :                       const gfxRect& aFillRect,
     173             :                       mozilla::gfx::ExtendMode aExtendMode,
     174             :                       const mozilla::gfx::SamplingFilter aSamplingFilter,
     175             :                       gfxFloat aOpacity = 1.0,
     176             :                       const gfxMatrix& aTransform = gfxMatrix());
     177             : 
     178             : 
     179             : protected:
     180             :     already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
     181             : 
     182             :     RefPtr<gfxPattern> mPattern;
     183             : };
     184             : 
     185             : #endif /* GFX_DRAWABLE_H */

Generated by: LCOV version 1.13