blob: aa4f59077daf1a107fc410e267a902ea0c222333 [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,
164 GLenum type)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000165{
Jiawei Shao89be29a2017-11-06 14:36:45 +0800166 ASSERT(type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER || type == GL_COMPUTE_SHADER ||
167 type == GL_GEOMETRY_SHADER_EXT);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500168 GLuint handle = mHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400169 mShaders.assign(handle, new Shader(this, factory, rendererLimitations, type, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000170 return handle;
171}
172
Jamie Madill6c1f6712017-02-14 19:08:04 -0500173void ShaderProgramManager::deleteShader(const Context *context, GLuint shader)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000174{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500175 deleteObject(context, &mShaders, shader);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000176}
177
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500178Shader *ShaderProgramManager::getShader(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000179{
Jamie Madill96a483b2017-06-27 16:49:21 -0400180 return mShaders.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000181}
182
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500183GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000184{
Jamie Madill96a483b2017-06-27 16:49:21 -0400185 GLuint handle = mHandleAllocator.allocate();
186 mPrograms.assign(handle, new Program(factory, this, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000187 return handle;
188}
189
Jamie Madill6c1f6712017-02-14 19:08:04 -0500190void ShaderProgramManager::deleteProgram(const gl::Context *context, GLuint program)
Jamie Madilldc356042013-07-19 16:36:57 -0400191{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500192 deleteObject(context, &mPrograms, program);
Jamie Madilldc356042013-07-19 16:36:57 -0400193}
194
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500195Program *ShaderProgramManager::getProgram(GLuint handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400196{
Jamie Madill96a483b2017-06-27 16:49:21 -0400197 return mPrograms.query(handle);
Jamie Madillcd055f82013-07-26 11:55:15 -0400198}
199
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500200template <typename ObjectType>
Jamie Madill6c1f6712017-02-14 19:08:04 -0500201void ShaderProgramManager::deleteObject(const Context *context,
202 ResourceMap<ObjectType> *objectMap,
203 GLuint id)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500204{
Jamie Madill96a483b2017-06-27 16:49:21 -0400205 ObjectType *object = objectMap->query(id);
206 if (!object)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500207 {
208 return;
209 }
210
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500211 if (object->getRefCount() == 0)
212 {
213 mHandleAllocator.release(id);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400214 object->onDestroy(context);
Jamie Madill96a483b2017-06-27 16:49:21 -0400215 objectMap->erase(id, &object);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500216 }
217 else
218 {
219 object->flagForDeletion();
220 }
221}
222
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800223// TextureManager Implementation.
224
225// static
Corentin Wallez99d492c2018-02-27 15:17:10 -0500226Texture *TextureManager::AllocateNewObject(rx::GLImplFactory *factory,
227 GLuint handle,
228 TextureType type)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800229{
Corentin Wallez99d492c2018-02-27 15:17:10 -0500230 Texture *texture = new Texture(factory, handle, type);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800231 texture->addRef();
232 return texture;
233}
234
235// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400236void TextureManager::DeleteObject(const Context *context, Texture *texture)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800237{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400238 texture->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800239}
240
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500241GLuint TextureManager::createTexture()
242{
243 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
244}
245
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500246Texture *TextureManager::getTexture(GLuint handle) const
247{
Jamie Madill96a483b2017-06-27 16:49:21 -0400248 ASSERT(mObjectMap.query(0) == nullptr);
249 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500250}
251
Jamie Madilld4442552018-02-27 22:03:47 -0500252void TextureManager::signalAllTexturesDirty(const Context *context) const
Geoff Lang9aded172017-04-05 11:07:56 -0400253{
Jamie Madill96a483b2017-06-27 16:49:21 -0400254 for (const auto &texture : mObjectMap)
Geoff Lang9aded172017-04-05 11:07:56 -0400255 {
256 if (texture.second)
257 {
Jamie Madill05b35b22017-10-03 09:01:44 -0400258 // We don't know if the Texture needs init, but that's ok, since it will only force
259 // a re-check, and will not initialize the pixels if it's not needed.
Jamie Madilld4442552018-02-27 22:03:47 -0500260 texture.second->signalDirty(context, InitState::MayNeedInit);
Geoff Lang9aded172017-04-05 11:07:56 -0400261 }
262 }
263}
264
Jamie Madillfc3463d2018-01-03 13:46:21 -0500265void TextureManager::enableHandleAllocatorLogging()
266{
267 mHandleAllocator.enableLogging(true);
268}
269
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800270// RenderbufferManager Implementation.
271
272// static
273Renderbuffer *RenderbufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
274{
Jamie Madille703c602018-02-20 10:21:48 -0500275 Renderbuffer *renderbuffer = new Renderbuffer(factory, handle);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800276 renderbuffer->addRef();
277 return renderbuffer;
278}
279
280// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400281void RenderbufferManager::DeleteObject(const Context *context, Renderbuffer *renderbuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800282{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400283 renderbuffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800284}
285
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500286GLuint RenderbufferManager::createRenderbuffer()
287{
288 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
289}
290
Yunchao Hea438f4e2017-08-04 13:42:39 +0800291Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500292{
Jamie Madill96a483b2017-06-27 16:49:21 -0400293 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500294}
295
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800296// SamplerManager Implementation.
297
298// static
299Sampler *SamplerManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
300{
301 Sampler *sampler = new Sampler(factory, handle);
302 sampler->addRef();
303 return sampler;
304}
305
306// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400307void SamplerManager::DeleteObject(const Context *context, Sampler *sampler)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800308{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400309 sampler->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800310}
311
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500312GLuint SamplerManager::createSampler()
313{
314 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
315}
316
Yunchao Hea438f4e2017-08-04 13:42:39 +0800317Sampler *SamplerManager::getSampler(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500318{
Jamie Madill96a483b2017-06-27 16:49:21 -0400319 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500320}
321
Yunchao Hea438f4e2017-08-04 13:42:39 +0800322bool SamplerManager::isSampler(GLuint sampler) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500323{
Jamie Madill96a483b2017-06-27 16:49:21 -0400324 return mObjectMap.contains(sampler);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500325}
326
Jamie Madill70b5bb02017-08-28 13:32:37 -0400327// SyncManager Implementation.
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800328
329// static
Jamie Madill70b5bb02017-08-28 13:32:37 -0400330void SyncManager::DeleteObject(const Context *context, Sync *sync)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500331{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400332 sync->release(context);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500333}
334
Jamie Madill70b5bb02017-08-28 13:32:37 -0400335GLuint SyncManager::createSync(rx::GLImplFactory *factory)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500336{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400337 GLuint handle = mHandleAllocator.allocate();
338 Sync *sync = new Sync(factory->createSync(), handle);
339 sync->addRef();
340 mObjectMap.assign(handle, sync);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800341 return handle;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500342}
343
Jamie Madill70b5bb02017-08-28 13:32:37 -0400344Sync *SyncManager::getSync(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500345{
Jamie Madill96a483b2017-06-27 16:49:21 -0400346 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500347}
348
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800349// PathManager Implementation.
350
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500351PathManager::PathManager()
352{
353}
354
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500355ErrorOrResult<GLuint> PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300356{
357 // Allocate client side handles.
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500358 const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300359 if (client == HandleRangeAllocator::kInvalidHandle)
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500360 return OutOfMemory() << "Failed to allocate path handle range.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300361
362 const auto &paths = factory->createPaths(range);
363 if (paths.empty())
364 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500365 mHandleAllocator.releaseRange(client, range);
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500366 return OutOfMemory() << "Failed to allocate path objects.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300367 }
368
Sami Väisänene45e53b2016-05-25 10:36:04 +0300369 for (GLsizei i = 0; i < range; ++i)
370 {
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500371 rx::PathImpl *impl = paths[static_cast<unsigned>(i)];
Sami Väisänene45e53b2016-05-25 10:36:04 +0300372 const auto id = client + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400373 mPaths.assign(id, new Path(impl));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300374 }
375 return client;
376}
377
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500378void PathManager::deletePaths(GLuint first, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300379{
380 for (GLsizei i = 0; i < range; ++i)
381 {
382 const auto id = first + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400383 Path *p = nullptr;
384 if (!mPaths.erase(id, &p))
Sami Väisänene45e53b2016-05-25 10:36:04 +0300385 continue;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300386 delete p;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300387 }
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500388 mHandleAllocator.releaseRange(first, static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300389}
390
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500391Path *PathManager::getPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000392{
Jamie Madill96a483b2017-06-27 16:49:21 -0400393 return mPaths.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000394}
395
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500396bool PathManager::hasPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000397{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500398 return mHandleAllocator.isUsed(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000399}
400
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500401PathManager::~PathManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000402{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500403 ASSERT(mPaths.empty());
404}
405
406void PathManager::reset(const Context *context)
407{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500408 for (auto path : mPaths)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000409 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500410 SafeDelete(path.second);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000411 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500412 mPaths.clear();
Geoff Langf41a7152016-09-19 15:11:17 -0400413}
414
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800415// FramebufferManager Implementation.
416
417// static
418Framebuffer *FramebufferManager::AllocateNewObject(rx::GLImplFactory *factory,
419 GLuint handle,
420 const Caps &caps)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500421{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800422 return new Framebuffer(caps, factory, handle);
423}
424
425// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400426void FramebufferManager::DeleteObject(const Context *context, Framebuffer *framebuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800427{
428 // Default framebuffer are owned by their respective Surface
429 if (framebuffer->id() != 0)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500430 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400431 framebuffer->onDestroy(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800432 delete framebuffer;
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500433 }
434}
435
436GLuint FramebufferManager::createFramebuffer()
437{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800438 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500439}
440
441Framebuffer *FramebufferManager::getFramebuffer(GLuint handle) const
442{
Jamie Madill96a483b2017-06-27 16:49:21 -0400443 return mObjectMap.query(handle);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500444}
445
446void FramebufferManager::setDefaultFramebuffer(Framebuffer *framebuffer)
447{
448 ASSERT(framebuffer == nullptr || framebuffer->id() == 0);
Jamie Madill96a483b2017-06-27 16:49:21 -0400449 mObjectMap.assign(0, framebuffer);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500450}
451
Jamie Madill96a483b2017-06-27 16:49:21 -0400452void FramebufferManager::invalidateFramebufferComplenessCache() const
Geoff Lang9aded172017-04-05 11:07:56 -0400453{
Jamie Madill96a483b2017-06-27 16:49:21 -0400454 for (const auto &framebuffer : mObjectMap)
Geoff Lang9aded172017-04-05 11:07:56 -0400455 {
456 if (framebuffer.second)
457 {
458 framebuffer.second->invalidateCompletenessCache();
459 }
460 }
461}
462
Yunchao Hea336b902017-08-02 16:05:21 +0800463// ProgramPipelineManager Implementation.
464
465// static
466ProgramPipeline *ProgramPipelineManager::AllocateNewObject(rx::GLImplFactory *factory,
467 GLuint handle)
468{
469 ProgramPipeline *pipeline = new ProgramPipeline(factory, handle);
470 pipeline->addRef();
471 return pipeline;
472}
473
474// static
475void ProgramPipelineManager::DeleteObject(const Context *context, ProgramPipeline *pipeline)
476{
477 pipeline->release(context);
478}
479
480GLuint ProgramPipelineManager::createProgramPipeline()
481{
482 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
483}
484
485ProgramPipeline *ProgramPipelineManager::getProgramPipeline(GLuint handle) const
486{
487 return mObjectMap.query(handle);
488}
489
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500490} // namespace gl