gfx/thebes/gfxDrawable.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     6 #ifndef GFX_DRAWABLE_H
     7 #define GFX_DRAWABLE_H
     9 #include "nsAutoPtr.h"
    10 #include "gfxRect.h"
    11 #include "gfxMatrix.h"
    12 #include "GraphicsFilter.h"
    13 #include "mozilla/gfx/2D.h"
    15 class gfxASurface;
    16 class gfxImageSurface;
    17 class gfxContext;
    18 class gfxPattern;
    20 /**
    21  * gfxDrawable
    22  * An Interface representing something that has an intrinsic size and can draw
    23  * itself repeatedly.
    24  */
    25 class gfxDrawable {
    26     NS_INLINE_DECL_REFCOUNTING(gfxDrawable)
    27 public:
    28     gfxDrawable(const gfxIntSize aSize)
    29      : mSize(aSize) {}
    31     /**
    32      * Draw into aContext filling aFillRect, possibly repeating, using aFilter.
    33      * aTransform is a userspace to "image"space matrix. For example, if Draw
    34      * draws using a gfxPattern, this is the matrix that should be set on the
    35      * pattern prior to rendering it.
    36      *  @return whether drawing was successful
    37      */
    38     virtual bool Draw(gfxContext* aContext,
    39                         const gfxRect& aFillRect,
    40                         bool aRepeat,
    41                         const GraphicsFilter& aFilter,
    42                         const gfxMatrix& aTransform = gfxMatrix()) = 0;
    43     virtual already_AddRefed<gfxImageSurface> GetAsImageSurface() { return nullptr; }
    44     virtual gfxIntSize Size() { return mSize; }
    46 protected:
    47     // Protected destructor, to discourage deletion outside of Release():
    48     virtual ~gfxDrawable() {}
    50     const gfxIntSize mSize;
    51 };
    53 /**
    54  * gfxSurfaceDrawable
    55  * A convenience implementation of gfxDrawable for surfaces.
    56  */
    57 class gfxSurfaceDrawable : public gfxDrawable {
    58 public:
    59     gfxSurfaceDrawable(gfxASurface* aSurface, const gfxIntSize aSize,
    60                        const gfxMatrix aTransform = gfxMatrix());
    61     gfxSurfaceDrawable(mozilla::gfx::DrawTarget* aDT, const gfxIntSize aSize,
    62                        const gfxMatrix aTransform = gfxMatrix());
    63     gfxSurfaceDrawable(mozilla::gfx::SourceSurface* aSurface, const gfxIntSize aSize,
    64                        const gfxMatrix aTransform = gfxMatrix());
    65     virtual ~gfxSurfaceDrawable() {}
    67     virtual bool Draw(gfxContext* aContext,
    68                         const gfxRect& aFillRect,
    69                         bool aRepeat,
    70                         const GraphicsFilter& aFilter,
    71                         const gfxMatrix& aTransform = gfxMatrix());
    73     virtual already_AddRefed<gfxImageSurface> GetAsImageSurface();
    75 protected:
    76     nsRefPtr<gfxASurface> mSurface;
    77     mozilla::RefPtr<mozilla::gfx::DrawTarget> mDrawTarget;
    78     mozilla::RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
    79     const gfxMatrix mTransform;
    80 };
    82 /**
    83  * gfxDrawingCallback
    84  * A simple drawing functor.
    85  */
    86 class gfxDrawingCallback {
    87     NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback)
    88 protected:
    89     // Protected destructor, to discourage deletion outside of Release():
    90     virtual ~gfxDrawingCallback() {}
    92 public:
    93     /**
    94      * Draw into aContext filling aFillRect using aFilter.
    95      * aTransform is a userspace to "image"space matrix. For example, if Draw
    96      * draws using a gfxPattern, this is the matrix that should be set on the
    97      * pattern prior to rendering it.
    98      *  @return whether drawing was successful
    99      */
   100     virtual bool operator()(gfxContext* aContext,
   101                               const gfxRect& aFillRect,
   102                               const GraphicsFilter& aFilter,
   103                               const gfxMatrix& aTransform = gfxMatrix()) = 0;
   105 };
   107 /**
   108  * gfxCallbackDrawable
   109  * A convenience implementation of gfxDrawable for callbacks.
   110  */
   111 class gfxCallbackDrawable : public gfxDrawable {
   112 public:
   113     gfxCallbackDrawable(gfxDrawingCallback* aCallback, const gfxIntSize aSize);
   114     virtual ~gfxCallbackDrawable() {}
   116     virtual bool Draw(gfxContext* aContext,
   117                         const gfxRect& aFillRect,
   118                         bool aRepeat,
   119                         const GraphicsFilter& aFilter,
   120                         const gfxMatrix& aTransform = gfxMatrix());
   122 protected:
   123     already_AddRefed<gfxSurfaceDrawable> MakeSurfaceDrawable(const GraphicsFilter aFilter = GraphicsFilter::FILTER_FAST);
   125     nsRefPtr<gfxDrawingCallback> mCallback;
   126     nsRefPtr<gfxSurfaceDrawable> mSurfaceDrawable;
   127 };
   129 /**
   130  * gfxPatternDrawable
   131  * A convenience implementation of gfxDrawable for patterns.
   132  */
   133 class gfxPatternDrawable : public gfxDrawable {
   134 public:
   135     gfxPatternDrawable(gfxPattern* aPattern,
   136                        const gfxIntSize aSize);
   137     virtual ~gfxPatternDrawable();
   139     virtual bool Draw(gfxContext* aContext,
   140                         const gfxRect& aFillRect,
   141                         bool aRepeat,
   142                         const GraphicsFilter& aFilter,
   143                         const gfxMatrix& aTransform = gfxMatrix());
   145 protected:
   146     already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
   148     nsRefPtr<gfxPattern> mPattern;
   149 };
   151 #endif /* GFX_DRAWABLE_H */

mercurial