blob: 1b7e966e5d5495d80a12a5aeca5a9518cb8f38e7 [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
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500138ShaderProgramManager::~ShaderProgramManager()
139{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500140 ASSERT(mPrograms.empty());
141 ASSERT(mShaders.empty());
142}
143
144void ShaderProgramManager::reset(const Context *context)
145{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500146 while (!mPrograms.empty())
147 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500148 deleteProgram(context, mPrograms.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500149 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500150 mPrograms.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500151 while (!mShaders.empty())
152 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500153 deleteShader(context, mShaders.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500154 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500155 mShaders.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500156}
157
158GLuint ShaderProgramManager::createShader(rx::GLImplFactory *factory,
159 const gl::Limitations &rendererLimitations,
160 GLenum type)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000161{
Jiawei Shao89be29a2017-11-06 14:36:45 +0800162 ASSERT(type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER || type == GL_COMPUTE_SHADER ||
163 type == GL_GEOMETRY_SHADER_EXT);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500164 GLuint handle = mHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400165 mShaders.assign(handle, new Shader(this, factory, rendererLimitations, type, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000166 return handle;
167}
168
Jamie Madill6c1f6712017-02-14 19:08:04 -0500169void ShaderProgramManager::deleteShader(const Context *context, GLuint shader)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000170{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500171 deleteObject(context, &mShaders, shader);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000172}
173
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500174Shader *ShaderProgramManager::getShader(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000175{
Jamie Madill96a483b2017-06-27 16:49:21 -0400176 return mShaders.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000177}
178
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500179GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000180{
Jamie Madill96a483b2017-06-27 16:49:21 -0400181 GLuint handle = mHandleAllocator.allocate();
182 mPrograms.assign(handle, new Program(factory, this, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000183 return handle;
184}
185
Jamie Madill6c1f6712017-02-14 19:08:04 -0500186void ShaderProgramManager::deleteProgram(const gl::Context *context, GLuint program)
Jamie Madilldc356042013-07-19 16:36:57 -0400187{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500188 deleteObject(context, &mPrograms, program);
Jamie Madilldc356042013-07-19 16:36:57 -0400189}
190
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500191Program *ShaderProgramManager::getProgram(GLuint handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400192{
Jamie Madill96a483b2017-06-27 16:49:21 -0400193 return mPrograms.query(handle);
Jamie Madillcd055f82013-07-26 11:55:15 -0400194}
195
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500196template <typename ObjectType>
Jamie Madill6c1f6712017-02-14 19:08:04 -0500197void ShaderProgramManager::deleteObject(const Context *context,
198 ResourceMap<ObjectType> *objectMap,
199 GLuint id)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500200{
Jamie Madill96a483b2017-06-27 16:49:21 -0400201 ObjectType *object = objectMap->query(id);
202 if (!object)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500203 {
204 return;
205 }
206
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500207 if (object->getRefCount() == 0)
208 {
209 mHandleAllocator.release(id);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400210 object->onDestroy(context);
Jamie Madill96a483b2017-06-27 16:49:21 -0400211 objectMap->erase(id, &object);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500212 }
213 else
214 {
215 object->flagForDeletion();
216 }
217}
218
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800219// TextureManager Implementation.
220
221// static
222Texture *TextureManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle, GLenum target)
223{
224 Texture *texture = new Texture(factory, handle, target);
225 texture->addRef();
226 return texture;
227}
228
229// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400230void TextureManager::DeleteObject(const Context *context, Texture *texture)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800231{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400232 texture->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800233}
234
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500235GLuint TextureManager::createTexture()
236{
237 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
238}
239
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500240Texture *TextureManager::getTexture(GLuint handle) const
241{
Jamie Madill96a483b2017-06-27 16:49:21 -0400242 ASSERT(mObjectMap.query(0) == nullptr);
243 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500244}
245
Jamie Madill81c2e252017-09-09 23:32:46 -0400246void TextureManager::signalAllTexturesDirty() const
Geoff Lang9aded172017-04-05 11:07:56 -0400247{
Jamie Madill96a483b2017-06-27 16:49:21 -0400248 for (const auto &texture : mObjectMap)
Geoff Lang9aded172017-04-05 11:07:56 -0400249 {
250 if (texture.second)
251 {
Jamie Madill05b35b22017-10-03 09:01:44 -0400252 // We don't know if the Texture needs init, but that's ok, since it will only force
253 // a re-check, and will not initialize the pixels if it's not needed.
254 texture.second->signalDirty(InitState::MayNeedInit);
Geoff Lang9aded172017-04-05 11:07:56 -0400255 }
256 }
257}
258
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800259// RenderbufferManager Implementation.
260
261// static
262Renderbuffer *RenderbufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
263{
264 Renderbuffer *renderbuffer = new Renderbuffer(factory->createRenderbuffer(), handle);
265 renderbuffer->addRef();
266 return renderbuffer;
267}
268
269// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400270void RenderbufferManager::DeleteObject(const Context *context, Renderbuffer *renderbuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800271{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400272 renderbuffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800273}
274
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500275GLuint RenderbufferManager::createRenderbuffer()
276{
277 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
278}
279
Yunchao Hea438f4e2017-08-04 13:42:39 +0800280Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500281{
Jamie Madill96a483b2017-06-27 16:49:21 -0400282 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500283}
284
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800285// SamplerManager Implementation.
286
287// static
288Sampler *SamplerManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
289{
290 Sampler *sampler = new Sampler(factory, handle);
291 sampler->addRef();
292 return sampler;
293}
294
295// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400296void SamplerManager::DeleteObject(const Context *context, Sampler *sampler)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800297{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400298 sampler->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800299}
300
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500301GLuint SamplerManager::createSampler()
302{
303 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
304}
305
Yunchao Hea438f4e2017-08-04 13:42:39 +0800306Sampler *SamplerManager::getSampler(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500307{
Jamie Madill96a483b2017-06-27 16:49:21 -0400308 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500309}
310
Yunchao Hea438f4e2017-08-04 13:42:39 +0800311bool SamplerManager::isSampler(GLuint sampler) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500312{
Jamie Madill96a483b2017-06-27 16:49:21 -0400313 return mObjectMap.contains(sampler);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500314}
315
Jamie Madill70b5bb02017-08-28 13:32:37 -0400316// SyncManager Implementation.
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800317
318// static
Jamie Madill70b5bb02017-08-28 13:32:37 -0400319void SyncManager::DeleteObject(const Context *context, Sync *sync)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500320{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400321 sync->release(context);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500322}
323
Jamie Madill70b5bb02017-08-28 13:32:37 -0400324GLuint SyncManager::createSync(rx::GLImplFactory *factory)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500325{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400326 GLuint handle = mHandleAllocator.allocate();
327 Sync *sync = new Sync(factory->createSync(), handle);
328 sync->addRef();
329 mObjectMap.assign(handle, sync);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800330 return handle;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500331}
332
Jamie Madill70b5bb02017-08-28 13:32:37 -0400333Sync *SyncManager::getSync(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500334{
Jamie Madill96a483b2017-06-27 16:49:21 -0400335 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500336}
337
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800338// PathManager Implementation.
339
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500340ErrorOrResult<GLuint> PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300341{
342 // Allocate client side handles.
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500343 const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300344 if (client == HandleRangeAllocator::kInvalidHandle)
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500345 return OutOfMemory() << "Failed to allocate path handle range.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300346
347 const auto &paths = factory->createPaths(range);
348 if (paths.empty())
349 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500350 mHandleAllocator.releaseRange(client, range);
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500351 return OutOfMemory() << "Failed to allocate path objects.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300352 }
353
Sami Väisänene45e53b2016-05-25 10:36:04 +0300354 for (GLsizei i = 0; i < range; ++i)
355 {
356 const auto impl = paths[static_cast<unsigned>(i)];
357 const auto id = client + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400358 mPaths.assign(id, new Path(impl));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300359 }
360 return client;
361}
362
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500363void PathManager::deletePaths(GLuint first, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300364{
365 for (GLsizei i = 0; i < range; ++i)
366 {
367 const auto id = first + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400368 Path *p = nullptr;
369 if (!mPaths.erase(id, &p))
Sami Väisänene45e53b2016-05-25 10:36:04 +0300370 continue;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300371 delete p;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300372 }
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500373 mHandleAllocator.releaseRange(first, static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300374}
375
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500376Path *PathManager::getPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000377{
Jamie Madill96a483b2017-06-27 16:49:21 -0400378 return mPaths.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000379}
380
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500381bool PathManager::hasPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000382{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500383 return mHandleAllocator.isUsed(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000384}
385
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500386PathManager::~PathManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000387{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500388 ASSERT(mPaths.empty());
389}
390
391void PathManager::reset(const Context *context)
392{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500393 for (auto path : mPaths)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000394 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500395 SafeDelete(path.second);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000396 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500397 mPaths.clear();
Geoff Langf41a7152016-09-19 15:11:17 -0400398}
399
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800400// FramebufferManager Implementation.
401
402// static
403Framebuffer *FramebufferManager::AllocateNewObject(rx::GLImplFactory *factory,
404 GLuint handle,
405 const Caps &caps)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500406{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800407 return new Framebuffer(caps, factory, handle);
408}
409
410// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400411void FramebufferManager::DeleteObject(const Context *context, Framebuffer *framebuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800412{
413 // Default framebuffer are owned by their respective Surface
414 if (framebuffer->id() != 0)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500415 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400416 framebuffer->onDestroy(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800417 delete framebuffer;
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500418 }
419}
420
421GLuint FramebufferManager::createFramebuffer()
422{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800423 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500424}
425
426Framebuffer *FramebufferManager::getFramebuffer(GLuint handle) const
427{
Jamie Madill96a483b2017-06-27 16:49:21 -0400428 return mObjectMap.query(handle);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500429}
430
431void FramebufferManager::setDefaultFramebuffer(Framebuffer *framebuffer)
432{
433 ASSERT(framebuffer == nullptr || framebuffer->id() == 0);
Jamie Madill96a483b2017-06-27 16:49:21 -0400434 mObjectMap.assign(0, framebuffer);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500435}
436
Jamie Madill96a483b2017-06-27 16:49:21 -0400437void FramebufferManager::invalidateFramebufferComplenessCache() const
Geoff Lang9aded172017-04-05 11:07:56 -0400438{
Jamie Madill96a483b2017-06-27 16:49:21 -0400439 for (const auto &framebuffer : mObjectMap)
Geoff Lang9aded172017-04-05 11:07:56 -0400440 {
441 if (framebuffer.second)
442 {
443 framebuffer.second->invalidateCompletenessCache();
444 }
445 }
446}
447
Yunchao Hea336b902017-08-02 16:05:21 +0800448// ProgramPipelineManager Implementation.
449
450// static
451ProgramPipeline *ProgramPipelineManager::AllocateNewObject(rx::GLImplFactory *factory,
452 GLuint handle)
453{
454 ProgramPipeline *pipeline = new ProgramPipeline(factory, handle);
455 pipeline->addRef();
456 return pipeline;
457}
458
459// static
460void ProgramPipelineManager::DeleteObject(const Context *context, ProgramPipeline *pipeline)
461{
462 pipeline->release(context);
463}
464
465GLuint ProgramPipelineManager::createProgramPipeline()
466{
467 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
468}
469
470ProgramPipeline *ProgramPipelineManager::getProgramPipeline(GLuint handle) const
471{
472 return mObjectMap.query(handle);
473}
474
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500475} // namespace gl