|
|
|
|
| 34 |
* the terms of any one of the MPL, the GPL or the LGPL. |
34 |
* the terms of any one of the MPL, the GPL or the LGPL. |
| 35 |
* |
35 |
* |
| 36 |
* ***** END LICENSE BLOCK ***** */ |
36 |
* ***** END LICENSE BLOCK ***** */ |
| 37 |
|
37 |
|
| 38 |
#ifndef GFX_IMAGELAYER_H |
38 |
#ifndef GFX_IMAGELAYER_H |
| 39 |
#define GFX_IMAGELAYER_H |
39 |
#define GFX_IMAGELAYER_H |
| 40 |
|
40 |
|
| 41 |
#include "Layers.h" |
41 |
#include "Layers.h" |
|
|
42 |
#include "mozilla/TimeStamp.h" |
| 42 |
|
43 |
|
| 43 |
#include "gfxPattern.h" |
44 |
#include "gfxPattern.h" |
| 44 |
#include "nsThreadUtils.h" |
45 |
#include "nsThreadUtils.h" |
| 45 |
#include "nsCoreAnimationSupport.h" |
46 |
#include "nsCoreAnimationSupport.h" |
| 46 |
|
47 |
|
| 47 |
namespace mozilla { |
48 |
namespace mozilla { |
| 48 |
namespace layers { |
49 |
namespace layers { |
| 49 |
|
50 |
|
|
|
| 105 |
* It wraps an IOSurface object and binds it directly to a GL texture. |
106 |
* It wraps an IOSurface object and binds it directly to a GL texture. |
| 106 |
*/ |
107 |
*/ |
| 107 |
MAC_IO_SURFACE |
108 |
MAC_IO_SURFACE |
| 108 |
}; |
109 |
}; |
| 109 |
|
110 |
|
| 110 |
Format GetFormat() { return mFormat; } |
111 |
Format GetFormat() { return mFormat; } |
| 111 |
void* GetImplData() { return mImplData; } |
112 |
void* GetImplData() { return mImplData; } |
| 112 |
|
113 |
|
|
|
114 |
/** |
| 115 |
* Return PR_TRUE if this image has been painted at least once. |
| 116 |
* Call on main thread only. |
| 117 |
*/ |
| 118 |
PRBool HasBeenPainted() const { |
| 119 |
NS_PRECONDITION(NS_IsMainThread(), "Must be called on main thread"); |
| 120 |
return mPainted; |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Marks this image as having been painted. |
| 125 |
* Call on main thread only. |
| 126 |
*/ |
| 127 |
void MarkPainted() { |
| 128 |
NS_PRECONDITION(NS_IsMainThread(), "Must be called on main thread"); |
| 129 |
mPainted = PR_TRUE; |
| 130 |
} |
| 131 |
|
| 113 |
protected: |
132 |
protected: |
| 114 |
Image(void* aImplData, Format aFormat) : |
133 |
Image(void* aImplData, Format aFormat) : |
| 115 |
mImplData(aImplData), |
134 |
mImplData(aImplData), |
| 116 |
mFormat(aFormat) |
135 |
mFormat(aFormat), |
|
|
136 |
mPainted(PR_FALSE) |
| 117 |
{} |
137 |
{} |
| 118 |
|
138 |
|
| 119 |
void* mImplData; |
139 |
void* mImplData; |
| 120 |
Format mFormat; |
140 |
Format mFormat; |
|
|
141 |
|
| 142 |
// PR_TRUE if the image has been painted at least once. |
| 143 |
// Accessed on main thread only. |
| 144 |
PRBool mPainted; |
| 121 |
}; |
145 |
}; |
| 122 |
|
146 |
|
| 123 |
/** |
147 |
/** |
| 124 |
* A class that manages Images for an ImageLayer. The only reason |
148 |
* A class that manages Images for an ImageLayer. The only reason |
| 125 |
* we need a separate class here is that ImageLayers aren't threadsafe |
149 |
* we need a separate class here is that ImageLayers aren't threadsafe |
| 126 |
* (because layers can only be used on the main thread) and we want to |
150 |
* (because layers can only be used on the main thread) and we want to |
| 127 |
* be able to set the current Image from any thread, to facilitate |
151 |
* be able to set the current Image from any thread, to facilitate |
| 128 |
* video playback without involving the main thread, for example. |
152 |
* video playback without involving the main thread, for example. |
| 129 |
*/ |
153 |
*/ |
| 130 |
class THEBES_API ImageContainer { |
154 |
class THEBES_API ImageContainer { |
| 131 |
THEBES_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageContainer) |
155 |
THEBES_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageContainer) |
| 132 |
|
156 |
|
| 133 |
public: |
157 |
public: |
| 134 |
ImageContainer() {} |
158 |
ImageContainer() : mPaintCount(0) {} |
| 135 |
virtual ~ImageContainer() {} |
159 |
virtual ~ImageContainer() {} |
| 136 |
|
160 |
|
| 137 |
/** |
161 |
/** |
| 138 |
* Create an Image in one of the given formats. |
162 |
* Create an Image in one of the given formats. |
| 139 |
* Picks the "best" format from the list and creates an Image of that |
163 |
* Picks the "best" format from the list and creates an Image of that |
| 140 |
* format. |
164 |
* format. |
| 141 |
* Returns null if this backend does not support any of the formats. |
165 |
* Returns null if this backend does not support any of the formats. |
| 142 |
*/ |
166 |
*/ |
|
|
| 206 |
|
230 |
|
| 207 |
/** |
231 |
/** |
| 208 |
* Get the layer manager type this image container was created with, |
232 |
* Get the layer manager type this image container was created with, |
| 209 |
* presumably its users might want to do something special if types do not |
233 |
* presumably its users might want to do something special if types do not |
| 210 |
* match. |
234 |
* match. |
| 211 |
*/ |
235 |
*/ |
| 212 |
virtual LayerManager::LayersBackend GetBackendType() = 0; |
236 |
virtual LayerManager::LayersBackend GetBackendType() = 0; |
| 213 |
|
237 |
|
|
|
238 |
/** |
| 239 |
* Returns the time at which the currently contained image was first |
| 240 |
* painted. This is reset every time a new image is set as the current |
| 241 |
* image. Note this may return a null timestamp if the current image |
| 242 |
* has not yet been painted. Threadsafe. |
| 243 |
*/ |
| 244 |
virtual TimeStamp GetPaintTime() = 0; |
| 245 |
|
| 246 |
/** |
| 247 |
* Returns the number of images which have been contained in this container |
| 248 |
* and painted at least once. Threadsafe. |
| 249 |
*/ |
| 250 |
virtual PRUint32 GetPaintCount() = 0; |
| 251 |
|
| 252 |
/** |
| 253 |
* Notifies the container that aImage has been painted. Note we must pass |
| 254 |
* in a pointer to the image that has been painted, as the current image |
| 255 |
* can change while we're rendering, and in that case we don't want to |
| 256 |
* record the paint time of the just painted image as the paint time of the |
| 257 |
* current image. Threadsafe. |
| 258 |
*/ |
| 259 |
virtual void NotifyPaintedImage(Image* aImage) = 0; |
| 260 |
|
| 214 |
protected: |
261 |
protected: |
| 215 |
LayerManager* mManager; |
262 |
LayerManager* mManager; |
| 216 |
|
263 |
|
| 217 |
ImageContainer(LayerManager* aManager) : mManager(aManager) {} |
264 |
ImageContainer(LayerManager* aManager) : mManager(aManager), mPaintCount(0) {} |
|
|
265 |
|
| 266 |
// Number of contained images that have been painted at least once. It's up |
| 267 |
// to the ImageContainer implementation to ensure accesses to this are |
| 268 |
// threadsafe. |
| 269 |
PRUint32 mPaintCount; |
| 270 |
|
| 271 |
// Time stamp at which the current image was first painted. It's up to the |
| 272 |
// ImageContainer implementation to ensure accesses to this are threadsafe. |
| 273 |
TimeStamp mPaintTime; |
| 218 |
}; |
274 |
}; |
| 219 |
|
275 |
|
| 220 |
/** |
276 |
/** |
| 221 |
* A Layer which renders an Image. |
277 |
* A Layer which renders an Image. |
| 222 |
*/ |
278 |
*/ |
| 223 |
class THEBES_API ImageLayer : public Layer { |
279 |
class THEBES_API ImageLayer : public Layer { |
| 224 |
public: |
280 |
public: |
| 225 |
/** |
281 |
/** |