blob: 6f5bd508cb354ae6fa03c01fbd83db391e6e02b9 [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"
16#include "libANGLE/Renderbuffer.h"
Jamie Madill53ea9cc2016-05-17 10:12:52 -040017#include "libANGLE/Sampler.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050018#include "libANGLE/Shader.h"
19#include "libANGLE/Texture.h"
Jamie Madill53ea9cc2016-05-17 10:12:52 -040020#include "libANGLE/renderer/GLImplFactory.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000021
22namespace gl
23{
Geoff Lang4ddf5af2016-12-01 14:30:44 -050024
25namespace
26{
27
28template <typename ResourceType>
29GLuint AllocateEmptyObject(HandleAllocator *handleAllocator, ResourceMap<ResourceType> *objectMap)
30{
Jamie Madill96a483b2017-06-27 16:49:21 -040031 GLuint handle = handleAllocator->allocate();
32 objectMap->assign(handle, nullptr);
Geoff Lang4ddf5af2016-12-01 14:30:44 -050033 return handle;
34}
35
Geoff Lang4ddf5af2016-12-01 14:30:44 -050036} // anonymous namespace
37
38template <typename HandleAllocatorType>
39ResourceManagerBase<HandleAllocatorType>::ResourceManagerBase() : mRefCount(1)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000040{
41}
42
Geoff Lang4ddf5af2016-12-01 14:30:44 -050043template <typename HandleAllocatorType>
44void ResourceManagerBase<HandleAllocatorType>::addRef()
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000045{
46 mRefCount++;
47}
48
Geoff Lang4ddf5af2016-12-01 14:30:44 -050049template <typename HandleAllocatorType>
Jamie Madill6c1f6712017-02-14 19:08:04 -050050void ResourceManagerBase<HandleAllocatorType>::release(const Context *context)
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000051{
52 if (--mRefCount == 0)
53 {
Jamie Madill6c1f6712017-02-14 19:08:04 -050054 reset(context);
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000055 delete this;
56 }
57}
58
Jamie Madill5f45e7c2017-02-10 15:23:28 -080059template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
60TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::~TypedResourceManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000061{
Jamie Madill6c1f6712017-02-14 19:08:04 -050062 ASSERT(mObjectMap.empty());
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000063}
64
Jamie Madill5f45e7c2017-02-10 15:23:28 -080065template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
Jamie Madill6c1f6712017-02-14 19:08:04 -050066void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::reset(const Context *context)
67{
Jamie Madill96a483b2017-06-27 16:49:21 -040068 this->mHandleAllocator.reset();
69 for (const auto &resource : mObjectMap)
Jamie Madill6c1f6712017-02-14 19:08:04 -050070 {
Jamie Madill96a483b2017-06-27 16:49:21 -040071 if (resource.second)
72 {
73 ImplT::DeleteObject(context, resource.second);
74 }
Jamie Madill6c1f6712017-02-14 19:08:04 -050075 }
76 mObjectMap.clear();
77}
78
79template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
80void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::deleteObject(
81 const Context *context,
82 GLuint handle)
Geoff Lang4ddf5af2016-12-01 14:30:44 -050083{
Jamie Madill96a483b2017-06-27 16:49:21 -040084 ResourceType *resource = nullptr;
85 if (!mObjectMap.erase(handle, &resource))
Jamie Madill5f45e7c2017-02-10 15:23:28 -080086 {
87 return;
88 }
89
Jamie Madill5f45e7c2017-02-10 15:23:28 -080090 // Requires an explicit this-> because of C++ template rules.
Jamie Madill96a483b2017-06-27 16:49:21 -040091 this->mHandleAllocator.release(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -050092
Jamie Madill96a483b2017-06-27 16:49:21 -040093 if (resource)
Jamie Madill5f45e7c2017-02-10 15:23:28 -080094 {
Jamie Madill96a483b2017-06-27 16:49:21 -040095 ImplT::DeleteObject(context, resource);
Jamie Madill5f45e7c2017-02-10 15:23:28 -080096 }
Jamie Madill5f45e7c2017-02-10 15:23:28 -080097}
98
Geoff Lang4ddf5af2016-12-01 14:30:44 -050099template class ResourceManagerBase<HandleAllocator>;
100template class ResourceManagerBase<HandleRangeAllocator>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800101template class TypedResourceManager<Buffer, HandleAllocator, BufferManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800102template class TypedResourceManager<Texture, HandleAllocator, TextureManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800103template class TypedResourceManager<Renderbuffer, HandleAllocator, RenderbufferManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800104template class TypedResourceManager<Sampler, HandleAllocator, SamplerManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800105template class TypedResourceManager<FenceSync, HandleAllocator, FenceSyncManager>;
106template class TypedResourceManager<Framebuffer, HandleAllocator, FramebufferManager>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800107
108// BufferManager Implementation.
109
110// static
111Buffer *BufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
112{
113 Buffer *buffer = new Buffer(factory, handle);
114 buffer->addRef();
115 return buffer;
116}
117
118// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400119void BufferManager::DeleteObject(const Context *context, Buffer *buffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800120{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400121 buffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800122}
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500123
124GLuint BufferManager::createBuffer()
125{
126 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
127}
128
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500129Buffer *BufferManager::getBuffer(GLuint handle) const
130{
Jamie Madill96a483b2017-06-27 16:49:21 -0400131 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500132}
133
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800134// ShaderProgramManager Implementation.
135
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500136ShaderProgramManager::~ShaderProgramManager()
137{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500138 ASSERT(mPrograms.empty());
139 ASSERT(mShaders.empty());
140}
141
142void ShaderProgramManager::reset(const Context *context)
143{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500144 while (!mPrograms.empty())
145 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500146 deleteProgram(context, mPrograms.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500147 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500148 mPrograms.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500149 while (!mShaders.empty())
150 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500151 deleteShader(context, mShaders.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500152 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500153 mShaders.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500154}
155
156GLuint ShaderProgramManager::createShader(rx::GLImplFactory *factory,
157 const gl::Limitations &rendererLimitations,
158 GLenum type)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000159{
Martin Radev4c4c8e72016-08-04 12:25:34 +0300160 ASSERT(type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER || type == GL_COMPUTE_SHADER);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500161 GLuint handle = mHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400162 mShaders.assign(handle, new Shader(this, factory, rendererLimitations, type, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000163 return handle;
164}
165
Jamie Madill6c1f6712017-02-14 19:08:04 -0500166void ShaderProgramManager::deleteShader(const Context *context, GLuint shader)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000167{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500168 deleteObject(context, &mShaders, shader);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000169}
170
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500171Shader *ShaderProgramManager::getShader(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000172{
Jamie Madill96a483b2017-06-27 16:49:21 -0400173 return mShaders.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000174}
175
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500176GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000177{
Jamie Madill96a483b2017-06-27 16:49:21 -0400178 GLuint handle = mHandleAllocator.allocate();
179 mPrograms.assign(handle, new Program(factory, this, handle));
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000180 return handle;
181}
182
Jamie Madill6c1f6712017-02-14 19:08:04 -0500183void ShaderProgramManager::deleteProgram(const gl::Context *context, GLuint program)
Jamie Madilldc356042013-07-19 16:36:57 -0400184{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500185 deleteObject(context, &mPrograms, program);
Jamie Madilldc356042013-07-19 16:36:57 -0400186}
187
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500188Program *ShaderProgramManager::getProgram(GLuint handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400189{
Jamie Madill96a483b2017-06-27 16:49:21 -0400190 return mPrograms.query(handle);
Jamie Madillcd055f82013-07-26 11:55:15 -0400191}
192
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500193template <typename ObjectType>
Jamie Madill6c1f6712017-02-14 19:08:04 -0500194void ShaderProgramManager::deleteObject(const Context *context,
195 ResourceMap<ObjectType> *objectMap,
196 GLuint id)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500197{
Jamie Madill96a483b2017-06-27 16:49:21 -0400198 ObjectType *object = objectMap->query(id);
199 if (!object)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500200 {
201 return;
202 }
203
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500204 if (object->getRefCount() == 0)
205 {
206 mHandleAllocator.release(id);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400207 object->onDestroy(context);
Jamie Madill96a483b2017-06-27 16:49:21 -0400208 objectMap->erase(id, &object);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500209 }
210 else
211 {
212 object->flagForDeletion();
213 }
214}
215
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800216// TextureManager Implementation.
217
218// static
219Texture *TextureManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle, GLenum target)
220{
221 Texture *texture = new Texture(factory, handle, target);
222 texture->addRef();
223 return texture;
224}
225
226// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400227void TextureManager::DeleteObject(const Context *context, Texture *texture)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800228{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400229 texture->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800230}
231
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500232GLuint TextureManager::createTexture()
233{
234 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
235}
236
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500237Texture *TextureManager::getTexture(GLuint handle) const
238{
Jamie Madill96a483b2017-06-27 16:49:21 -0400239 ASSERT(mObjectMap.query(0) == nullptr);
240 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500241}
242
Jamie Madill96a483b2017-06-27 16:49:21 -0400243void TextureManager::invalidateTextureComplenessCache() const
Geoff Lang9aded172017-04-05 11:07:56 -0400244{
Jamie Madill96a483b2017-06-27 16:49:21 -0400245 for (const auto &texture : mObjectMap)
Geoff Lang9aded172017-04-05 11:07:56 -0400246 {
247 if (texture.second)
248 {
249 texture.second->invalidateCompletenessCache();
250 }
251 }
252}
253
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800254// RenderbufferManager Implementation.
255
256// static
257Renderbuffer *RenderbufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
258{
259 Renderbuffer *renderbuffer = new Renderbuffer(factory->createRenderbuffer(), handle);
260 renderbuffer->addRef();
261 return renderbuffer;
262}
263
264// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400265void RenderbufferManager::DeleteObject(const Context *context, Renderbuffer *renderbuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800266{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400267 renderbuffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800268}
269
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500270GLuint RenderbufferManager::createRenderbuffer()
271{
272 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
273}
274
Yunchao Hea438f4e2017-08-04 13:42:39 +0800275Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500276{
Jamie Madill96a483b2017-06-27 16:49:21 -0400277 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500278}
279
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800280// SamplerManager Implementation.
281
282// static
283Sampler *SamplerManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
284{
285 Sampler *sampler = new Sampler(factory, handle);
286 sampler->addRef();
287 return sampler;
288}
289
290// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400291void SamplerManager::DeleteObject(const Context *context, Sampler *sampler)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800292{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400293 sampler->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800294}
295
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500296GLuint SamplerManager::createSampler()
297{
298 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
299}
300
Yunchao Hea438f4e2017-08-04 13:42:39 +0800301Sampler *SamplerManager::getSampler(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500302{
Jamie Madill96a483b2017-06-27 16:49:21 -0400303 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500304}
305
Yunchao Hea438f4e2017-08-04 13:42:39 +0800306bool SamplerManager::isSampler(GLuint sampler) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500307{
Jamie Madill96a483b2017-06-27 16:49:21 -0400308 return mObjectMap.contains(sampler);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500309}
310
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800311// FenceSyncManager Implementation.
312
313// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400314void FenceSyncManager::DeleteObject(const Context *context, FenceSync *fenceSync)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500315{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400316 fenceSync->release(context);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500317}
318
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800319GLuint FenceSyncManager::createFenceSync(rx::GLImplFactory *factory)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500320{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800321 GLuint handle = mHandleAllocator.allocate();
322 FenceSync *fenceSync = new FenceSync(factory->createFenceSync(), handle);
323 fenceSync->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -0400324 mObjectMap.assign(handle, fenceSync);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800325 return handle;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500326}
327
Yunchao Hea438f4e2017-08-04 13:42:39 +0800328FenceSync *FenceSyncManager::getFenceSync(GLuint handle) const
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500329{
Jamie Madill96a483b2017-06-27 16:49:21 -0400330 return mObjectMap.query(handle);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500331}
332
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800333// PathManager Implementation.
334
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500335ErrorOrResult<GLuint> PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300336{
337 // Allocate client side handles.
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500338 const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300339 if (client == HandleRangeAllocator::kInvalidHandle)
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500340 return OutOfMemory() << "Failed to allocate path handle range.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300341
342 const auto &paths = factory->createPaths(range);
343 if (paths.empty())
344 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500345 mHandleAllocator.releaseRange(client, range);
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500346 return OutOfMemory() << "Failed to allocate path objects.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300347 }
348
Sami Väisänene45e53b2016-05-25 10:36:04 +0300349 for (GLsizei i = 0; i < range; ++i)
350 {
351 const auto impl = paths[static_cast<unsigned>(i)];
352 const auto id = client + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400353 mPaths.assign(id, new Path(impl));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300354 }
355 return client;
356}
357
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500358void PathManager::deletePaths(GLuint first, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300359{
360 for (GLsizei i = 0; i < range; ++i)
361 {
362 const auto id = first + i;
Jamie Madill96a483b2017-06-27 16:49:21 -0400363 Path *p = nullptr;
364 if (!mPaths.erase(id, &p))
Sami Väisänene45e53b2016-05-25 10:36:04 +0300365 continue;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300366 delete p;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300367 }
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500368 mHandleAllocator.releaseRange(first, static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300369}
370
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500371Path *PathManager::getPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000372{
Jamie Madill96a483b2017-06-27 16:49:21 -0400373 return mPaths.query(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000374}
375
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500376bool PathManager::hasPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000377{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500378 return mHandleAllocator.isUsed(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000379}
380
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500381PathManager::~PathManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000382{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500383 ASSERT(mPaths.empty());
384}
385
386void PathManager::reset(const Context *context)
387{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500388 for (auto path : mPaths)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000389 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500390 SafeDelete(path.second);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000391 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500392 mPaths.clear();
Geoff Langf41a7152016-09-19 15:11:17 -0400393}
394
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800395// FramebufferManager Implementation.
396
397// static
398Framebuffer *FramebufferManager::AllocateNewObject(rx::GLImplFactory *factory,
399 GLuint handle,
400 const Caps &caps)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500401{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800402 return new Framebuffer(caps, factory, handle);
403}
404
405// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400406void FramebufferManager::DeleteObject(const Context *context, Framebuffer *framebuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800407{
408 // Default framebuffer are owned by their respective Surface
409 if (framebuffer->id() != 0)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500410 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400411 framebuffer->onDestroy(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800412 delete framebuffer;
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500413 }
414}
415
416GLuint FramebufferManager::createFramebuffer()
417{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800418 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500419}
420
421Framebuffer *FramebufferManager::getFramebuffer(GLuint handle) const
422{
Jamie Madill96a483b2017-06-27 16:49:21 -0400423 return mObjectMap.query(handle);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500424}
425
426void FramebufferManager::setDefaultFramebuffer(Framebuffer *framebuffer)
427{
428 ASSERT(framebuffer == nullptr || framebuffer->id() == 0);
Jamie Madill96a483b2017-06-27 16:49:21 -0400429 mObjectMap.assign(0, framebuffer);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500430}
431
Jamie Madill96a483b2017-06-27 16:49:21 -0400432void FramebufferManager::invalidateFramebufferComplenessCache() const
Geoff Lang9aded172017-04-05 11:07:56 -0400433{
Jamie Madill96a483b2017-06-27 16:49:21 -0400434 for (const auto &framebuffer : mObjectMap)
Geoff Lang9aded172017-04-05 11:07:56 -0400435 {
436 if (framebuffer.second)
437 {
438 framebuffer.second->invalidateCompletenessCache();
439 }
440 }
441}
442
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500443} // namespace gl