blob: 91ad8eff5d0f2fc4cc805f87b7cbc458304aa17e [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{
Martin Radev4c4c8e72016-08-04 12:25:34 +0300162 ASSERT(type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER || type == GL_COMPUTE_SHADER);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500163 GLuint handle = mHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400164 mShaders.assign(handle, new Shader(this, factory, rendererLimitations, type, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000165 return handle;
166}
167
Jamie Madill6c1f6712017-02-14 19:08:04 -0500168void ShaderProgramManager::deleteShader(const Context *context, GLuint shader)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000169{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500170 deleteObject(context, &mShaders, shader);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000171}
172
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500173Shader *ShaderProgramManager::getShader(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000174{
Jamie Madill96a483b2017-06-27 16:49:21 -0400175 return mShaders.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000176}
177
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500178GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000179{
Jamie Madill96a483b2017-06-27 16:49:21 -0400180 GLuint handle = mHandleAllocator.allocate();
181 mPrograms.assign(handle, new Program(factory, this, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000182 return handle;
183}
184
Jamie Madill6c1f6712017-02-14 19:08:04 -0500185void ShaderProgramManager::deleteProgram(const gl::Context *context, GLuint program)
Jamie Madilldc356042013-07-19 16:36:57 -0400186{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500187 deleteObject(context, &mPrograms, program);
Jamie Madilldc356042013-07-19 16:36:57 -0400188}
189
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500190Program *ShaderProgramManager::getProgram(GLuint handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400191{
Jamie Madill96a483b2017-06-27 16:49:21 -0400192 return mPrograms.query(handle);
Jamie Madillcd055f82013-07-26 11:55:15 -0400193}
194
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500195template <typename ObjectType>
Jamie Madill6c1f6712017-02-14 19:08:04 -0500196void ShaderProgramManager::deleteObject(const Context *context,
197 ResourceMap<ObjectType> *objectMap,
198 GLuint id)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500199{
Jamie Madill96a483b2017-06-27 16:49:21 -0400200 ObjectType *object = objectMap->query(id);
201 if (!object)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500202 {
203 return;
204 }
205
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500206 if (object->getRefCount() == 0)
207 {
208 mHandleAllocator.release(id);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400209 object->onDestroy(context);
Jamie Madill96a483b2017-06-27 16:49:21 -0400210 objectMap->erase(id, &object);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500211 }
212 else
213 {
214 object->flagForDeletion();
215 }
216}
217
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800218// TextureManager Implementation.
219
220// static
221Texture *TextureManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle, GLenum target)
222{
223 Texture *texture = new Texture(factory, handle, target);
224 texture->addRef();
225 return texture;
226}
227
228// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400229void TextureManager::DeleteObject(const Context *context, Texture *texture)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800230{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400231 texture->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800232}
233
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500234GLuint TextureManager::createTexture()
235{
236 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
237}
238
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500239Texture *TextureManager::getTexture(GLuint handle) const
240{
Jamie Madill96a483b2017-06-27 16:49:21 -0400241 ASSERT(mObjectMap.query(0) == nullptr);
242 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500243}
244
Jamie Madill81c2e252017-09-09 23:32:46 -0400245void TextureManager::signalAllTexturesDirty() 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 Madill81c2e252017-09-09 23:32:46 -0400251 texture.second->signalDirty();
Geoff Lang9aded172017-04-05 11:07:56 -0400252 }
253 }
254}
255
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800256// RenderbufferManager Implementation.
257
258// static
259Renderbuffer *RenderbufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
260{
261 Renderbuffer *renderbuffer = new Renderbuffer(factory->createRenderbuffer(), handle);
262 renderbuffer->addRef();
263 return renderbuffer;
264}
265
266// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400267void RenderbufferManager::DeleteObject(const Context *context, Renderbuffer *renderbuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800268{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400269 renderbuffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800270}
271
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500272GLuint RenderbufferManager::createRenderbuffer()
273{
274 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
275}
276
Yunchao Hea438f4e2017-08-04 13:42:39 +0800277Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500278{
Jamie Madill96a483b2017-06-27 16:49:21 -0400279 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500280}
281
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800282// SamplerManager Implementation.
283
284// static
285Sampler *SamplerManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
286{
287 Sampler *sampler = new Sampler(factory, handle);
288 sampler->addRef();
289 return sampler;
290}
291
292// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400293void SamplerManager::DeleteObject(const Context *context, Sampler *sampler)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800294{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400295 sampler->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800296}
297
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500298GLuint SamplerManager::createSampler()
299{
300 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
301}
302
Yunchao Hea438f4e2017-08-04 13:42:39 +0800303Sampler *SamplerManager::getSampler(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500304{
Jamie Madill96a483b2017-06-27 16:49:21 -0400305 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500306}
307
Yunchao Hea438f4e2017-08-04 13:42:39 +0800308bool SamplerManager::isSampler(GLuint sampler) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500309{
Jamie Madill96a483b2017-06-27 16:49:21 -0400310 return mObjectMap.contains(sampler);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500311}
312
Jamie Madill70b5bb02017-08-28 13:32:37 -0400313// SyncManager Implementation.
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800314
315// static
Jamie Madill70b5bb02017-08-28 13:32:37 -0400316void SyncManager::DeleteObject(const Context *context, Sync *sync)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500317{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400318 sync->release(context);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500319}
320
Jamie Madill70b5bb02017-08-28 13:32:37 -0400321GLuint SyncManager::createSync(rx::GLImplFactory *factory)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500322{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400323 GLuint handle = mHandleAllocator.allocate();
324 Sync *sync = new Sync(factory->createSync(), handle);
325 sync->addRef();
326 mObjectMap.assign(handle, sync);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800327 return handle;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500328}
329
Jamie Madill70b5bb02017-08-28 13:32:37 -0400330Sync *SyncManager::getSync(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500331{
Jamie Madill96a483b2017-06-27 16:49:21 -0400332 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500333}
334
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800335// PathManager Implementation.
336
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500337ErrorOrResult<GLuint> PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300338{
339 // Allocate client side handles.
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500340 const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300341 if (client == HandleRangeAllocator::kInvalidHandle)
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500342 return OutOfMemory() << "Failed to allocate path handle range.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300343
344 const auto &paths = factory->createPaths(range);
345 if (paths.empty())
346 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500347 mHandleAllocator.releaseRange(client, range);
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500348 return OutOfMemory() << "Failed to allocate path objects.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300349 }
350
Sami Väisänene45e53b2016-05-25 10:36:04 +0300351 for (GLsizei i = 0; i < range; ++i)
352 {
353 const auto impl = paths[static_cast<unsigned>(i)];
354 const auto id = client + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400355 mPaths.assign(id, new Path(impl));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300356 }
357 return client;
358}
359
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500360void PathManager::deletePaths(GLuint first, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300361{
362 for (GLsizei i = 0; i < range; ++i)
363 {
364 const auto id = first + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400365 Path *p = nullptr;
366 if (!mPaths.erase(id, &p))
Sami Väisänene45e53b2016-05-25 10:36:04 +0300367 continue;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300368 delete p;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300369 }
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500370 mHandleAllocator.releaseRange(first, static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300371}
372
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500373Path *PathManager::getPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000374{
Jamie Madill96a483b2017-06-27 16:49:21 -0400375 return mPaths.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000376}
377
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500378bool PathManager::hasPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000379{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500380 return mHandleAllocator.isUsed(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000381}
382
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500383PathManager::~PathManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000384{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500385 ASSERT(mPaths.empty());
386}
387
388void PathManager::reset(const Context *context)
389{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500390 for (auto path : mPaths)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000391 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500392 SafeDelete(path.second);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000393 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500394 mPaths.clear();
Geoff Langf41a7152016-09-19 15:11:17 -0400395}
396
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800397// FramebufferManager Implementation.
398
399// static
400Framebuffer *FramebufferManager::AllocateNewObject(rx::GLImplFactory *factory,
401 GLuint handle,
402 const Caps &caps)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500403{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800404 return new Framebuffer(caps, factory, handle);
405}
406
407// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400408void FramebufferManager::DeleteObject(const Context *context, Framebuffer *framebuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800409{
410 // Default framebuffer are owned by their respective Surface
411 if (framebuffer->id() != 0)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500412 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400413 framebuffer->onDestroy(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800414 delete framebuffer;
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500415 }
416}
417
418GLuint FramebufferManager::createFramebuffer()
419{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800420 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500421}
422
423Framebuffer *FramebufferManager::getFramebuffer(GLuint handle) const
424{
Jamie Madill96a483b2017-06-27 16:49:21 -0400425 return mObjectMap.query(handle);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500426}
427
428void FramebufferManager::setDefaultFramebuffer(Framebuffer *framebuffer)
429{
430 ASSERT(framebuffer == nullptr || framebuffer->id() == 0);
Jamie Madill96a483b2017-06-27 16:49:21 -0400431 mObjectMap.assign(0, framebuffer);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500432}
433
Jamie Madill96a483b2017-06-27 16:49:21 -0400434void FramebufferManager::invalidateFramebufferComplenessCache() const
Geoff Lang9aded172017-04-05 11:07:56 -0400435{
Jamie Madill96a483b2017-06-27 16:49:21 -0400436 for (const auto &framebuffer : mObjectMap)
Geoff Lang9aded172017-04-05 11:07:56 -0400437 {
438 if (framebuffer.second)
439 {
440 framebuffer.second->invalidateCompletenessCache();
441 }
442 }
443}
444
Yunchao Hea336b902017-08-02 16:05:21 +0800445// ProgramPipelineManager Implementation.
446
447// static
448ProgramPipeline *ProgramPipelineManager::AllocateNewObject(rx::GLImplFactory *factory,
449 GLuint handle)
450{
451 ProgramPipeline *pipeline = new ProgramPipeline(factory, handle);
452 pipeline->addRef();
453 return pipeline;
454}
455
456// static
457void ProgramPipelineManager::DeleteObject(const Context *context, ProgramPipeline *pipeline)
458{
459 pipeline->release(context);
460}
461
462GLuint ProgramPipelineManager::createProgramPipeline()
463{
464 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
465}
466
467ProgramPipeline *ProgramPipelineManager::getProgramPipeline(GLuint handle) const
468{
469 return mObjectMap.query(handle);
470}
471
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500472} // namespace gl