1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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
) : mSize(aSize
) {}
34 * Draw into aContext filling aFillRect, possibly repeating, using
35 * aSamplingFilter. aTransform is a userspace to "image"space matrix. For
36 * example, if Draw draws using a gfxPattern, this is the matrix that should
37 * be set on the pattern prior to rendering it.
38 * @return whether drawing was successful
40 virtual bool Draw(gfxContext
* aContext
, const gfxRect
& aFillRect
,
41 mozilla::gfx::ExtendMode aExtendMode
,
42 const mozilla::gfx::SamplingFilter aSamplingFilter
,
43 gfxFloat aOpacity
= 1.0,
44 const gfxMatrix
& aTransform
= gfxMatrix()) = 0;
46 virtual bool DrawWithSamplingRect(
47 DrawTarget
* aDrawTarget
, CompositionOp aOp
, AntialiasMode aAntialiasMode
,
48 const gfxRect
& aFillRect
, const gfxRect
& aSamplingRect
,
49 mozilla::gfx::ExtendMode aExtendMode
,
50 const mozilla::gfx::SamplingFilter aSamplingFilter
,
51 gfxFloat aOpacity
= 1.0) {
55 virtual mozilla::gfx::IntSize
Size() { return mSize
; }
58 // Protected destructor, to discourage deletion outside of Release():
59 virtual ~gfxDrawable() = default;
61 const mozilla::gfx::IntSize mSize
;
66 * A convenience implementation of gfxDrawable for surfaces.
68 class gfxSurfaceDrawable
: public gfxDrawable
{
70 gfxSurfaceDrawable(mozilla::gfx::SourceSurface
* aSurface
,
71 const mozilla::gfx::IntSize aSize
,
72 const gfxMatrix aTransform
= gfxMatrix());
73 virtual ~gfxSurfaceDrawable() = default;
75 virtual bool Draw(gfxContext
* aContext
, const gfxRect
& aFillRect
,
76 mozilla::gfx::ExtendMode aExtendMode
,
77 const mozilla::gfx::SamplingFilter aSamplingFilter
,
78 gfxFloat aOpacity
= 1.0,
79 const gfxMatrix
& aTransform
= gfxMatrix()) override
;
81 virtual bool DrawWithSamplingRect(
82 DrawTarget
* aDrawTarget
, CompositionOp aOp
, AntialiasMode aAntialiasMode
,
83 const gfxRect
& aFillRect
, const gfxRect
& aSamplingRect
,
84 mozilla::gfx::ExtendMode aExtendMode
,
85 const mozilla::gfx::SamplingFilter aSamplingFilter
,
86 gfxFloat aOpacity
= 1.0) override
;
89 void DrawInternal(DrawTarget
* aDrawTarget
, CompositionOp aOp
,
90 AntialiasMode aAntialiasMode
, const gfxRect
& aFillRect
,
91 const mozilla::gfx::IntRect
& aSamplingRect
,
92 mozilla::gfx::ExtendMode aExtendMode
,
93 const mozilla::gfx::SamplingFilter aSamplingFilter
,
95 const gfxMatrix
& aTransform
= gfxMatrix());
97 RefPtr
<mozilla::gfx::SourceSurface
> mSourceSurface
;
98 const gfxMatrix mTransform
;
103 * A simple drawing functor.
105 class gfxDrawingCallback
{
106 NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback
)
108 // Protected destructor, to discourage deletion outside of Release():
109 virtual ~gfxDrawingCallback() = default;
113 * Draw into aContext filling aFillRect using aSamplingFilter.
114 * aTransform is a userspace to "image"space matrix. For example, if Draw
115 * draws using a gfxPattern, this is the matrix that should be set on the
116 * pattern prior to rendering it.
117 * @return whether drawing was successful
119 virtual bool operator()(gfxContext
* aContext
, const gfxRect
& aFillRect
,
120 const mozilla::gfx::SamplingFilter aSamplingFilter
,
121 const gfxMatrix
& aTransform
= gfxMatrix()) = 0;
125 * gfxCallbackDrawable
126 * A convenience implementation of gfxDrawable for callbacks.
128 class gfxCallbackDrawable
: public gfxDrawable
{
130 gfxCallbackDrawable(gfxDrawingCallback
* aCallback
,
131 const mozilla::gfx::IntSize aSize
);
132 virtual ~gfxCallbackDrawable() = default;
134 virtual bool Draw(gfxContext
* aContext
, const gfxRect
& aFillRect
,
135 mozilla::gfx::ExtendMode aExtendMode
,
136 const mozilla::gfx::SamplingFilter aSamplingFilter
,
137 gfxFloat aOpacity
= 1.0,
138 const gfxMatrix
& aTransform
= gfxMatrix()) override
;
141 already_AddRefed
<gfxSurfaceDrawable
> MakeSurfaceDrawable(
142 gfxContext
* aContext
, mozilla::gfx::SamplingFilter aSamplingFilter
=
143 mozilla::gfx::SamplingFilter::LINEAR
);
145 RefPtr
<gfxDrawingCallback
> mCallback
;
146 RefPtr
<gfxSurfaceDrawable
> mSurfaceDrawable
;
151 * A convenience implementation of gfxDrawable for patterns.
153 class gfxPatternDrawable
: public gfxDrawable
{
155 gfxPatternDrawable(gfxPattern
* aPattern
, const mozilla::gfx::IntSize aSize
);
156 virtual ~gfxPatternDrawable();
158 virtual bool Draw(gfxContext
* aContext
, const gfxRect
& aFillRect
,
159 mozilla::gfx::ExtendMode aExtendMode
,
160 const mozilla::gfx::SamplingFilter aSamplingFilter
,
161 gfxFloat aOpacity
= 1.0,
162 const gfxMatrix
& aTransform
= gfxMatrix()) override
;
165 already_AddRefed
<gfxCallbackDrawable
> MakeCallbackDrawable();
167 RefPtr
<gfxPattern
> mPattern
;
170 #endif /* GFX_DRAWABLE_H */