|
1 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */ |
|
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 /* SharedSurface abstracts an actual surface (can be a GL texture, but |
|
7 * not necessarily) that handles sharing. |
|
8 * Its specializations are: |
|
9 * SharedSurface_Basic (client-side bitmap, does readback) |
|
10 * SharedSurface_GLTexture |
|
11 * SharedSurface_EGLImage |
|
12 * SharedSurface_ANGLEShareHandle |
|
13 */ |
|
14 |
|
15 #ifndef SHARED_SURFACE_H_ |
|
16 #define SHARED_SURFACE_H_ |
|
17 |
|
18 #include <stdint.h> |
|
19 #include "mozilla/Attributes.h" |
|
20 #include "GLDefs.h" |
|
21 #include "mozilla/gfx/Point.h" |
|
22 #include "SurfaceTypes.h" |
|
23 |
|
24 namespace mozilla { |
|
25 namespace gfx { |
|
26 |
|
27 class SurfaceFactory; |
|
28 |
|
29 class SharedSurface |
|
30 { |
|
31 protected: |
|
32 const SharedSurfaceType mType; |
|
33 const APITypeT mAPI; |
|
34 const AttachmentType mAttachType; |
|
35 const gfx::IntSize mSize; |
|
36 const bool mHasAlpha; |
|
37 bool mIsLocked; |
|
38 |
|
39 SharedSurface(SharedSurfaceType type, |
|
40 APITypeT api, |
|
41 AttachmentType attachType, |
|
42 const gfx::IntSize& size, |
|
43 bool hasAlpha) |
|
44 : mType(type) |
|
45 , mAPI(api) |
|
46 , mAttachType(attachType) |
|
47 , mSize(size) |
|
48 , mHasAlpha(hasAlpha) |
|
49 , mIsLocked(false) |
|
50 { |
|
51 } |
|
52 |
|
53 public: |
|
54 virtual ~SharedSurface() { |
|
55 } |
|
56 |
|
57 static void Copy(SharedSurface* src, SharedSurface* dest, |
|
58 SurfaceFactory* factory); |
|
59 |
|
60 // This locks the SharedSurface as the production buffer for the context. |
|
61 // This is needed by backends which use PBuffers and/or EGLSurfaces. |
|
62 virtual void LockProd() { |
|
63 MOZ_ASSERT(!mIsLocked); |
|
64 LockProdImpl(); |
|
65 mIsLocked = true; |
|
66 } |
|
67 |
|
68 // Unlocking is harmless if we're already unlocked. |
|
69 virtual void UnlockProd() { |
|
70 if (!mIsLocked) |
|
71 return; |
|
72 |
|
73 UnlockProdImpl(); |
|
74 mIsLocked = false; |
|
75 } |
|
76 |
|
77 virtual void LockProdImpl() = 0; |
|
78 virtual void UnlockProdImpl() = 0; |
|
79 |
|
80 virtual void Fence() = 0; |
|
81 virtual bool WaitSync() = 0; |
|
82 |
|
83 |
|
84 SharedSurfaceType Type() const { |
|
85 return mType; |
|
86 } |
|
87 |
|
88 APITypeT APIType() const { |
|
89 return mAPI; |
|
90 } |
|
91 |
|
92 AttachmentType AttachType() const { |
|
93 return mAttachType; |
|
94 } |
|
95 |
|
96 const gfx::IntSize& Size() const { |
|
97 return mSize; |
|
98 } |
|
99 |
|
100 bool HasAlpha() const { |
|
101 return mHasAlpha; |
|
102 } |
|
103 }; |
|
104 |
|
105 } /* namespace gfx */ |
|
106 } /* namespace mozilla */ |
|
107 |
|
108 #endif /* SHARED_SURFACE_H_ */ |