Bug 1492908 [wpt PR 13122] - Update wpt metadata, a=testonly
[gecko.git] / gfx / thebes / gfxDrawable.h
blob646b08450391c68bd2156c73a76de85de4ed549a
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 "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"
16 class gfxContext;
17 class gfxPattern;
19 /**
20 * gfxDrawable
21 * An Interface representing something that has an intrinsic size and can draw
22 * itself repeatedly.
24 class gfxDrawable {
25 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;
31 explicit gfxDrawable(const mozilla::gfx::IntSize aSize)
32 : mSize(aSize) {}
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
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,
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)
57 return false;
60 virtual mozilla::gfx::IntSize Size() { return mSize; }
62 protected:
63 // Protected destructor, to discourage deletion outside of Release():
64 virtual ~gfxDrawable() {}
66 const mozilla::gfx::IntSize mSize;
69 /**
70 * gfxSurfaceDrawable
71 * A convenience implementation of gfxDrawable for surfaces.
73 class gfxSurfaceDrawable : public gfxDrawable {
74 public:
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,
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) override;
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());
106 RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
107 const gfxMatrix mTransform;
111 * gfxDrawingCallback
112 * A simple drawing functor.
114 class gfxDrawingCallback {
115 NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback)
116 protected:
117 // Protected destructor, to discourage deletion outside of Release():
118 virtual ~gfxDrawingCallback() {}
120 public:
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 {
140 public:
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;
151 protected:
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;
162 * gfxPatternDrawable
163 * A convenience implementation of gfxDrawable for patterns.
165 class gfxPatternDrawable : public gfxDrawable {
166 public:
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;
178 protected:
179 already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
181 RefPtr<gfxPattern> mPattern;
184 #endif /* GFX_DRAWABLE_H */