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/. */
9 #include "nsISupportsImpl.h"
10 #include "nsAutoPtr.h"
14 #include "gfxMatrix.h"
15 #include "gfxPattern.h"
22 * An Interface representing something that has an intrinsic size and can draw
25 class THEBES_API gfxDrawable
{
26 NS_INLINE_DECL_REFCOUNTING(gfxDrawable
)
28 gfxDrawable(const gfxIntSize aSize
)
30 virtual ~gfxDrawable() {}
33 * Draw into aContext filling aFillRect, possibly repeating, using aFilter.
34 * aTransform is a userspace to "image"space matrix. For example, if Draw
35 * draws using a gfxPattern, this is the matrix that should be set on the
36 * pattern prior to rendering it.
37 * @return whether drawing was successful
39 virtual bool Draw(gfxContext
* aContext
,
40 const gfxRect
& aFillRect
,
42 const gfxPattern::GraphicsFilter
& aFilter
,
43 const gfxMatrix
& aTransform
= gfxMatrix()) = 0;
44 virtual gfxIntSize
Size() { return mSize
; }
47 const gfxIntSize mSize
;
52 * A convenience implementation of gfxDrawable for surfaces.
54 class THEBES_API gfxSurfaceDrawable
: public gfxDrawable
{
56 gfxSurfaceDrawable(gfxASurface
* aSurface
, const gfxIntSize aSize
,
57 const gfxMatrix aTransform
= gfxMatrix());
58 virtual ~gfxSurfaceDrawable() {}
60 virtual bool Draw(gfxContext
* aContext
,
61 const gfxRect
& aFillRect
,
63 const gfxPattern::GraphicsFilter
& aFilter
,
64 const gfxMatrix
& aTransform
= gfxMatrix());
67 nsRefPtr
<gfxASurface
> mSurface
;
68 const gfxMatrix mTransform
;
73 * A simple drawing functor.
75 class THEBES_API gfxDrawingCallback
{
76 NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback
)
78 virtual ~gfxDrawingCallback() {}
81 * Draw into aContext filling aFillRect using aFilter.
82 * aTransform is a userspace to "image"space matrix. For example, if Draw
83 * draws using a gfxPattern, this is the matrix that should be set on the
84 * pattern prior to rendering it.
85 * @return whether drawing was successful
87 virtual bool operator()(gfxContext
* aContext
,
88 const gfxRect
& aFillRect
,
89 const gfxPattern::GraphicsFilter
& aFilter
,
90 const gfxMatrix
& aTransform
= gfxMatrix()) = 0;
96 * A convenience implementation of gfxDrawable for callbacks.
98 class THEBES_API gfxCallbackDrawable
: public gfxDrawable
{
100 gfxCallbackDrawable(gfxDrawingCallback
* aCallback
, const gfxIntSize aSize
);
101 virtual ~gfxCallbackDrawable() {}
103 virtual bool Draw(gfxContext
* aContext
,
104 const gfxRect
& aFillRect
,
106 const gfxPattern::GraphicsFilter
& aFilter
,
107 const gfxMatrix
& aTransform
= gfxMatrix());
110 already_AddRefed
<gfxSurfaceDrawable
> MakeSurfaceDrawable(const gfxPattern::GraphicsFilter aFilter
= gfxPattern::FILTER_FAST
);
112 nsRefPtr
<gfxDrawingCallback
> mCallback
;
113 nsRefPtr
<gfxSurfaceDrawable
> mSurfaceDrawable
;
118 * A convenience implementation of gfxDrawable for patterns.
120 class THEBES_API gfxPatternDrawable
: public gfxDrawable
{
122 gfxPatternDrawable(gfxPattern
* aPattern
,
123 const gfxIntSize aSize
);
124 virtual ~gfxPatternDrawable() {}
126 virtual bool Draw(gfxContext
* aContext
,
127 const gfxRect
& aFillRect
,
129 const gfxPattern::GraphicsFilter
& aFilter
,
130 const gfxMatrix
& aTransform
= gfxMatrix());
133 already_AddRefed
<gfxCallbackDrawable
> MakeCallbackDrawable();
135 nsRefPtr
<gfxPattern
> mPattern
;
138 #endif /* GFX_DRAWABLE_H */