blob: d8690b7589fab2e9ccf90aead1fdfddb0eb48516 [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{
31 GLuint handle = handleAllocator->allocate();
32 (*objectMap)[handle] = nullptr;
33 return handle;
34}
35
Geoff Lang4ddf5af2016-12-01 14:30:44 -050036template <typename ResourceType>
37ResourceType *GetObject(const ResourceMap<ResourceType> &objectMap, GLuint handle)
38{
39 auto iter = objectMap.find(handle);
40 return iter != objectMap.end() ? iter->second : nullptr;
41}
42
43} // anonymous namespace
44
45template <typename HandleAllocatorType>
46ResourceManagerBase<HandleAllocatorType>::ResourceManagerBase() : mRefCount(1)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000047{
48}
49
Geoff Lang4ddf5af2016-12-01 14:30:44 -050050template <typename HandleAllocatorType>
51void ResourceManagerBase<HandleAllocatorType>::addRef()
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000052{
53 mRefCount++;
54}
55
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056template <typename HandleAllocatorType>
Jamie Madill6c1f6712017-02-14 19:08:04 -050057void ResourceManagerBase<HandleAllocatorType>::release(const Context *context)
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000058{
59 if (--mRefCount == 0)
60 {
Jamie Madill6c1f6712017-02-14 19:08:04 -050061 reset(context);
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000062 delete this;
63 }
64}
65
Jamie Madill5f45e7c2017-02-10 15:23:28 -080066template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
67TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::~TypedResourceManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000068{
Jamie Madill6c1f6712017-02-14 19:08:04 -050069 ASSERT(mObjectMap.empty());
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000070}
71
Jamie Madill5f45e7c2017-02-10 15:23:28 -080072template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
Jamie Madill6c1f6712017-02-14 19:08:04 -050073void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::reset(const Context *context)
74{
75 while (!mObjectMap.empty())
76 {
77 deleteObject(context, mObjectMap.begin()->first);
78 }
79 mObjectMap.clear();
80}
81
82template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
83void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::deleteObject(
84 const Context *context,
85 GLuint handle)
Geoff Lang4ddf5af2016-12-01 14:30:44 -050086{
Jamie Madill5f45e7c2017-02-10 15:23:28 -080087 auto objectIter = mObjectMap.find(handle);
88 if (objectIter == mObjectMap.end())
89 {
90 return;
91 }
92
93 if (objectIter->second != nullptr)
94 {
Jamie Madill4928b7c2017-06-20 12:57:39 -040095 ImplT::DeleteObject(context, objectIter->second);
Jamie Madill5f45e7c2017-02-10 15:23:28 -080096 }
97
98 // Requires an explicit this-> because of C++ template rules.
99 this->mHandleAllocator.release(objectIter->first);
100 mObjectMap.erase(objectIter);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500101}
102
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800103template <typename ResourceType, typename HandleAllocatorType, typename ImplT>
104template <typename... ArgTypes>
105ResourceType *TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::allocateObject(
106 typename ResourceMap<ResourceType>::iterator &objectMapIter,
107 rx::GLImplFactory *factory,
108 GLuint handle,
109 ArgTypes... args)
110{
111 ResourceType *object = ImplT::AllocateNewObject(factory, handle, args...);
112
113 if (objectMapIter != mObjectMap.end())
114 {
115 objectMapIter->second = object;
116 }
117 else
118 {
119 this->mHandleAllocator.reserve(handle);
120 mObjectMap[handle] = object;
121 }
122
123 return object;
124}
125
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500126template class ResourceManagerBase<HandleAllocator>;
127template class ResourceManagerBase<HandleRangeAllocator>;
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800128template class TypedResourceManager<Buffer, HandleAllocator, BufferManager>;
129template Buffer *TypedResourceManager<Buffer, HandleAllocator, BufferManager>::allocateObject(
130 ResourceMap<Buffer>::iterator &,
131 rx::GLImplFactory *,
132 GLuint);
133template class TypedResourceManager<Texture, HandleAllocator, TextureManager>;
134template Texture *TypedResourceManager<Texture, HandleAllocator, TextureManager>::allocateObject(
135 ResourceMap<Texture>::iterator &,
136 rx::GLImplFactory *,
137 GLuint,
138 GLenum);
139template class TypedResourceManager<Renderbuffer, HandleAllocator, RenderbufferManager>;
140template Renderbuffer *
141TypedResourceManager<Renderbuffer, HandleAllocator, RenderbufferManager>::allocateObject(
142 ResourceMap<Renderbuffer>::iterator &,
143 rx::GLImplFactory *,
144 GLuint);
145template class TypedResourceManager<Sampler, HandleAllocator, SamplerManager>;
146template Sampler *TypedResourceManager<Sampler, HandleAllocator, SamplerManager>::allocateObject(
147 ResourceMap<Sampler>::iterator &,
148 rx::GLImplFactory *,
149 GLuint);
150template class TypedResourceManager<FenceSync, HandleAllocator, FenceSyncManager>;
151template class TypedResourceManager<Framebuffer, HandleAllocator, FramebufferManager>;
152template Framebuffer *
153TypedResourceManager<Framebuffer, HandleAllocator, FramebufferManager>::allocateObject(
154 ResourceMap<Framebuffer>::iterator &,
155 rx::GLImplFactory *,
156 GLuint,
157 const Caps &);
158
159// BufferManager Implementation.
160
161// static
162Buffer *BufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
163{
164 Buffer *buffer = new Buffer(factory, handle);
165 buffer->addRef();
166 return buffer;
167}
168
169// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400170void BufferManager::DeleteObject(const Context *context, Buffer *buffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800171{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400172 buffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800173}
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500174
175GLuint BufferManager::createBuffer()
176{
177 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
178}
179
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500180Buffer *BufferManager::getBuffer(GLuint handle) const
181{
182 return GetObject(mObjectMap, handle);
183}
184
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500185bool BufferManager::isBufferGenerated(GLuint buffer) const
186{
187 return buffer == 0 || mObjectMap.find(buffer) != mObjectMap.end();
188}
189
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800190// ShaderProgramManager Implementation.
191
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500192ShaderProgramManager::~ShaderProgramManager()
193{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500194 ASSERT(mPrograms.empty());
195 ASSERT(mShaders.empty());
196}
197
198void ShaderProgramManager::reset(const Context *context)
199{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500200 while (!mPrograms.empty())
201 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500202 deleteProgram(context, mPrograms.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500203 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500204 mPrograms.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500205 while (!mShaders.empty())
206 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500207 deleteShader(context, mShaders.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500208 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500209 mShaders.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500210}
211
212GLuint ShaderProgramManager::createShader(rx::GLImplFactory *factory,
213 const gl::Limitations &rendererLimitations,
214 GLenum type)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000215{
Martin Radev4c4c8e72016-08-04 12:25:34 +0300216 ASSERT(type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER || type == GL_COMPUTE_SHADER);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500217 GLuint handle = mHandleAllocator.allocate();
218 mShaders[handle] = new Shader(this, factory, rendererLimitations, type, handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000219 return handle;
220}
221
Jamie Madill6c1f6712017-02-14 19:08:04 -0500222void ShaderProgramManager::deleteShader(const Context *context, GLuint shader)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000223{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500224 deleteObject(context, &mShaders, shader);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000225}
226
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500227Shader *ShaderProgramManager::getShader(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000228{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500229 return GetObject(mShaders, handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000230}
231
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500232GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000233{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500234 GLuint handle = mHandleAllocator.allocate();
235 mPrograms[handle] = new Program(factory, this, handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000236 return handle;
237}
238
Jamie Madill6c1f6712017-02-14 19:08:04 -0500239void ShaderProgramManager::deleteProgram(const gl::Context *context, GLuint program)
Jamie Madilldc356042013-07-19 16:36:57 -0400240{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500241 deleteObject(context, &mPrograms, program);
Jamie Madilldc356042013-07-19 16:36:57 -0400242}
243
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500244Program *ShaderProgramManager::getProgram(GLuint handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400245{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500246 return GetObject(mPrograms, handle);
Jamie Madillcd055f82013-07-26 11:55:15 -0400247}
248
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500249template <typename ObjectType>
Jamie Madill6c1f6712017-02-14 19:08:04 -0500250void ShaderProgramManager::deleteObject(const Context *context,
251 ResourceMap<ObjectType> *objectMap,
252 GLuint id)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500253{
254 auto iter = objectMap->find(id);
255 if (iter == objectMap->end())
256 {
257 return;
258 }
259
260 auto object = iter->second;
261 if (object->getRefCount() == 0)
262 {
263 mHandleAllocator.release(id);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400264 object->onDestroy(context);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500265 objectMap->erase(iter);
266 }
267 else
268 {
269 object->flagForDeletion();
270 }
271}
272
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800273// TextureManager Implementation.
274
275// static
276Texture *TextureManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle, GLenum target)
277{
278 Texture *texture = new Texture(factory, handle, target);
279 texture->addRef();
280 return texture;
281}
282
283// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400284void TextureManager::DeleteObject(const Context *context, Texture *texture)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800285{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400286 texture->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800287}
288
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500289GLuint TextureManager::createTexture()
290{
291 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
292}
293
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500294Texture *TextureManager::getTexture(GLuint handle) const
295{
296 ASSERT(GetObject(mObjectMap, 0) == nullptr);
297 return GetObject(mObjectMap, handle);
298}
299
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500300bool TextureManager::isTextureGenerated(GLuint texture) const
301{
302 return texture == 0 || mObjectMap.find(texture) != mObjectMap.end();
303}
304
Geoff Lang9aded172017-04-05 11:07:56 -0400305void TextureManager::invalidateTextureComplenessCache()
306{
307 for (auto &texture : mObjectMap)
308 {
309 if (texture.second)
310 {
311 texture.second->invalidateCompletenessCache();
312 }
313 }
314}
315
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800316// RenderbufferManager Implementation.
317
318// static
319Renderbuffer *RenderbufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
320{
321 Renderbuffer *renderbuffer = new Renderbuffer(factory->createRenderbuffer(), handle);
322 renderbuffer->addRef();
323 return renderbuffer;
324}
325
326// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400327void RenderbufferManager::DeleteObject(const Context *context, Renderbuffer *renderbuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800328{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400329 renderbuffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800330}
331
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500332GLuint RenderbufferManager::createRenderbuffer()
333{
334 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
335}
336
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500337Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle)
338{
339 return GetObject(mObjectMap, handle);
340}
341
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500342bool RenderbufferManager::isRenderbufferGenerated(GLuint renderbuffer) const
343{
344 return renderbuffer == 0 || mObjectMap.find(renderbuffer) != mObjectMap.end();
345}
346
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800347// SamplerManager Implementation.
348
349// static
350Sampler *SamplerManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
351{
352 Sampler *sampler = new Sampler(factory, handle);
353 sampler->addRef();
354 return sampler;
355}
356
357// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400358void SamplerManager::DeleteObject(const Context *context, Sampler *sampler)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800359{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400360 sampler->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800361}
362
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500363GLuint SamplerManager::createSampler()
364{
365 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
366}
367
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500368Sampler *SamplerManager::getSampler(GLuint handle)
369{
370 return GetObject(mObjectMap, handle);
371}
372
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500373bool SamplerManager::isSampler(GLuint sampler)
374{
375 return mObjectMap.find(sampler) != mObjectMap.end();
376}
377
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800378// FenceSyncManager Implementation.
379
380// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400381void FenceSyncManager::DeleteObject(const Context *context, FenceSync *fenceSync)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500382{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400383 fenceSync->release(context);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500384}
385
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800386GLuint FenceSyncManager::createFenceSync(rx::GLImplFactory *factory)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500387{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800388 GLuint handle = mHandleAllocator.allocate();
389 FenceSync *fenceSync = new FenceSync(factory->createFenceSync(), handle);
390 fenceSync->addRef();
391 mObjectMap[handle] = fenceSync;
392 return handle;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500393}
394
395FenceSync *FenceSyncManager::getFenceSync(GLuint handle)
396{
397 return GetObject(mObjectMap, handle);
398}
399
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800400// PathManager Implementation.
401
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500402ErrorOrResult<GLuint> PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300403{
404 // Allocate client side handles.
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500405 const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300406 if (client == HandleRangeAllocator::kInvalidHandle)
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500407 return OutOfMemory() << "Failed to allocate path handle range.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300408
409 const auto &paths = factory->createPaths(range);
410 if (paths.empty())
411 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500412 mHandleAllocator.releaseRange(client, range);
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500413 return OutOfMemory() << "Failed to allocate path objects.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300414 }
415
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500416 auto hint = mPaths.begin();
Sami Väisänene45e53b2016-05-25 10:36:04 +0300417
418 for (GLsizei i = 0; i < range; ++i)
419 {
420 const auto impl = paths[static_cast<unsigned>(i)];
421 const auto id = client + i;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500422 hint = mPaths.insert(hint, std::make_pair(id, new Path(impl)));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300423 }
424 return client;
425}
426
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500427void PathManager::deletePaths(GLuint first, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300428{
429 for (GLsizei i = 0; i < range; ++i)
430 {
431 const auto id = first + i;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500432 const auto it = mPaths.find(id);
433 if (it == mPaths.end())
Sami Väisänene45e53b2016-05-25 10:36:04 +0300434 continue;
435 Path *p = it->second;
436 delete p;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500437 mPaths.erase(it);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300438 }
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500439 mHandleAllocator.releaseRange(first, static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300440}
441
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500442Path *PathManager::getPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000443{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500444 auto iter = mPaths.find(handle);
445 return iter != mPaths.end() ? iter->second : nullptr;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000446}
447
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500448bool PathManager::hasPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000449{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500450 return mHandleAllocator.isUsed(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000451}
452
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500453PathManager::~PathManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000454{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500455 ASSERT(mPaths.empty());
456}
457
458void PathManager::reset(const Context *context)
459{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500460 for (auto path : mPaths)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000461 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500462 SafeDelete(path.second);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000463 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500464 mPaths.clear();
Geoff Langf41a7152016-09-19 15:11:17 -0400465}
466
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800467// FramebufferManager Implementation.
468
469// static
470Framebuffer *FramebufferManager::AllocateNewObject(rx::GLImplFactory *factory,
471 GLuint handle,
472 const Caps &caps)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500473{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800474 return new Framebuffer(caps, factory, handle);
475}
476
477// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400478void FramebufferManager::DeleteObject(const Context *context, Framebuffer *framebuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800479{
480 // Default framebuffer are owned by their respective Surface
481 if (framebuffer->id() != 0)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500482 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400483 framebuffer->onDestroy(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800484 delete framebuffer;
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500485 }
486}
487
488GLuint FramebufferManager::createFramebuffer()
489{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800490 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500491}
492
493Framebuffer *FramebufferManager::getFramebuffer(GLuint handle) const
494{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800495 return GetObject(mObjectMap, handle);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500496}
497
498void FramebufferManager::setDefaultFramebuffer(Framebuffer *framebuffer)
499{
500 ASSERT(framebuffer == nullptr || framebuffer->id() == 0);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800501 mObjectMap[0] = framebuffer;
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500502}
503
504bool FramebufferManager::isFramebufferGenerated(GLuint framebuffer)
505{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800506 ASSERT(mObjectMap.find(0) != mObjectMap.end());
507 return mObjectMap.find(framebuffer) != mObjectMap.end();
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500508}
509
Geoff Lang9aded172017-04-05 11:07:56 -0400510void FramebufferManager::invalidateFramebufferComplenessCache()
511{
512 for (auto &framebuffer : mObjectMap)
513 {
514 if (framebuffer.second)
515 {
516 framebuffer.second->invalidateCompletenessCache();
517 }
518 }
519}
520
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500521} // namespace gl