blob: 5eeaf2ebb1fa74a6273169e642c9ab5a074ef840 [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
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800185// ShaderProgramManager Implementation.
186
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500187ShaderProgramManager::~ShaderProgramManager()
188{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500189 ASSERT(mPrograms.empty());
190 ASSERT(mShaders.empty());
191}
192
193void ShaderProgramManager::reset(const Context *context)
194{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500195 while (!mPrograms.empty())
196 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500197 deleteProgram(context, mPrograms.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500198 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500199 mPrograms.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500200 while (!mShaders.empty())
201 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500202 deleteShader(context, mShaders.begin()->first);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500203 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500204 mShaders.clear();
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500205}
206
207GLuint ShaderProgramManager::createShader(rx::GLImplFactory *factory,
208 const gl::Limitations &rendererLimitations,
209 GLenum type)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000210{
Martin Radev4c4c8e72016-08-04 12:25:34 +0300211 ASSERT(type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER || type == GL_COMPUTE_SHADER);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500212 GLuint handle = mHandleAllocator.allocate();
213 mShaders[handle] = new Shader(this, factory, rendererLimitations, type, handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000214 return handle;
215}
216
Jamie Madill6c1f6712017-02-14 19:08:04 -0500217void ShaderProgramManager::deleteShader(const Context *context, GLuint shader)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000218{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500219 deleteObject(context, &mShaders, shader);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000220}
221
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500222Shader *ShaderProgramManager::getShader(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000223{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500224 return GetObject(mShaders, handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000225}
226
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500227GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000228{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500229 GLuint handle = mHandleAllocator.allocate();
230 mPrograms[handle] = new Program(factory, this, handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000231 return handle;
232}
233
Jamie Madill6c1f6712017-02-14 19:08:04 -0500234void ShaderProgramManager::deleteProgram(const gl::Context *context, GLuint program)
Jamie Madilldc356042013-07-19 16:36:57 -0400235{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500236 deleteObject(context, &mPrograms, program);
Jamie Madilldc356042013-07-19 16:36:57 -0400237}
238
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500239Program *ShaderProgramManager::getProgram(GLuint handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400240{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500241 return GetObject(mPrograms, handle);
Jamie Madillcd055f82013-07-26 11:55:15 -0400242}
243
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500244template <typename ObjectType>
Jamie Madill6c1f6712017-02-14 19:08:04 -0500245void ShaderProgramManager::deleteObject(const Context *context,
246 ResourceMap<ObjectType> *objectMap,
247 GLuint id)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500248{
249 auto iter = objectMap->find(id);
250 if (iter == objectMap->end())
251 {
252 return;
253 }
254
255 auto object = iter->second;
256 if (object->getRefCount() == 0)
257 {
258 mHandleAllocator.release(id);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400259 object->onDestroy(context);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500260 objectMap->erase(iter);
261 }
262 else
263 {
264 object->flagForDeletion();
265 }
266}
267
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800268// TextureManager Implementation.
269
270// static
271Texture *TextureManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle, GLenum target)
272{
273 Texture *texture = new Texture(factory, handle, target);
274 texture->addRef();
275 return texture;
276}
277
278// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400279void TextureManager::DeleteObject(const Context *context, Texture *texture)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800280{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400281 texture->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800282}
283
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500284GLuint TextureManager::createTexture()
285{
286 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
287}
288
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500289Texture *TextureManager::getTexture(GLuint handle) const
290{
291 ASSERT(GetObject(mObjectMap, 0) == nullptr);
292 return GetObject(mObjectMap, handle);
293}
294
Geoff Lang9aded172017-04-05 11:07:56 -0400295void TextureManager::invalidateTextureComplenessCache()
296{
297 for (auto &texture : mObjectMap)
298 {
299 if (texture.second)
300 {
301 texture.second->invalidateCompletenessCache();
302 }
303 }
304}
305
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800306// RenderbufferManager Implementation.
307
308// static
309Renderbuffer *RenderbufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
310{
311 Renderbuffer *renderbuffer = new Renderbuffer(factory->createRenderbuffer(), handle);
312 renderbuffer->addRef();
313 return renderbuffer;
314}
315
316// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400317void RenderbufferManager::DeleteObject(const Context *context, Renderbuffer *renderbuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800318{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400319 renderbuffer->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800320}
321
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500322GLuint RenderbufferManager::createRenderbuffer()
323{
324 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
325}
326
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500327Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle)
328{
329 return GetObject(mObjectMap, handle);
330}
331
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800332// SamplerManager Implementation.
333
334// static
335Sampler *SamplerManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle)
336{
337 Sampler *sampler = new Sampler(factory, handle);
338 sampler->addRef();
339 return sampler;
340}
341
342// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400343void SamplerManager::DeleteObject(const Context *context, Sampler *sampler)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800344{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400345 sampler->release(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800346}
347
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500348GLuint SamplerManager::createSampler()
349{
350 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
351}
352
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500353Sampler *SamplerManager::getSampler(GLuint handle)
354{
355 return GetObject(mObjectMap, handle);
356}
357
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500358bool SamplerManager::isSampler(GLuint sampler)
359{
360 return mObjectMap.find(sampler) != mObjectMap.end();
361}
362
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800363// FenceSyncManager Implementation.
364
365// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400366void FenceSyncManager::DeleteObject(const Context *context, FenceSync *fenceSync)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500367{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400368 fenceSync->release(context);
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500369}
370
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800371GLuint FenceSyncManager::createFenceSync(rx::GLImplFactory *factory)
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500372{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800373 GLuint handle = mHandleAllocator.allocate();
374 FenceSync *fenceSync = new FenceSync(factory->createFenceSync(), handle);
375 fenceSync->addRef();
376 mObjectMap[handle] = fenceSync;
377 return handle;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500378}
379
380FenceSync *FenceSyncManager::getFenceSync(GLuint handle)
381{
382 return GetObject(mObjectMap, handle);
383}
384
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800385// PathManager Implementation.
386
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500387ErrorOrResult<GLuint> PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300388{
389 // Allocate client side handles.
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500390 const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300391 if (client == HandleRangeAllocator::kInvalidHandle)
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500392 return OutOfMemory() << "Failed to allocate path handle range.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300393
394 const auto &paths = factory->createPaths(range);
395 if (paths.empty())
396 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500397 mHandleAllocator.releaseRange(client, range);
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500398 return OutOfMemory() << "Failed to allocate path objects.";
Sami Väisänene45e53b2016-05-25 10:36:04 +0300399 }
400
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500401 auto hint = mPaths.begin();
Sami Väisänene45e53b2016-05-25 10:36:04 +0300402
403 for (GLsizei i = 0; i < range; ++i)
404 {
405 const auto impl = paths[static_cast<unsigned>(i)];
406 const auto id = client + i;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500407 hint = mPaths.insert(hint, std::make_pair(id, new Path(impl)));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300408 }
409 return client;
410}
411
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500412void PathManager::deletePaths(GLuint first, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300413{
414 for (GLsizei i = 0; i < range; ++i)
415 {
416 const auto id = first + i;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500417 const auto it = mPaths.find(id);
418 if (it == mPaths.end())
Sami Väisänene45e53b2016-05-25 10:36:04 +0300419 continue;
420 Path *p = it->second;
421 delete p;
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500422 mPaths.erase(it);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300423 }
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500424 mHandleAllocator.releaseRange(first, static_cast<GLuint>(range));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300425}
426
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500427Path *PathManager::getPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000428{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500429 auto iter = mPaths.find(handle);
430 return iter != mPaths.end() ? iter->second : nullptr;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000431}
432
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500433bool PathManager::hasPath(GLuint handle) const
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000434{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500435 return mHandleAllocator.isUsed(handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000436}
437
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500438PathManager::~PathManager()
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000439{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500440 ASSERT(mPaths.empty());
441}
442
443void PathManager::reset(const Context *context)
444{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500445 for (auto path : mPaths)
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000446 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500447 SafeDelete(path.second);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000448 }
Jamie Madill6c1f6712017-02-14 19:08:04 -0500449 mPaths.clear();
Geoff Langf41a7152016-09-19 15:11:17 -0400450}
451
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800452// FramebufferManager Implementation.
453
454// static
455Framebuffer *FramebufferManager::AllocateNewObject(rx::GLImplFactory *factory,
456 GLuint handle,
457 const Caps &caps)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500458{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800459 return new Framebuffer(caps, factory, handle);
460}
461
462// static
Jamie Madill4928b7c2017-06-20 12:57:39 -0400463void FramebufferManager::DeleteObject(const Context *context, Framebuffer *framebuffer)
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800464{
465 // Default framebuffer are owned by their respective Surface
466 if (framebuffer->id() != 0)
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500467 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400468 framebuffer->onDestroy(context);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800469 delete framebuffer;
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500470 }
471}
472
473GLuint FramebufferManager::createFramebuffer()
474{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800475 return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500476}
477
478Framebuffer *FramebufferManager::getFramebuffer(GLuint handle) const
479{
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800480 return GetObject(mObjectMap, handle);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500481}
482
483void FramebufferManager::setDefaultFramebuffer(Framebuffer *framebuffer)
484{
485 ASSERT(framebuffer == nullptr || framebuffer->id() == 0);
Jamie Madill5f45e7c2017-02-10 15:23:28 -0800486 mObjectMap[0] = framebuffer;
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500487}
488
Geoff Lang9aded172017-04-05 11:07:56 -0400489void FramebufferManager::invalidateFramebufferComplenessCache()
490{
491 for (auto &framebuffer : mObjectMap)
492 {
493 if (framebuffer.second)
494 {
495 framebuffer.second->invalidateCompletenessCache();
496 }
497 }
498}
499
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500500} // namespace gl