|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef GFXCOWSURFACEWRAPPER |
|
6 #define GFXCOWSURFACEWRAPPER |
|
7 |
|
8 #include "gfxImageSurface.h" |
|
9 #include "nsISupportsImpl.h" |
|
10 #include "nsAutoPtr.h" |
|
11 |
|
12 |
|
13 /** |
|
14 * Provides an interface to implement a cross thread/process wrapper for a |
|
15 * gfxImageSurface that has copy-on-write semantics. |
|
16 * |
|
17 * Only the owner thread can write to the surface and acquire |
|
18 * read locks. Destroying a gfxReusableSurfaceWrapper releases |
|
19 * a read lock. |
|
20 * |
|
21 * OMTC Usage: |
|
22 * 1) Content creates a writable copy of this surface |
|
23 * wrapper which will be optimized to the same wrapper if there |
|
24 * are no readers. |
|
25 * 2) The surface is sent from content to the compositor once |
|
26 * or potentially many times, each increasing a read lock. |
|
27 * 3) When the compositor receives the surface, it adopts the |
|
28 * read lock. |
|
29 * 4) Once the compositor has processed the surface and uploaded |
|
30 * the content, it then releases the read lock by dereferencing |
|
31 * its wrapper. |
|
32 */ |
|
33 class gfxReusableSurfaceWrapper { |
|
34 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxReusableSurfaceWrapper) |
|
35 public: |
|
36 |
|
37 /** |
|
38 * Returns a read-only pointer to the image data. |
|
39 */ |
|
40 virtual const unsigned char* GetReadOnlyData() const = 0; |
|
41 |
|
42 /** |
|
43 * Returns the image surface format. |
|
44 */ |
|
45 virtual gfxImageFormat Format() = 0; |
|
46 |
|
47 /** |
|
48 * Returns a writable copy of the image. |
|
49 * If necessary this will copy the wrapper. If there are no contention |
|
50 * the same wrapper will be returned. A ReadLock must be held when |
|
51 * calling this function, and calling it will give up this lock. |
|
52 */ |
|
53 virtual gfxReusableSurfaceWrapper* GetWritable(gfxImageSurface** aSurface) = 0; |
|
54 |
|
55 /** |
|
56 * A read only lock count is recorded, any attempts to |
|
57 * call GetWritable() while this count is greater than one will |
|
58 * create a new surface/wrapper pair. |
|
59 * |
|
60 * When a surface's read count falls to zero, its memory will be |
|
61 * deallocated. It is the responsibility of the user to make sure |
|
62 * that all locks are matched with an equal number of unlocks. |
|
63 */ |
|
64 virtual void ReadLock() = 0; |
|
65 virtual void ReadUnlock() = 0; |
|
66 |
|
67 /** |
|
68 * Types for each implementation of gfxReusableSurfaceWrapper. |
|
69 */ |
|
70 enum Type { |
|
71 TYPE_SHARED_IMAGE, |
|
72 TYPE_IMAGE, |
|
73 |
|
74 TYPE_MAX |
|
75 }; |
|
76 |
|
77 /** |
|
78 * Returns a unique ID for each implementation of gfxReusableSurfaceWrapper. |
|
79 */ |
|
80 virtual Type GetType() = 0; |
|
81 |
|
82 protected: |
|
83 // Protected destructor, to discourage deletion outside of Release(): |
|
84 virtual ~gfxReusableSurfaceWrapper() {} |
|
85 |
|
86 NS_DECL_OWNINGTHREAD |
|
87 }; |
|
88 |
|
89 #endif // GFXCOWSURFACEWRAPPER |