Bug 835381 - Update libnestegg to 38c83d9d4c0c5c84373aa285bd30094a12d6b6f6. r=kinetik
[gecko.git] / gfx / thebes / gfxDrawable.h
blob1acdb377663772a76ff8793f6c5bd791ca957132
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 "nsISupportsImpl.h"
10 #include "nsAutoPtr.h"
11 #include "gfxTypes.h"
12 #include "gfxRect.h"
13 #include "gfxColor.h"
14 #include "gfxMatrix.h"
15 #include "gfxPattern.h"
17 class gfxASurface;
18 class gfxContext;
20 /**
21 * gfxDrawable
22 * An Interface representing something that has an intrinsic size and can draw
23 * itself repeatedly.
25 class THEBES_API gfxDrawable {
26 NS_INLINE_DECL_REFCOUNTING(gfxDrawable)
27 public:
28 gfxDrawable(const gfxIntSize aSize)
29 : mSize(aSize) {}
30 virtual ~gfxDrawable() {}
32 /**
33 * Draw into aContext filling aFillRect, possibly repeating, using aFilter.
34 * aTransform is a userspace to "image"space matrix. For example, if Draw
35 * draws using a gfxPattern, this is the matrix that should be set on the
36 * pattern prior to rendering it.
37 * @return whether drawing was successful
39 virtual bool Draw(gfxContext* aContext,
40 const gfxRect& aFillRect,
41 bool aRepeat,
42 const gfxPattern::GraphicsFilter& aFilter,
43 const gfxMatrix& aTransform = gfxMatrix()) = 0;
44 virtual gfxIntSize Size() { return mSize; }
46 protected:
47 const gfxIntSize mSize;
50 /**
51 * gfxSurfaceDrawable
52 * A convenience implementation of gfxDrawable for surfaces.
54 class THEBES_API gfxSurfaceDrawable : public gfxDrawable {
55 public:
56 gfxSurfaceDrawable(gfxASurface* aSurface, const gfxIntSize aSize,
57 const gfxMatrix aTransform = gfxMatrix());
58 virtual ~gfxSurfaceDrawable() {}
60 virtual bool Draw(gfxContext* aContext,
61 const gfxRect& aFillRect,
62 bool aRepeat,
63 const gfxPattern::GraphicsFilter& aFilter,
64 const gfxMatrix& aTransform = gfxMatrix());
66 protected:
67 nsRefPtr<gfxASurface> mSurface;
68 const gfxMatrix mTransform;
71 /**
72 * gfxDrawingCallback
73 * A simple drawing functor.
75 class THEBES_API gfxDrawingCallback {
76 NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback)
77 public:
78 virtual ~gfxDrawingCallback() {}
80 /**
81 * Draw into aContext filling aFillRect using aFilter.
82 * aTransform is a userspace to "image"space matrix. For example, if Draw
83 * draws using a gfxPattern, this is the matrix that should be set on the
84 * pattern prior to rendering it.
85 * @return whether drawing was successful
87 virtual bool operator()(gfxContext* aContext,
88 const gfxRect& aFillRect,
89 const gfxPattern::GraphicsFilter& aFilter,
90 const gfxMatrix& aTransform = gfxMatrix()) = 0;
94 /**
95 * gfxSurfaceDrawable
96 * A convenience implementation of gfxDrawable for callbacks.
98 class THEBES_API gfxCallbackDrawable : public gfxDrawable {
99 public:
100 gfxCallbackDrawable(gfxDrawingCallback* aCallback, const gfxIntSize aSize);
101 virtual ~gfxCallbackDrawable() {}
103 virtual bool Draw(gfxContext* aContext,
104 const gfxRect& aFillRect,
105 bool aRepeat,
106 const gfxPattern::GraphicsFilter& aFilter,
107 const gfxMatrix& aTransform = gfxMatrix());
109 protected:
110 already_AddRefed<gfxSurfaceDrawable> MakeSurfaceDrawable(const gfxPattern::GraphicsFilter aFilter = gfxPattern::FILTER_FAST);
112 nsRefPtr<gfxDrawingCallback> mCallback;
113 nsRefPtr<gfxSurfaceDrawable> mSurfaceDrawable;
117 * gfxPatternDrawable
118 * A convenience implementation of gfxDrawable for patterns.
120 class THEBES_API gfxPatternDrawable : public gfxDrawable {
121 public:
122 gfxPatternDrawable(gfxPattern* aPattern,
123 const gfxIntSize aSize);
124 virtual ~gfxPatternDrawable() {}
126 virtual bool Draw(gfxContext* aContext,
127 const gfxRect& aFillRect,
128 bool aRepeat,
129 const gfxPattern::GraphicsFilter& aFilter,
130 const gfxMatrix& aTransform = gfxMatrix());
132 protected:
133 already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
135 nsRefPtr<gfxPattern> mPattern;
138 #endif /* GFX_DRAWABLE_H */