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/. */
10 #include "gfxMatrix.h"
12 #include "mozilla/gfx/2D.h"
13 #include "mozilla/gfx/Types.h"
14 #include "nsISupportsImpl.h"
21 * An Interface representing something that has an intrinsic size and can draw
25 NS_INLINE_DECL_REFCOUNTING(gfxDrawable
)
27 typedef mozilla::gfx::AntialiasMode AntialiasMode
;
28 typedef mozilla::gfx::CompositionOp CompositionOp
;
29 typedef mozilla::gfx::DrawTarget DrawTarget
;
31 explicit gfxDrawable(const mozilla::gfx::IntSize aSize
)
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
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;
48 virtual bool DrawWithSamplingRect(DrawTarget
* aDrawTarget
,
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)
60 virtual mozilla::gfx::IntSize
Size() { return mSize
; }
63 // Protected destructor, to discourage deletion outside of Release():
64 virtual ~gfxDrawable() {}
66 const mozilla::gfx::IntSize mSize
;
71 * A convenience implementation of gfxDrawable for surfaces.
73 class gfxSurfaceDrawable
: public gfxDrawable
{
75 gfxSurfaceDrawable(mozilla::gfx::SourceSurface
* aSurface
, const mozilla::gfx::IntSize aSize
,
76 const gfxMatrix aTransform
= gfxMatrix());
77 virtual ~gfxSurfaceDrawable() {}
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()) override
;
86 virtual bool DrawWithSamplingRect(DrawTarget
* aDrawTarget
,
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) override
;
96 void DrawInternal(DrawTarget
* aDrawTarget
,
98 AntialiasMode aAntialiasMode
,
99 const gfxRect
& aFillRect
,
100 const mozilla::gfx::IntRect
& aSamplingRect
,
101 mozilla::gfx::ExtendMode aExtendMode
,
102 const mozilla::gfx::SamplingFilter aSamplingFilter
,
104 const gfxMatrix
& aTransform
= gfxMatrix());
106 RefPtr
<mozilla::gfx::SourceSurface
> mSourceSurface
;
107 const gfxMatrix mTransform
;
112 * A simple drawing functor.
114 class gfxDrawingCallback
{
115 NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback
)
117 // Protected destructor, to discourage deletion outside of Release():
118 virtual ~gfxDrawingCallback() {}
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
128 virtual bool operator()(gfxContext
* aContext
,
129 const gfxRect
& aFillRect
,
130 const mozilla::gfx::SamplingFilter aSamplingFilter
,
131 const gfxMatrix
& aTransform
= gfxMatrix()) = 0;
136 * gfxCallbackDrawable
137 * A convenience implementation of gfxDrawable for callbacks.
139 class gfxCallbackDrawable
: public gfxDrawable
{
141 gfxCallbackDrawable(gfxDrawingCallback
* aCallback
, const mozilla::gfx::IntSize aSize
);
142 virtual ~gfxCallbackDrawable() {}
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()) override
;
152 already_AddRefed
<gfxSurfaceDrawable
>
153 MakeSurfaceDrawable(gfxContext
* aContext
,
154 mozilla::gfx::SamplingFilter aSamplingFilter
=
155 mozilla::gfx::SamplingFilter::LINEAR
);
157 RefPtr
<gfxDrawingCallback
> mCallback
;
158 RefPtr
<gfxSurfaceDrawable
> mSurfaceDrawable
;
163 * A convenience implementation of gfxDrawable for patterns.
165 class gfxPatternDrawable
: public gfxDrawable
{
167 gfxPatternDrawable(gfxPattern
* aPattern
,
168 const mozilla::gfx::IntSize aSize
);
169 virtual ~gfxPatternDrawable();
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()) override
;
179 already_AddRefed
<gfxCallbackDrawable
> MakeCallbackDrawable();
181 RefPtr
<gfxPattern
> mPattern
;
184 #endif /* GFX_DRAWABLE_H */