1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is Markus Stange.
18 : * Portions created by the Initial Developer are Copyright (C) 2010
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 2 or later (the "GPL"), or
25 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 : * in which case the provisions of the GPL or the LGPL are applicable instead
27 : * of those above. If you wish to allow use of your version of this file only
28 : * under the terms of either the GPL or the LGPL, and not to allow others to
29 : * use your version of this file under the terms of the MPL, indicate your
30 : * decision by deleting the provisions above and replace them with the notice
31 : * and other provisions required by the GPL or the LGPL. If you do not delete
32 : * the provisions above, a recipient may use your version of this file under
33 : * the terms of any one of the MPL, the GPL or the LGPL.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : #ifndef GFX_DRAWABLE_H
38 : #define GFX_DRAWABLE_H
39 :
40 : #include "nsISupportsImpl.h"
41 : #include "nsAutoPtr.h"
42 : #include "gfxTypes.h"
43 : #include "gfxRect.h"
44 : #include "gfxColor.h"
45 : #include "gfxMatrix.h"
46 : #include "gfxPattern.h"
47 :
48 : class gfxASurface;
49 : class gfxContext;
50 :
51 : /**
52 : * gfxDrawable
53 : * An Interface representing something that has an intrinsic size and can draw
54 : * itself repeatedly.
55 : */
56 : class THEBES_API gfxDrawable {
57 0 : NS_INLINE_DECL_REFCOUNTING(gfxDrawable)
58 : public:
59 : gfxDrawable(const gfxIntSize aSize)
60 : : mSize(aSize) {}
61 : virtual ~gfxDrawable() {}
62 :
63 : /**
64 : * Draw into aContext filling aFillRect, possibly repeating, using aFilter.
65 : * aTransform is a userspace to "image"space matrix. For example, if Draw
66 : * draws using a gfxPattern, this is the matrix that should be set on the
67 : * pattern prior to rendering it.
68 : * @return whether drawing was successful
69 : */
70 : virtual bool Draw(gfxContext* aContext,
71 : const gfxRect& aFillRect,
72 : bool aRepeat,
73 : const gfxPattern::GraphicsFilter& aFilter,
74 : const gfxMatrix& aTransform = gfxMatrix()) = 0;
75 : virtual gfxIntSize Size() { return mSize; }
76 :
77 : protected:
78 : const gfxIntSize mSize;
79 : };
80 :
81 : /**
82 : * gfxSurfaceDrawable
83 : * A convenience implementation of gfxDrawable for surfaces.
84 : */
85 : class THEBES_API gfxSurfaceDrawable : public gfxDrawable {
86 : public:
87 : gfxSurfaceDrawable(gfxASurface* aSurface, const gfxIntSize aSize,
88 : const gfxMatrix aTransform = gfxMatrix());
89 : virtual ~gfxSurfaceDrawable() {}
90 :
91 : virtual bool Draw(gfxContext* aContext,
92 : const gfxRect& aFillRect,
93 : bool aRepeat,
94 : const gfxPattern::GraphicsFilter& aFilter,
95 : const gfxMatrix& aTransform = gfxMatrix());
96 :
97 : protected:
98 : nsRefPtr<gfxASurface> mSurface;
99 : const gfxMatrix mTransform;
100 : };
101 :
102 : /**
103 : * gfxDrawingCallback
104 : * A simple drawing functor.
105 : */
106 0 : class THEBES_API gfxDrawingCallback {
107 0 : NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback)
108 : public:
109 0 : virtual ~gfxDrawingCallback() {}
110 :
111 : /**
112 : * Draw into aContext filling aFillRect using aFilter.
113 : * aTransform is a userspace to "image"space matrix. For example, if Draw
114 : * draws using a gfxPattern, this is the matrix that should be set on the
115 : * pattern prior to rendering it.
116 : * @return whether drawing was successful
117 : */
118 : virtual bool operator()(gfxContext* aContext,
119 : const gfxRect& aFillRect,
120 : const gfxPattern::GraphicsFilter& aFilter,
121 : const gfxMatrix& aTransform = gfxMatrix()) = 0;
122 :
123 : };
124 :
125 : /**
126 : * gfxSurfaceDrawable
127 : * A convenience implementation of gfxDrawable for callbacks.
128 : */
129 : class THEBES_API gfxCallbackDrawable : public gfxDrawable {
130 : public:
131 : gfxCallbackDrawable(gfxDrawingCallback* aCallback, const gfxIntSize aSize);
132 : virtual ~gfxCallbackDrawable() {}
133 :
134 : virtual bool Draw(gfxContext* aContext,
135 : const gfxRect& aFillRect,
136 : bool aRepeat,
137 : const gfxPattern::GraphicsFilter& aFilter,
138 : const gfxMatrix& aTransform = gfxMatrix());
139 :
140 : protected:
141 : already_AddRefed<gfxSurfaceDrawable> MakeSurfaceDrawable(const gfxPattern::GraphicsFilter aFilter = gfxPattern::FILTER_FAST);
142 :
143 : nsRefPtr<gfxDrawingCallback> mCallback;
144 : nsRefPtr<gfxSurfaceDrawable> mSurfaceDrawable;
145 : };
146 :
147 : /**
148 : * gfxPatternDrawable
149 : * A convenience implementation of gfxDrawable for patterns.
150 : */
151 : class THEBES_API gfxPatternDrawable : public gfxDrawable {
152 : public:
153 : gfxPatternDrawable(gfxPattern* aPattern,
154 : const gfxIntSize aSize);
155 : virtual ~gfxPatternDrawable() {}
156 :
157 : virtual bool Draw(gfxContext* aContext,
158 : const gfxRect& aFillRect,
159 : bool aRepeat,
160 : const gfxPattern::GraphicsFilter& aFilter,
161 : const gfxMatrix& aTransform = gfxMatrix());
162 :
163 : protected:
164 : already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
165 :
166 : nsRefPtr<gfxPattern> mPattern;
167 : };
168 :
169 : #endif /* GFX_DRAWABLE_H */
|