|
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 #include "GLContext.h" // for GLContext, etc |
|
7 #include "SurfaceStream.h" |
|
8 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
|
9 #include "mozilla/layers/ISurfaceAllocator.h" |
|
10 #include "mozilla/layers/TextureClientOGL.h" |
|
11 #include "nsSize.h" // for nsIntSize |
|
12 |
|
13 using namespace mozilla::gl; |
|
14 |
|
15 namespace mozilla { |
|
16 namespace layers { |
|
17 |
|
18 class CompositableForwarder; |
|
19 |
|
20 SharedTextureClientOGL::SharedTextureClientOGL(TextureFlags aFlags) |
|
21 : TextureClient(aFlags) |
|
22 , mHandle(0) |
|
23 , mInverted(false) |
|
24 { |
|
25 // SharedTextureClient is always owned externally. |
|
26 mFlags |= TEXTURE_DEALLOCATE_CLIENT; |
|
27 } |
|
28 |
|
29 SharedTextureClientOGL::~SharedTextureClientOGL() |
|
30 { |
|
31 // the shared data is owned externally. |
|
32 } |
|
33 |
|
34 |
|
35 bool |
|
36 SharedTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) |
|
37 { |
|
38 MOZ_ASSERT(IsValid()); |
|
39 if (!IsAllocated()) { |
|
40 return false; |
|
41 } |
|
42 aOutDescriptor = SharedTextureDescriptor(mShareType, mHandle, mSize, mInverted); |
|
43 return true; |
|
44 } |
|
45 |
|
46 void |
|
47 SharedTextureClientOGL::InitWith(gl::SharedTextureHandle aHandle, |
|
48 gfx::IntSize aSize, |
|
49 gl::SharedTextureShareType aShareType, |
|
50 bool aInverted) |
|
51 { |
|
52 MOZ_ASSERT(IsValid()); |
|
53 MOZ_ASSERT(!IsAllocated()); |
|
54 mHandle = aHandle; |
|
55 mSize = aSize; |
|
56 mShareType = aShareType; |
|
57 mInverted = aInverted; |
|
58 if (mInverted) { |
|
59 AddFlags(TEXTURE_NEEDS_Y_FLIP); |
|
60 } |
|
61 } |
|
62 |
|
63 bool |
|
64 SharedTextureClientOGL::Lock(OpenMode mode) |
|
65 { |
|
66 MOZ_ASSERT(!mIsLocked); |
|
67 if (!IsValid() || !IsAllocated()) { |
|
68 return false; |
|
69 } |
|
70 mIsLocked = true; |
|
71 return true; |
|
72 } |
|
73 |
|
74 void |
|
75 SharedTextureClientOGL::Unlock() |
|
76 { |
|
77 MOZ_ASSERT(mIsLocked); |
|
78 mIsLocked = false; |
|
79 } |
|
80 |
|
81 bool |
|
82 SharedTextureClientOGL::IsAllocated() const |
|
83 { |
|
84 return mHandle != 0; |
|
85 } |
|
86 |
|
87 StreamTextureClientOGL::StreamTextureClientOGL(TextureFlags aFlags) |
|
88 : TextureClient(aFlags) |
|
89 , mIsLocked(false) |
|
90 { |
|
91 } |
|
92 |
|
93 StreamTextureClientOGL::~StreamTextureClientOGL() |
|
94 { |
|
95 // the data is owned externally. |
|
96 } |
|
97 |
|
98 bool |
|
99 StreamTextureClientOGL::Lock(OpenMode mode) |
|
100 { |
|
101 MOZ_ASSERT(!mIsLocked); |
|
102 if (!IsValid() || !IsAllocated()) { |
|
103 return false; |
|
104 } |
|
105 mIsLocked = true; |
|
106 return true; |
|
107 } |
|
108 |
|
109 void |
|
110 StreamTextureClientOGL::Unlock() |
|
111 { |
|
112 MOZ_ASSERT(mIsLocked); |
|
113 mIsLocked = false; |
|
114 } |
|
115 |
|
116 bool |
|
117 StreamTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) |
|
118 { |
|
119 if (!IsAllocated()) { |
|
120 return false; |
|
121 } |
|
122 |
|
123 gfx::SurfaceStreamHandle handle = mStream->GetShareHandle(); |
|
124 aOutDescriptor = SurfaceStreamDescriptor(handle, false); |
|
125 return true; |
|
126 } |
|
127 |
|
128 void |
|
129 StreamTextureClientOGL::InitWith(gfx::SurfaceStream* aStream) |
|
130 { |
|
131 MOZ_ASSERT(!IsAllocated()); |
|
132 mStream = aStream; |
|
133 mGL = mStream->GLContext(); |
|
134 } |
|
135 |
|
136 bool |
|
137 StreamTextureClientOGL::IsAllocated() const |
|
138 { |
|
139 return mStream != 0; |
|
140 } |
|
141 |
|
142 |
|
143 } // namespace |
|
144 } // namespace |