Bug 1941128 - Turn off network.dns.native_https_query on Mac again
[gecko.git] / dom / canvas / HostWebGLContext.cpp
blobc35122c28859137546128adcf5a96293aa420c57
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/LayersSurfaces.h"
11 #include "MozFramebuffer.h"
12 #include "TexUnpackBlob.h"
13 #include "WebGL2Context.h"
14 #include "WebGLBuffer.h"
15 #include "WebGLContext.h"
16 #include "WebGLFramebuffer.h"
17 #include "WebGLMemoryTracker.h"
18 #include "WebGLParent.h"
19 #include "WebGLProgram.h"
20 #include "WebGLRenderbuffer.h"
21 #include "WebGLSampler.h"
22 #include "WebGLShader.h"
23 #include "WebGLSync.h"
24 #include "WebGLTexture.h"
25 #include "WebGLTransformFeedback.h"
26 #include "WebGLVertexArray.h"
27 #include "WebGLQuery.h"
29 #include "mozilla/StaticMutex.h"
31 namespace mozilla {
33 // -
35 static StaticMutex sContextSetLock MOZ_UNANNOTATED;
37 static std::unordered_set<HostWebGLContext*>& DeferredStaticContextSet() {
38 static std::unordered_set<HostWebGLContext*> sContextSet;
39 return sContextSet;
42 LockedOutstandingContexts::LockedOutstandingContexts()
43 : contexts(DeferredStaticContextSet()) {
44 sContextSetLock.Lock();
47 LockedOutstandingContexts::~LockedOutstandingContexts() {
48 sContextSetLock.Unlock();
51 // -
53 /*static*/
54 std::unique_ptr<HostWebGLContext> HostWebGLContext::Create(
55 const OwnerData& ownerData, const webgl::InitContextDesc& desc,
56 webgl::InitContextResult* const out) {
57 auto host =
58 std::unique_ptr<HostWebGLContext>(new HostWebGLContext(ownerData));
59 auto webgl = WebGLContext::Create(host.get(), 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);
185 if (!slot) return;
187 slot->OnCompleteTaskAdd([host = WeakPtr{this}, id]() {
188 if (!host) return;
189 if (host->mOwnerData.inProcess) {
190 host->mOwnerData.inProcess->OnSyncComplete(id);
191 } else if (host->mOwnerData.outOfProcess) {
192 (void)host->mOwnerData.outOfProcess->SendOnSyncComplete(id);
197 void HostWebGLContext::CreateTexture(const ObjectId id) {
198 auto& slot = mTextureMap[id];
199 if (slot) {
200 MOZ_ASSERT(false, "duplicate ID");
201 return;
203 slot = mContext->CreateTexture();
206 void HostWebGLContext::CreateTransformFeedback(const ObjectId id) {
207 auto& slot = mTransformFeedbackMap[id];
208 if (slot) {
209 MOZ_ASSERT(false, "duplicate ID");
210 return;
212 slot = GetWebGL2Context()->CreateTransformFeedback();
215 void HostWebGLContext::CreateVertexArray(const ObjectId id) {
216 auto& slot = mVertexArrayMap[id];
217 if (slot) {
218 MOZ_ASSERT(false, "duplicate ID");
219 return;
221 slot = mContext->CreateVertexArray();
224 ////////////////////////
226 #define _(X) \
227 void HostWebGLContext::Delete##X(const ObjectId id) { m##X##Map.erase(id); }
229 _(Buffer)
230 _(Framebuffer)
231 _(Program)
232 _(Query)
233 _(Renderbuffer)
234 _(Sampler)
235 _(Shader)
236 _(Sync)
237 _(Texture)
238 _(TransformFeedback)
239 _(VertexArray)
241 #undef _
243 } // namespace mozilla