Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / thebes / gfxDrawable.h
blobb0d47e3691a5396d38e9826e1221d1495040d6fd
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/. */
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) : mSize(aSize) {}
33 /**
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) {
52 return false;
55 virtual mozilla::gfx::IntSize Size() { return mSize; }
57 protected:
58 // Protected destructor, to discourage deletion outside of Release():
59 virtual ~gfxDrawable() = default;
61 const mozilla::gfx::IntSize mSize;
64 /**
65 * gfxSurfaceDrawable
66 * A convenience implementation of gfxDrawable for surfaces.
68 class gfxSurfaceDrawable : public gfxDrawable {
69 public:
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;
88 protected:
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,
94 gfxFloat aOpacity,
95 const gfxMatrix& aTransform = gfxMatrix());
97 RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
98 const gfxMatrix mTransform;
102 * gfxDrawingCallback
103 * A simple drawing functor.
105 class gfxDrawingCallback {
106 NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback)
107 protected:
108 // Protected destructor, to discourage deletion outside of Release():
109 virtual ~gfxDrawingCallback() = default;
111 public:
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 {
129 public:
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;
140 protected:
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;
150 * gfxPatternDrawable
151 * A convenience implementation of gfxDrawable for patterns.
153 class gfxPatternDrawable : public gfxDrawable {
154 public:
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;
164 protected:
165 already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
167 RefPtr<gfxPattern> mPattern;
170 #endif /* GFX_DRAWABLE_H */