daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1 | // |
Stuart Morgan | 9d73796 | 2019-08-14 12:25:12 -0700 | [diff] [blame] | 2 | // Copyright 2002 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 7 | // ResourceManager.cpp: Implements the the ResourceManager classes, which handle allocation and |
| 8 | // lifetime of GL objects. |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 9 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 10 | #include "libANGLE/ResourceManager.h" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 11 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 12 | #include "libANGLE/Buffer.h" |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 13 | #include "libANGLE/Context.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 14 | #include "libANGLE/Fence.h" |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 15 | #include "libANGLE/MemoryObject.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 16 | #include "libANGLE/Path.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 17 | #include "libANGLE/Program.h" |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 18 | #include "libANGLE/ProgramPipeline.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 19 | #include "libANGLE/Renderbuffer.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 20 | #include "libANGLE/Sampler.h" |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 21 | #include "libANGLE/Semaphore.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 22 | #include "libANGLE/Shader.h" |
| 23 | #include "libANGLE/Texture.h" |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 24 | #include "libANGLE/renderer/ContextImpl.h" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 25 | |
| 26 | namespace gl |
| 27 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 28 | |
| 29 | namespace |
| 30 | { |
| 31 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 32 | template <typename ResourceType, typename IDType> |
| 33 | IDType AllocateEmptyObject(HandleAllocator *handleAllocator, |
| 34 | ResourceMap<ResourceType, IDType> *objectMap) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 35 | { |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 36 | IDType handle = FromGL<IDType>(handleAllocator->allocate()); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 37 | objectMap->assign(handle, nullptr); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 38 | return handle; |
| 39 | } |
| 40 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 41 | } // anonymous namespace |
| 42 | |
| 43 | template <typename HandleAllocatorType> |
| 44 | ResourceManagerBase<HandleAllocatorType>::ResourceManagerBase() : mRefCount(1) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 45 | {} |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 46 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 47 | template <typename HandleAllocatorType> |
| 48 | void ResourceManagerBase<HandleAllocatorType>::addRef() |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 49 | { |
| 50 | mRefCount++; |
| 51 | } |
| 52 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 53 | template <typename HandleAllocatorType> |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 54 | void ResourceManagerBase<HandleAllocatorType>::release(const Context *context) |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 55 | { |
| 56 | if (--mRefCount == 0) |
| 57 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 58 | reset(context); |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 59 | delete this; |
| 60 | } |
| 61 | } |
| 62 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 63 | template <typename ResourceType, typename HandleAllocatorType, typename ImplT, typename IDType> |
| 64 | TypedResourceManager<ResourceType, HandleAllocatorType, ImplT, IDType>::~TypedResourceManager() |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 65 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 66 | ASSERT(mObjectMap.empty()); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 69 | template <typename ResourceType, typename HandleAllocatorType, typename ImplT, typename IDType> |
| 70 | void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT, IDType>::reset( |
| 71 | const Context *context) |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 72 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 73 | this->mHandleAllocator.reset(); |
| 74 | for (const auto &resource : mObjectMap) |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 75 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 76 | if (resource.second) |
| 77 | { |
| 78 | ImplT::DeleteObject(context, resource.second); |
| 79 | } |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 80 | } |
| 81 | mObjectMap.clear(); |
| 82 | } |
| 83 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 84 | template <typename ResourceType, typename HandleAllocatorType, typename ImplT, typename IDType> |
| 85 | void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT, IDType>::deleteObject( |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 86 | const Context *context, |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 87 | IDType handle) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 88 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 89 | ResourceType *resource = nullptr; |
| 90 | if (!mObjectMap.erase(handle, &resource)) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 91 | { |
| 92 | return; |
| 93 | } |
| 94 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 95 | // Requires an explicit this-> because of C++ template rules. |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 96 | this->mHandleAllocator.release(GetIDValue(handle)); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 97 | |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 98 | if (resource) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 99 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 100 | ImplT::DeleteObject(context, resource); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 101 | } |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 104 | template class ResourceManagerBase<HandleAllocator>; |
| 105 | template class ResourceManagerBase<HandleRangeAllocator>; |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 106 | template class TypedResourceManager<Buffer, HandleAllocator, BufferManager, BufferID>; |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 107 | template class TypedResourceManager<Texture, HandleAllocator, TextureManager, TextureID>; |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 108 | template class TypedResourceManager<Renderbuffer, |
| 109 | HandleAllocator, |
| 110 | RenderbufferManager, |
| 111 | RenderbufferID>; |
Jiacheng Lu | ee79e2f | 2019-08-20 11:28:36 -0600 | [diff] [blame] | 112 | template class TypedResourceManager<Sampler, HandleAllocator, SamplerManager, SamplerID>; |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 113 | template class TypedResourceManager<Sync, HandleAllocator, SyncManager, GLuint>; |
| 114 | template class TypedResourceManager<Framebuffer, HandleAllocator, FramebufferManager, GLuint>; |
| 115 | template class TypedResourceManager<ProgramPipeline, |
| 116 | HandleAllocator, |
| 117 | ProgramPipelineManager, |
Jiacheng Lu | 378c188 | 2019-08-22 16:55:39 -0600 | [diff] [blame] | 118 | ProgramPipelineID>; |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 119 | |
| 120 | // BufferManager Implementation. |
| 121 | |
| 122 | // static |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 123 | Buffer *BufferManager::AllocateNewObject(rx::GLImplFactory *factory, BufferID handle) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 124 | { |
| 125 | Buffer *buffer = new Buffer(factory, handle); |
| 126 | buffer->addRef(); |
| 127 | return buffer; |
| 128 | } |
| 129 | |
| 130 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 131 | void BufferManager::DeleteObject(const Context *context, Buffer *buffer) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 132 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 133 | buffer->release(context); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 134 | } |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 135 | |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 136 | BufferID BufferManager::createBuffer() |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 137 | { |
| 138 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 139 | } |
| 140 | |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 141 | Buffer *BufferManager::getBuffer(BufferID handle) const |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 142 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 143 | return mObjectMap.query(handle); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 144 | } |
| 145 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 146 | // ShaderProgramManager Implementation. |
| 147 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 148 | ShaderProgramManager::ShaderProgramManager() {} |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 149 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 150 | ShaderProgramManager::~ShaderProgramManager() |
| 151 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 152 | ASSERT(mPrograms.empty()); |
| 153 | ASSERT(mShaders.empty()); |
| 154 | } |
| 155 | |
| 156 | void ShaderProgramManager::reset(const Context *context) |
| 157 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 158 | while (!mPrograms.empty()) |
| 159 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 160 | deleteProgram(context, {mPrograms.begin()->first}); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 161 | } |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 162 | mPrograms.clear(); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 163 | while (!mShaders.empty()) |
| 164 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 165 | deleteShader(context, {mShaders.begin()->first}); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 166 | } |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 167 | mShaders.clear(); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 168 | } |
| 169 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 170 | ShaderProgramID ShaderProgramManager::createShader(rx::GLImplFactory *factory, |
| 171 | const gl::Limitations &rendererLimitations, |
| 172 | ShaderType type) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 173 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 174 | ASSERT(type != ShaderType::InvalidEnum); |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 175 | ShaderProgramID handle = ShaderProgramID{mHandleAllocator.allocate()}; |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 176 | mShaders.assign(handle, new Shader(this, factory, rendererLimitations, type, handle)); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 177 | return handle; |
| 178 | } |
| 179 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 180 | void ShaderProgramManager::deleteShader(const Context *context, ShaderProgramID shader) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 181 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 182 | deleteObject(context, &mShaders, shader); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 185 | Shader *ShaderProgramManager::getShader(ShaderProgramID handle) const |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 186 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 187 | return mShaders.query(handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 190 | ShaderProgramID ShaderProgramManager::createProgram(rx::GLImplFactory *factory) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 191 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 192 | ShaderProgramID handle = ShaderProgramID{mHandleAllocator.allocate()}; |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 193 | mPrograms.assign(handle, new Program(factory, this, handle)); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 194 | return handle; |
| 195 | } |
| 196 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 197 | void ShaderProgramManager::deleteProgram(const gl::Context *context, ShaderProgramID program) |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 198 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 199 | deleteObject(context, &mPrograms, program); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 202 | template <typename ObjectType, typename IDType> |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 203 | void ShaderProgramManager::deleteObject(const Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 204 | ResourceMap<ObjectType, IDType> *objectMap, |
| 205 | IDType id) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 206 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 207 | ObjectType *object = objectMap->query(id); |
| 208 | if (!object) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 209 | { |
| 210 | return; |
| 211 | } |
| 212 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 213 | if (object->getRefCount() == 0) |
| 214 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame^] | 215 | mHandleAllocator.release(id.value); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 216 | object->onDestroy(context); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 217 | objectMap->erase(id, &object); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 218 | } |
| 219 | else |
| 220 | { |
| 221 | object->flagForDeletion(); |
| 222 | } |
| 223 | } |
| 224 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 225 | // TextureManager Implementation. |
| 226 | |
| 227 | // static |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 228 | Texture *TextureManager::AllocateNewObject(rx::GLImplFactory *factory, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 229 | TextureID handle, |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 230 | TextureType type) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 231 | { |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 232 | Texture *texture = new Texture(factory, handle, type); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 233 | texture->addRef(); |
| 234 | return texture; |
| 235 | } |
| 236 | |
| 237 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 238 | void TextureManager::DeleteObject(const Context *context, Texture *texture) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 239 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 240 | texture->release(context); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 243 | TextureID TextureManager::createTexture() |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 244 | { |
| 245 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 246 | } |
| 247 | |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 248 | void TextureManager::signalAllTexturesDirty() const |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 249 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 250 | for (const auto &texture : mObjectMap) |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 251 | { |
| 252 | if (texture.second) |
| 253 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 254 | // We don't know if the Texture needs init, but that's ok, since it will only force |
| 255 | // a re-check, and will not initialize the pixels if it's not needed. |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 256 | texture.second->signalDirtyStorage(InitState::MayNeedInit); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
Jamie Madill | fc3463d | 2018-01-03 13:46:21 -0500 | [diff] [blame] | 261 | void TextureManager::enableHandleAllocatorLogging() |
| 262 | { |
| 263 | mHandleAllocator.enableLogging(true); |
| 264 | } |
| 265 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 266 | // RenderbufferManager Implementation. |
| 267 | |
| 268 | // static |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 269 | Renderbuffer *RenderbufferManager::AllocateNewObject(rx::GLImplFactory *factory, |
| 270 | RenderbufferID handle) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 271 | { |
Jamie Madill | e703c60 | 2018-02-20 10:21:48 -0500 | [diff] [blame] | 272 | Renderbuffer *renderbuffer = new Renderbuffer(factory, handle); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 273 | renderbuffer->addRef(); |
| 274 | return renderbuffer; |
| 275 | } |
| 276 | |
| 277 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 278 | void RenderbufferManager::DeleteObject(const Context *context, Renderbuffer *renderbuffer) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 279 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 280 | renderbuffer->release(context); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 283 | RenderbufferID RenderbufferManager::createRenderbuffer() |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 284 | { |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 285 | return {AllocateEmptyObject(&mHandleAllocator, &mObjectMap)}; |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 286 | } |
| 287 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 288 | Renderbuffer *RenderbufferManager::getRenderbuffer(RenderbufferID handle) const |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 289 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 290 | return mObjectMap.query(handle); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 291 | } |
| 292 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 293 | // SamplerManager Implementation. |
| 294 | |
| 295 | // static |
Jiacheng Lu | ee79e2f | 2019-08-20 11:28:36 -0600 | [diff] [blame] | 296 | Sampler *SamplerManager::AllocateNewObject(rx::GLImplFactory *factory, SamplerID handle) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 297 | { |
| 298 | Sampler *sampler = new Sampler(factory, handle); |
| 299 | sampler->addRef(); |
| 300 | return sampler; |
| 301 | } |
| 302 | |
| 303 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 304 | void SamplerManager::DeleteObject(const Context *context, Sampler *sampler) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 305 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 306 | sampler->release(context); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Jiacheng Lu | ee79e2f | 2019-08-20 11:28:36 -0600 | [diff] [blame] | 309 | SamplerID SamplerManager::createSampler() |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 310 | { |
| 311 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 312 | } |
| 313 | |
Jiacheng Lu | ee79e2f | 2019-08-20 11:28:36 -0600 | [diff] [blame] | 314 | Sampler *SamplerManager::getSampler(SamplerID handle) const |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 315 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 316 | return mObjectMap.query(handle); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 317 | } |
| 318 | |
Jiacheng Lu | ee79e2f | 2019-08-20 11:28:36 -0600 | [diff] [blame] | 319 | bool SamplerManager::isSampler(SamplerID sampler) const |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 320 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 321 | return mObjectMap.contains(sampler); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 322 | } |
| 323 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 324 | // SyncManager Implementation. |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 325 | |
| 326 | // static |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 327 | void SyncManager::DeleteObject(const Context *context, Sync *sync) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 328 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 329 | sync->release(context); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 330 | } |
| 331 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 332 | GLuint SyncManager::createSync(rx::GLImplFactory *factory) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 333 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 334 | GLuint handle = mHandleAllocator.allocate(); |
| 335 | Sync *sync = new Sync(factory->createSync(), handle); |
| 336 | sync->addRef(); |
| 337 | mObjectMap.assign(handle, sync); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 338 | return handle; |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 339 | } |
| 340 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 341 | Sync *SyncManager::getSync(GLuint handle) const |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 342 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 343 | return mObjectMap.query(handle); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 344 | } |
| 345 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 346 | // PathManager Implementation. |
| 347 | |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 348 | PathManager::PathManager() = default; |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 349 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 350 | angle::Result PathManager::createPaths(Context *context, GLsizei range, PathID *createdOut) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 351 | { |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 352 | *createdOut = {0}; |
Jamie Madill | 1395134 | 2018-09-30 15:24:28 -0400 | [diff] [blame] | 353 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 354 | // Allocate client side handles. |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 355 | const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range)); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 356 | if (client == HandleRangeAllocator::kInvalidHandle) |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 357 | { |
| 358 | context->handleError(GL_OUT_OF_MEMORY, "Failed to allocate path handle range.", __FILE__, |
| 359 | ANGLE_FUNCTION, __LINE__); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 360 | return angle::Result::Stop; |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 361 | } |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 362 | |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 363 | const auto &paths = context->getImplementation()->createPaths(range); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 364 | if (paths.empty()) |
| 365 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 366 | mHandleAllocator.releaseRange(client, range); |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 367 | context->handleError(GL_OUT_OF_MEMORY, "Failed to allocate path objects.", __FILE__, |
| 368 | ANGLE_FUNCTION, __LINE__); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 369 | return angle::Result::Stop; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 370 | } |
| 371 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 372 | for (GLsizei i = 0; i < range; ++i) |
| 373 | { |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 374 | rx::PathImpl *impl = paths[static_cast<unsigned>(i)]; |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 375 | PathID id = PathID{client + i}; |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 376 | mPaths.assign(id, new Path(impl)); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 377 | } |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 378 | *createdOut = PathID{client}; |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 379 | return angle::Result::Continue; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 380 | } |
| 381 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 382 | void PathManager::deletePaths(PathID first, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 383 | { |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 384 | GLuint firstHandle = first.value; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 385 | for (GLsizei i = 0; i < range; ++i) |
| 386 | { |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 387 | GLuint id = firstHandle + i; |
| 388 | Path *p = nullptr; |
| 389 | if (!mPaths.erase({id}, &p)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 390 | continue; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 391 | delete p; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 392 | } |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 393 | mHandleAllocator.releaseRange(firstHandle, static_cast<GLuint>(range)); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 394 | } |
| 395 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 396 | Path *PathManager::getPath(PathID handle) const |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 397 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 398 | return mPaths.query(handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 401 | bool PathManager::hasPath(PathID handle) const |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 402 | { |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 403 | return mHandleAllocator.isUsed(GetIDValue(handle)); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 406 | PathManager::~PathManager() |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 407 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 408 | ASSERT(mPaths.empty()); |
| 409 | } |
| 410 | |
| 411 | void PathManager::reset(const Context *context) |
| 412 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 413 | for (auto path : mPaths) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 414 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 415 | SafeDelete(path.second); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 416 | } |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 417 | mPaths.clear(); |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 418 | } |
| 419 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 420 | // FramebufferManager Implementation. |
| 421 | |
| 422 | // static |
| 423 | Framebuffer *FramebufferManager::AllocateNewObject(rx::GLImplFactory *factory, |
| 424 | GLuint handle, |
| 425 | const Caps &caps) |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 426 | { |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 427 | return new Framebuffer(caps, factory, handle); |
| 428 | } |
| 429 | |
| 430 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 431 | void FramebufferManager::DeleteObject(const Context *context, Framebuffer *framebuffer) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 432 | { |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 433 | framebuffer->onDestroy(context); |
| 434 | delete framebuffer; |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | GLuint FramebufferManager::createFramebuffer() |
| 438 | { |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 439 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | Framebuffer *FramebufferManager::getFramebuffer(GLuint handle) const |
| 443 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 444 | return mObjectMap.query(handle); |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | void FramebufferManager::setDefaultFramebuffer(Framebuffer *framebuffer) |
| 448 | { |
| 449 | ASSERT(framebuffer == nullptr || framebuffer->id() == 0); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 450 | mObjectMap.assign(0, framebuffer); |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 451 | } |
| 452 | |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 453 | void FramebufferManager::invalidateFramebufferComplenessCache() const |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 454 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 455 | for (const auto &framebuffer : mObjectMap) |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 456 | { |
| 457 | if (framebuffer.second) |
| 458 | { |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 459 | framebuffer.second->invalidateCompletenessCache(); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 464 | // ProgramPipelineManager Implementation. |
| 465 | |
| 466 | // static |
| 467 | ProgramPipeline *ProgramPipelineManager::AllocateNewObject(rx::GLImplFactory *factory, |
Jiacheng Lu | 378c188 | 2019-08-22 16:55:39 -0600 | [diff] [blame] | 468 | ProgramPipelineID handle) |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 469 | { |
| 470 | ProgramPipeline *pipeline = new ProgramPipeline(factory, handle); |
| 471 | pipeline->addRef(); |
| 472 | return pipeline; |
| 473 | } |
| 474 | |
| 475 | // static |
| 476 | void ProgramPipelineManager::DeleteObject(const Context *context, ProgramPipeline *pipeline) |
| 477 | { |
| 478 | pipeline->release(context); |
| 479 | } |
| 480 | |
Jiacheng Lu | 378c188 | 2019-08-22 16:55:39 -0600 | [diff] [blame] | 481 | ProgramPipelineID ProgramPipelineManager::createProgramPipeline() |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 482 | { |
| 483 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 484 | } |
| 485 | |
Jiacheng Lu | 378c188 | 2019-08-22 16:55:39 -0600 | [diff] [blame] | 486 | ProgramPipeline *ProgramPipelineManager::getProgramPipeline(ProgramPipelineID handle) const |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 487 | { |
| 488 | return mObjectMap.query(handle); |
| 489 | } |
| 490 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 491 | // MemoryObjectManager Implementation. |
| 492 | |
| 493 | MemoryObjectManager::MemoryObjectManager() {} |
| 494 | |
| 495 | MemoryObjectManager::~MemoryObjectManager() |
| 496 | { |
| 497 | ASSERT(mMemoryObjects.empty()); |
| 498 | } |
| 499 | |
| 500 | void MemoryObjectManager::reset(const Context *context) |
| 501 | { |
| 502 | while (!mMemoryObjects.empty()) |
| 503 | { |
| 504 | deleteMemoryObject(context, mMemoryObjects.begin()->first); |
| 505 | } |
| 506 | mMemoryObjects.clear(); |
| 507 | } |
| 508 | |
| 509 | GLuint MemoryObjectManager::createMemoryObject(rx::GLImplFactory *factory) |
| 510 | { |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 511 | GLuint handle = mHandleAllocator.allocate(); |
Michael Spang | a0b00e9 | 2019-04-09 18:45:22 -0400 | [diff] [blame] | 512 | MemoryObject *memoryObject = new MemoryObject(factory, handle); |
| 513 | memoryObject->addRef(); |
| 514 | mMemoryObjects.assign(handle, memoryObject); |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 515 | return handle; |
| 516 | } |
| 517 | |
| 518 | void MemoryObjectManager::deleteMemoryObject(const Context *context, GLuint handle) |
| 519 | { |
| 520 | MemoryObject *memoryObject = nullptr; |
| 521 | if (!mMemoryObjects.erase(handle, &memoryObject)) |
| 522 | { |
| 523 | return; |
| 524 | } |
| 525 | |
| 526 | // Requires an explicit this-> because of C++ template rules. |
| 527 | this->mHandleAllocator.release(handle); |
| 528 | |
| 529 | if (memoryObject) |
| 530 | { |
| 531 | memoryObject->release(context); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | MemoryObject *MemoryObjectManager::getMemoryObject(GLuint handle) const |
| 536 | { |
| 537 | return mMemoryObjects.query(handle); |
| 538 | } |
| 539 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 540 | // SemaphoreManager Implementation. |
| 541 | |
| 542 | SemaphoreManager::SemaphoreManager() {} |
| 543 | |
| 544 | SemaphoreManager::~SemaphoreManager() |
| 545 | { |
| 546 | ASSERT(mSemaphores.empty()); |
| 547 | } |
| 548 | |
| 549 | void SemaphoreManager::reset(const Context *context) |
| 550 | { |
| 551 | while (!mSemaphores.empty()) |
| 552 | { |
| 553 | deleteSemaphore(context, mSemaphores.begin()->first); |
| 554 | } |
| 555 | mSemaphores.clear(); |
| 556 | } |
| 557 | |
| 558 | GLuint SemaphoreManager::createSemaphore(rx::GLImplFactory *factory) |
| 559 | { |
| 560 | GLuint handle = mHandleAllocator.allocate(); |
| 561 | Semaphore *semaphore = new Semaphore(factory, handle); |
| 562 | semaphore->addRef(); |
| 563 | mSemaphores.assign(handle, semaphore); |
| 564 | return handle; |
| 565 | } |
| 566 | |
| 567 | void SemaphoreManager::deleteSemaphore(const Context *context, GLuint handle) |
| 568 | { |
| 569 | Semaphore *semaphore = nullptr; |
| 570 | if (!mSemaphores.erase(handle, &semaphore)) |
| 571 | { |
| 572 | return; |
| 573 | } |
| 574 | |
| 575 | // Requires an explicit this-> because of C++ template rules. |
| 576 | this->mHandleAllocator.release(handle); |
| 577 | |
| 578 | if (semaphore) |
| 579 | { |
| 580 | semaphore->release(context); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | Semaphore *SemaphoreManager::getSemaphore(GLuint handle) const |
| 585 | { |
| 586 | return mSemaphores.query(handle); |
| 587 | } |
| 588 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 589 | } // namespace gl |