blob: 63bf64cbc6d6bb749dfbe15155020ecb4a782104 [file] [log] [blame]
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +00001//
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002// Copyright (c) 2002-2016 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang4ddf5af2016-12-01 14:30:44 -05007// ResourceManager.cpp: Implements the the ResourceManager classes, which handle allocation and
8// lifetime of GL objects.
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +00009
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/ResourceManager.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000011
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Buffer.h"
Jamie Madill53ea9cc2016-05-17 10:12:52 -040013#include "libANGLE/Fence.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030014#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050015#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080016#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050017#include "libANGLE/Renderbuffer.h"
Jamie Madill53ea9cc2016-05-17 10:12:52 -040018#include "libANGLE/Sampler.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050019#include "libANGLE/Shader.h"
20#include "libANGLE/Texture.h"
Jamie Madill53ea9cc2016-05-17 10:12:52 -040021#include "libANGLE/renderer/GLImplFactory.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000022
23namespace gl
24{
Geoff Lang4ddf5af2016-12-01 14:30:44 -050025
26namespace
27{
28
29template <typename ResourceType>
30GLuint AllocateEmptyObject(HandleAllocator *handleAllocator, ResourceMap<ResourceType> *objectMap)
31{
Jamie Madill96a483b2017-06-27 16:49:21 -040032 GLuint handle = handleAllocator->allocate();
33 objectMap->assign(handle, nullptr);
Geoff Lang4ddf5af2016-12-01 14:30:44 -050034 return handle;
35}
36
Geoff Lang4ddf5af2016-12-01 14:30:44 -050037} // anonymous namespace
38
39template <typename HandleAllocatorType>
40ResourceManagerBase<HandleAllocatorType>::ResourceManagerBase() : mRefCount(1)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000041{
42}
43
Geoff Lang4ddf5af2016-12-01 14:30:44 -050044template <typename HandleAllocatorType>
45void ResourceManagerBase<HandleAllocatorType>::addRef()
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000046{
47 mRefCount++;
48}
49
Geoff Lang4ddf5af2016-12-01 14:30:44 -050050template <typename HandleAllocatorType>
Jamie Madill6c1f6712017-02-14 19:08:04 -050051void ResourceManagerBase<HandleAllocatorType>::release(const Context *context)
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000052{
53 if (--mRefCount == 0)
54 {
Jamie Madill6c1f6712017-02-14 19:08:04 -050055 reset(context);
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000056 delete this;
57 }
58}
59
Jamie Madill5f45e7c2017-02-10 15:23:28 -080060template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
61TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::~TypedResourceManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000062{
Jamie Madill6c1f6712017-02-14 19:08:04 -050063 ASSERT(mObjectMap.empty());
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000064}
65
Jamie Madill5f45e7c2017-02-10 15:23:28 -080066template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
Jamie Madill6c1f6712017-02-14 19:08:04 -050067void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::reset(const Context *context)
68{
Jamie Madill96a483b2017-06-27 16:49:21 -040069 this->mHandleAllocator.reset();
70 for (const auto &resource : mObjectMap)
Jamie Madill6c1f6712017-02-14 19:08:04 -050071 {
Jamie Madill96a483b2017-06-27 16:49:21 -040072 if (resource.second)
73 {
74 ImplT::DeleteObject(context, resource.second);
75 }
Jamie Madill6c1f6712017-02-14 19:08:04 -050076 }
77 mObjectMap.clear();
78}
79
80template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
81void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::deleteObject(
82 const Context *context,
83 GLuint handle)
Geoff Lang4ddf5af2016-12-01 14:30:44 -050084{
Jamie Madill96a483b2017-06-27 16:49:21 -040085 ResourceType *resource = nullptr;
86 if (!mObjectMap.erase(handle, &resource))
Jamie Madill5f45e7c2017-02-10 15:23:28 -080087 {
88 return;
89 }
90
Jamie Madill5f45e7c2017-02-10 15:23:28 -080091 // Requires an explicit this-> because of C++ template rules.
Jamie Madill96a483b2017-06-27 16:49:21 -040092 this->mHandleAllocator.release(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -050093
Jamie Madill96a483b2017-06-27 16:49:21 -040094 if (resource)
Jamie Madill5f45e7c2017-02-10 15:23:28 -080095 {
Jamie Madill96a483b2017-06-27 16:49:21 -040096 ImplT::DeleteObject(context, resource);
Jamie Madill5f45e7c2017-02-10 15:23:28 -080097 }
Jamie Madill5f45e7c2017-02-10 15:23:28 -080098}
99
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500100template class ResourceManagerBase<HandleAllocator>;
101template class ResourceManagerBase<HandleRangeAllocator>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800102template class TypedResourceManager<Buffer, HandleAllocator, BufferManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800103template class TypedResourceManager<Texture, HandleAllocator, TextureManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800104template class TypedResourceManager<Renderbuffer, HandleAllocator, RenderbufferManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800105template class TypedResourceManager<Sampler, HandleAllocator, SamplerManager>;
Jamie Madill70b5bb02017-08-28 13:32:37 -0400106template class TypedResourceManager<Sync, HandleAllocator, SyncManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800107template class TypedResourceManager<Framebuffer, HandleAllocator, FramebufferManager>;
Yunchao Hea336b902017-08-02 16:05:21 +0800108template class TypedResourceManager<ProgramPipeline, HandleAllocator, ProgramPipelineManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800109
110// BufferManager Implementation.
111
112// static
113Buffer *BufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
114{
115 Buffer *buffer = new Buffer(factory, handle);
116 buffer->addRef();
117 return buffer;
118}
119
120// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400121void BufferManager::DeleteObject(const Context *context, Buffer *buffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800122{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400123 buffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800124}
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500125
126GLuint BufferManager::createBuffer()
127{
128 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
129}
130
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500131Buffer *BufferManager::getBuffer(GLuint handle) const
132{
Jamie Madill96a483b2017-06-27 16:49:21 -0400133 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500134}
135
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800136// ShaderProgramManager Implementation.
137
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500138ShaderProgramManager::ShaderProgramManager()
139{
140}
141
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500142ShaderProgramManager::~ShaderProgramManager()
143{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500144 ASSERT(mPrograms.empty());
145 ASSERT(mShaders.empty());
146}
147
148void ShaderProgramManager::reset(const Context *context)
149{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500150 while (!mPrograms.empty())
151 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500152 deleteProgram(context, mPrograms.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500153 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500154 mPrograms.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500155 while (!mShaders.empty())
156 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500157 deleteShader(context, mShaders.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500158 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500159 mShaders.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500160}
161
162GLuint ShaderProgramManager::createShader(rx::GLImplFactory *factory,
163 const gl::Limitations &rendererLimitations,
Jiawei Shao385b3e02018-03-21 09:43:28 +0800164 ShaderType type)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000165{
Jiawei Shao385b3e02018-03-21 09:43:28 +0800166 ASSERT(type != ShaderType::InvalidEnum);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500167 GLuint handle = mHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400168 mShaders.assign(handle, new Shader(this, factory, rendererLimitations, type, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000169 return handle;
170}
171
Jamie Madill6c1f6712017-02-14 19:08:04 -0500172void ShaderProgramManager::deleteShader(const Context *context, GLuint shader)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000173{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500174 deleteObject(context, &mShaders, shader);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000175}
176
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500177Shader *ShaderProgramManager::getShader(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000178{
Jamie Madill96a483b2017-06-27 16:49:21 -0400179 return mShaders.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000180}
181
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500182GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000183{
Jamie Madill96a483b2017-06-27 16:49:21 -0400184 GLuint handle = mHandleAllocator.allocate();
185 mPrograms.assign(handle, new Program(factory, this, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000186 return handle;
187}
188
Jamie Madill6c1f6712017-02-14 19:08:04 -0500189void ShaderProgramManager::deleteProgram(const gl::Context *context, GLuint program)
Jamie Madilldc356042013-07-19 16:36:57 -0400190{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500191 deleteObject(context, &mPrograms, program);
Jamie Madilldc356042013-07-19 16:36:57 -0400192}
193
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500194Program *ShaderProgramManager::getProgram(GLuint handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400195{
Jamie Madill96a483b2017-06-27 16:49:21 -0400196 return mPrograms.query(handle);
Jamie Madillcd055f82013-07-26 11:55:15 -0400197}
198
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500199template <typename ObjectType>
Jamie Madill6c1f6712017-02-14 19:08:04 -0500200void ShaderProgramManager::deleteObject(const Context *context,
201 ResourceMap<ObjectType> *objectMap,
202 GLuint id)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500203{
Jamie Madill96a483b2017-06-27 16:49:21 -0400204 ObjectType *object = objectMap->query(id);
205 if (!object)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500206 {
207 return;
208 }
209
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500210 if (object->getRefCount() == 0)
211 {
212 mHandleAllocator.release(id);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400213 object->onDestroy(context);
Jamie Madill96a483b2017-06-27 16:49:21 -0400214 objectMap->erase(id, &object);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500215 }
216 else
217 {
218 object->flagForDeletion();
219 }
220}
221
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800222// TextureManager Implementation.
223
224// static
Corentin Wallez99d492c2018-02-27 15:17:10 -0500225Texture *TextureManager::AllocateNewObject(rx::GLImplFactory *factory,
226 GLuint handle,
227 TextureType type)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800228{
Corentin Wallez99d492c2018-02-27 15:17:10 -0500229 Texture *texture = new Texture(factory, handle, type);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800230 texture->addRef();
231 return texture;
232}
233
234// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400235void TextureManager::DeleteObject(const Context *context, Texture *texture)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800236{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400237 texture->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800238}
239
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500240GLuint TextureManager::createTexture()
241{
242 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
243}
244
Jamie Madilld4442552018-02-27 22:03:47 -0500245void TextureManager::signalAllTexturesDirty(const Context *context) const
Geoff Lang9aded172017-04-05 11:07:56 -0400246{
Jamie Madill96a483b2017-06-27 16:49:21 -0400247 for (const auto &texture : mObjectMap)
Geoff Lang9aded172017-04-05 11:07:56 -0400248 {
249 if (texture.second)
250 {
Jamie Madill05b35b22017-10-03 09:01:44 -0400251 // We don't know if the Texture needs init, but that's ok, since it will only force
252 // a re-check, and will not initialize the pixels if it's not needed.
Jamie Madilld4442552018-02-27 22:03:47 -0500253 texture.second->signalDirty(context, InitState::MayNeedInit);
Geoff Lang9aded172017-04-05 11:07:56 -0400254 }
255 }
256}
257
Jamie Madillfc3463d2018-01-03 13:46:21 -0500258void TextureManager::enableHandleAllocatorLogging()
259{
260 mHandleAllocator.enableLogging(true);
261}
262
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800263// RenderbufferManager Implementation.
264
265// static
266Renderbuffer *RenderbufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
267{
Jamie Madille703c602018-02-20 10:21:48 -0500268 Renderbuffer *renderbuffer = new Renderbuffer(factory, handle);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800269 renderbuffer->addRef();
270 return renderbuffer;
271}
272
273// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400274void RenderbufferManager::DeleteObject(const Context *context, Renderbuffer *renderbuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800275{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400276 renderbuffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800277}
278
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500279GLuint RenderbufferManager::createRenderbuffer()
280{
281 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
282}
283
Yunchao Hea438f4e2017-08-04 13:42:39 +0800284Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500285{
Jamie Madill96a483b2017-06-27 16:49:21 -0400286 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500287}
288
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800289// SamplerManager Implementation.
290
291// static
292Sampler *SamplerManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
293{
294 Sampler *sampler = new Sampler(factory, handle);
295 sampler->addRef();
296 return sampler;
297}
298
299// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400300void SamplerManager::DeleteObject(const Context *context, Sampler *sampler)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800301{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400302 sampler->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800303}
304
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500305GLuint SamplerManager::createSampler()
306{
307 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
308}
309
Yunchao Hea438f4e2017-08-04 13:42:39 +0800310Sampler *SamplerManager::getSampler(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500311{
Jamie Madill96a483b2017-06-27 16:49:21 -0400312 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500313}
314
Yunchao Hea438f4e2017-08-04 13:42:39 +0800315bool SamplerManager::isSampler(GLuint sampler) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500316{
Jamie Madill96a483b2017-06-27 16:49:21 -0400317 return mObjectMap.contains(sampler);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500318}
319
Jamie Madill70b5bb02017-08-28 13:32:37 -0400320// SyncManager Implementation.
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800321
322// static
Jamie Madill70b5bb02017-08-28 13:32:37 -0400323void SyncManager::DeleteObject(const Context *context, Sync *sync)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500324{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400325 sync->release(context);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500326}
327
Jamie Madill70b5bb02017-08-28 13:32:37 -0400328GLuint SyncManager::createSync(rx::GLImplFactory *factory)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500329{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400330 GLuint handle = mHandleAllocator.allocate();
331 Sync *sync = new Sync(factory->createSync(), handle);
332 sync->addRef();
333 mObjectMap.assign(handle, sync);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800334 return handle;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500335}
336
Jamie Madill70b5bb02017-08-28 13:32:37 -0400337Sync *SyncManager::getSync(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500338{
Jamie Madill96a483b2017-06-27 16:49:21 -0400339 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500340}
341
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800342// PathManager Implementation.
343
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500344PathManager::PathManager()
345{
346}
347
Jamie Madill13951342018-09-30 15:24:28 -0400348Error PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range, GLuint *createdOut)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300349{
Jamie Madill13951342018-09-30 15:24:28 -0400350 *createdOut = 0;
351
Sami Väisänene45e53b2016-05-25 10:36:04 +0300352 // Allocate client side handles.
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500353 const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300354 if (client == HandleRangeAllocator::kInvalidHandle)
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500355 return OutOfMemory() << "Failed to allocate path handle range.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300356
357 const auto &paths = factory->createPaths(range);
358 if (paths.empty())
359 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500360 mHandleAllocator.releaseRange(client, range);
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500361 return OutOfMemory() << "Failed to allocate path objects.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300362 }
363
Sami Väisänene45e53b2016-05-25 10:36:04 +0300364 for (GLsizei i = 0; i < range; ++i)
365 {
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500366 rx::PathImpl *impl = paths[static_cast<unsigned>(i)];
Sami Väisänene45e53b2016-05-25 10:36:04 +0300367 const auto id = client + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400368 mPaths.assign(id, new Path(impl));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300369 }
Jamie Madill13951342018-09-30 15:24:28 -0400370 *createdOut = client;
371 return NoError();
Sami Väisänene45e53b2016-05-25 10:36:04 +0300372}
373
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500374void PathManager::deletePaths(GLuint first, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300375{
376 for (GLsizei i = 0; i < range; ++i)
377 {
378 const auto id = first + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400379 Path *p = nullptr;
380 if (!mPaths.erase(id, &p))
Sami Väisänene45e53b2016-05-25 10:36:04 +0300381 continue;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300382 delete p;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300383 }
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500384 mHandleAllocator.releaseRange(first, static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300385}
386
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500387Path *PathManager::getPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000388{
Jamie Madill96a483b2017-06-27 16:49:21 -0400389 return mPaths.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000390}
391
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500392bool PathManager::hasPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000393{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500394 return mHandleAllocator.isUsed(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000395}
396
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500397PathManager::~PathManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000398{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500399 ASSERT(mPaths.empty());
400}
401
402void PathManager::reset(const Context *context)
403{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500404 for (auto path : mPaths)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000405 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500406 SafeDelete(path.second);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000407 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500408 mPaths.clear();
Geoff Langf41a7152016-09-19 15:11:17 -0400409}
410
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800411// FramebufferManager Implementation.
412
413// static
414Framebuffer *FramebufferManager::AllocateNewObject(rx::GLImplFactory *factory,
415 GLuint handle,
416 const Caps &caps)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500417{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800418 return new Framebuffer(caps, factory, handle);
419}
420
421// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400422void FramebufferManager::DeleteObject(const Context *context, Framebuffer *framebuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800423{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400424 framebuffer->onDestroy(context);
425 delete framebuffer;
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500426}
427
428GLuint FramebufferManager::createFramebuffer()
429{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800430 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500431}
432
433Framebuffer *FramebufferManager::getFramebuffer(GLuint handle) const
434{
Jamie Madill96a483b2017-06-27 16:49:21 -0400435 return mObjectMap.query(handle);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500436}
437
438void FramebufferManager::setDefaultFramebuffer(Framebuffer *framebuffer)
439{
440 ASSERT(framebuffer == nullptr || framebuffer->id() == 0);
Jamie Madill96a483b2017-06-27 16:49:21 -0400441 mObjectMap.assign(0, framebuffer);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500442}
443
Jamie Madillb983a4b2018-08-01 11:34:51 -0400444void FramebufferManager::invalidateFramebufferComplenessCache(const Context *context) const
Geoff Lang9aded172017-04-05 11:07:56 -0400445{
Jamie Madill96a483b2017-06-27 16:49:21 -0400446 for (const auto &framebuffer : mObjectMap)
Geoff Lang9aded172017-04-05 11:07:56 -0400447 {
448 if (framebuffer.second)
449 {
Jamie Madillb983a4b2018-08-01 11:34:51 -0400450 framebuffer.second->invalidateCompletenessCache(context);
Geoff Lang9aded172017-04-05 11:07:56 -0400451 }
452 }
453}
454
Yunchao Hea336b902017-08-02 16:05:21 +0800455// ProgramPipelineManager Implementation.
456
457// static
458ProgramPipeline *ProgramPipelineManager::AllocateNewObject(rx::GLImplFactory *factory,
459 GLuint handle)
460{
461 ProgramPipeline *pipeline = new ProgramPipeline(factory, handle);
462 pipeline->addRef();
463 return pipeline;
464}
465
466// static
467void ProgramPipelineManager::DeleteObject(const Context *context, ProgramPipeline *pipeline)
468{
469 pipeline->release(context);
470}
471
472GLuint ProgramPipelineManager::createProgramPipeline()
473{
474 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
475}
476
477ProgramPipeline *ProgramPipelineManager::getProgramPipeline(GLuint handle) const
478{
479 return mObjectMap.query(handle);
480}
481
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500482} // namespace gl