Bug 1700051: part 26) Correct typo in comment of `mozInlineSpellWordUtil::BuildSoftTe...
[gecko.git] / dom / canvas / HostWebGLContext.cpp
blobe009f1942600d9c7e08f99e6f3ec1de6041501cb
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/. */
6 #include "HostWebGLContext.h"
8 #include "CompositableHost.h"
9 #include "mozilla/layers/LayerTransactionChild.h"
10 #include "mozilla/layers/LayersSurfaces.h"
12 #include "MozFramebuffer.h"
13 #include "TexUnpackBlob.h"
14 #include "WebGL2Context.h"
15 #include "WebGLBuffer.h"
16 #include "WebGLContext.h"
17 #include "WebGLFramebuffer.h"
18 #include "WebGLMemoryTracker.h"
19 #include "WebGLParent.h"
20 #include "WebGLProgram.h"
21 #include "WebGLRenderbuffer.h"
22 #include "WebGLSampler.h"
23 #include "WebGLShader.h"
24 #include "WebGLSync.h"
25 #include "WebGLTexture.h"
26 #include "WebGLTransformFeedback.h"
27 #include "WebGLVertexArray.h"
28 #include "WebGLQuery.h"
30 #include "mozilla/StaticMutex.h"
32 namespace mozilla {
34 // -
36 static StaticMutex sContextSetLock;
38 static std::unordered_set<HostWebGLContext*>& DeferredStaticContextSet() {
39 static std::unordered_set<HostWebGLContext*> sContextSet;
40 return sContextSet;
43 LockedOutstandingContexts::LockedOutstandingContexts()
44 : contexts(DeferredStaticContextSet()) {
45 sContextSetLock.Lock();
48 LockedOutstandingContexts::~LockedOutstandingContexts() {
49 sContextSetLock.Unlock();
52 // -
54 /*static*/
55 UniquePtr<HostWebGLContext> HostWebGLContext::Create(
56 const OwnerData& ownerData, const webgl::InitContextDesc& desc,
57 webgl::InitContextResult* const out) {
58 auto host = WrapUnique(new HostWebGLContext(ownerData));
59 auto webgl = WebGLContext::Create(*host, desc, out);
60 if (!webgl) return nullptr;
61 return host;
64 HostWebGLContext::HostWebGLContext(const OwnerData& ownerData)
65 : mOwnerData(ownerData) {
66 StaticMutexAutoLock lock(sContextSetLock);
67 auto& contexts = DeferredStaticContextSet();
68 (void)contexts.insert(this);
71 HostWebGLContext::~HostWebGLContext() {
72 StaticMutexAutoLock lock(sContextSetLock);
73 auto& contexts = DeferredStaticContextSet();
74 (void)contexts.erase(this);
77 // -
79 void HostWebGLContext::OnContextLoss(const webgl::ContextLossReason reason) {
80 if (mOwnerData.inProcess) {
81 mOwnerData.inProcess->OnContextLoss(reason);
82 } else {
83 (void)mOwnerData.outOfProcess->SendOnContextLoss(reason);
87 void HostWebGLContext::JsWarning(const std::string& text) const {
88 if (mOwnerData.inProcess) {
89 mOwnerData.inProcess->JsWarning(text);
90 return;
92 (void)mOwnerData.outOfProcess->SendJsWarning(text);
95 Maybe<layers::SurfaceDescriptor> HostWebGLContext::GetFrontBuffer(
96 const ObjectId xrFb, const bool webvr) const {
97 return mContext->GetFrontBuffer(AutoResolve(xrFb), webvr);
100 //////////////////////////////////////////////
101 // Creation
103 void HostWebGLContext::CreateBuffer(const ObjectId id) {
104 auto& slot = mBufferMap[id];
105 if (slot) {
106 MOZ_ASSERT(false, "duplicate ID");
107 return;
109 slot = mContext->CreateBuffer();
112 void HostWebGLContext::CreateFramebuffer(const ObjectId id) {
113 auto& slot = mFramebufferMap[id];
114 if (slot) {
115 MOZ_ASSERT(false, "duplicate ID");
116 return;
118 slot = mContext->CreateFramebuffer();
121 bool HostWebGLContext::CreateOpaqueFramebuffer(
122 const ObjectId id, const webgl::OpaqueFramebufferOptions& options) {
123 auto& slot = mFramebufferMap[id];
124 if (slot) {
125 MOZ_ASSERT(false, "duplicate ID");
126 return false;
128 slot = mContext->CreateOpaqueFramebuffer(options);
129 return slot;
132 void HostWebGLContext::CreateProgram(const ObjectId id) {
133 auto& slot = mProgramMap[id];
134 if (slot) {
135 MOZ_ASSERT(false, "duplicate ID");
136 return;
138 slot = mContext->CreateProgram();
141 void HostWebGLContext::CreateQuery(const ObjectId id) {
142 auto& slot = mQueryMap[id];
143 if (slot) {
144 MOZ_ASSERT(false, "duplicate ID");
145 return;
147 slot = mContext->CreateQuery();
150 void HostWebGLContext::CreateRenderbuffer(const ObjectId id) {
151 auto& slot = mRenderbufferMap[id];
152 if (slot) {
153 MOZ_ASSERT(false, "duplicate ID");
154 return;
156 slot = mContext->CreateRenderbuffer();
159 void HostWebGLContext::CreateSampler(const ObjectId id) {
160 auto& slot = mSamplerMap[id];
161 if (slot) {
162 MOZ_ASSERT(false, "duplicate ID");
163 return;
165 slot = GetWebGL2Context()->CreateSampler();
168 void HostWebGLContext::CreateShader(const ObjectId id, GLenum type) {
169 auto& slot = mShaderMap[id];
170 if (slot) {
171 MOZ_ASSERT(false, "duplicate ID");
172 return;
174 slot = mContext->CreateShader(type);
177 void HostWebGLContext::CreateSync(const ObjectId id) {
178 auto& slot = mSyncMap[id];
179 if (slot) {
180 MOZ_ASSERT(false, "duplicate ID");
181 return;
183 slot = GetWebGL2Context()->FenceSync(LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
186 void HostWebGLContext::CreateTexture(const ObjectId id) {
187 auto& slot = mTextureMap[id];
188 if (slot) {
189 MOZ_ASSERT(false, "duplicate ID");
190 return;
192 slot = mContext->CreateTexture();
195 void HostWebGLContext::CreateTransformFeedback(const ObjectId id) {
196 auto& slot = mTransformFeedbackMap[id];
197 if (slot) {
198 MOZ_ASSERT(false, "duplicate ID");
199 return;
201 slot = GetWebGL2Context()->CreateTransformFeedback();
204 void HostWebGLContext::CreateVertexArray(const ObjectId id) {
205 auto& slot = mVertexArrayMap[id];
206 if (slot) {
207 MOZ_ASSERT(false, "duplicate ID");
208 return;
210 slot = mContext->CreateVertexArray();
213 ////////////////////////
215 #define _(X) \
216 void HostWebGLContext::Delete##X(const ObjectId id) { m##X##Map.erase(id); }
218 _(Buffer)
219 _(Framebuffer)
220 _(Program)
221 _(Query)
222 _(Renderbuffer)
223 _(Sampler)
224 _(Shader)
225 _(Sync)
226 _(Texture)
227 _(TransformFeedback)
228 _(VertexArray)
230 #undef _
232 } // namespace mozilla