|
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/. */ |
|
5 |
|
6 #ifndef GFX_CACHED_TEMP_SURFACE_H |
|
7 #define GFX_CACHED_TEMP_SURFACE_H |
|
8 |
|
9 #include "gfxASurface.h" |
|
10 #include "nsExpirationTracker.h" |
|
11 #include "nsSize.h" |
|
12 |
|
13 class gfxContext; |
|
14 |
|
15 /** |
|
16 * This class can be used to cache double-buffering back surfaces. |
|
17 * |
|
18 * Large resource allocations may have an overhead that can be avoided by |
|
19 * caching. Caching also alows the system to use history in deciding whether |
|
20 * to manage the surfaces in video or system memory. |
|
21 * |
|
22 * However, because we don't want to set aside megabytes of unused resources |
|
23 * unncessarily, these surfaces are released on a timer. |
|
24 */ |
|
25 |
|
26 class gfxCachedTempSurface { |
|
27 public: |
|
28 /** |
|
29 * Returns a context for a surface that can be efficiently copied to |
|
30 * |aSimilarTo|. |
|
31 * |
|
32 * When |aContentType| has an alpha component, the surface will be cleared. |
|
33 * For opaque surfaces, the initial surface contents are undefined. |
|
34 * When |aContentType| differs in different invocations this is handled |
|
35 * appropriately, creating a new surface if necessary. |
|
36 * |
|
37 * Because the cached surface may have been created during a previous |
|
38 * invocation, this will not be efficient if the new |aSimilarTo| has a |
|
39 * different format, size, or gfxSurfaceType. |
|
40 */ |
|
41 already_AddRefed<gfxContext> Get(gfxContentType aContentType, |
|
42 const gfxRect& aRect, |
|
43 gfxASurface* aSimilarTo); |
|
44 |
|
45 void Expire() { mSurface = nullptr; } |
|
46 nsExpirationState* GetExpirationState() { return &mExpirationState; } |
|
47 ~gfxCachedTempSurface(); |
|
48 |
|
49 bool IsSurface(gfxASurface* aSurface) { return mSurface == aSurface; } |
|
50 |
|
51 private: |
|
52 nsRefPtr<gfxASurface> mSurface; |
|
53 gfxIntSize mSize; |
|
54 nsExpirationState mExpirationState; |
|
55 gfxSurfaceType mType; |
|
56 }; |
|
57 |
|
58 #endif /* GFX_CACHED_TEMP_SURFACE_H */ |