2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "scene-graph-texture-set.h"
21 #include <dali/internal/common/internal-constants.h>
22 #include <dali/internal/common/memory-pool-object-allocator.h>
23 #include <dali/internal/render/common/render-manager.h>
24 #include <dali/internal/render/renderers/render-texture.h>
25 #include <dali/internal/update/controllers/render-message-dispatcher.h>
26 #include <dali/internal/update/rendering/scene-graph-renderer.h>
28 namespace //Unnamed namespace
30 //Memory pool used to allocate new texture sets. Memory used by this pool will be released when shutting down DALi
31 Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet>& GetTextureSetMemoryPool()
33 static Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet> gTextureSetMemoryPool;
34 return gTextureSetMemoryPool;
44 TextureSet* TextureSet::New()
46 return new(GetTextureSetMemoryPool().AllocateRawThreadSafe()) TextureSet();
49 TextureSet::TextureSet()
55 TextureSet::~TextureSet()
59 void TextureSet::operator delete(void* ptr)
61 GetTextureSetMemoryPool().FreeThreadSafe(static_cast<TextureSet*>(ptr));
64 void TextureSet::SetSampler(uint32_t index, Render::Sampler* sampler)
66 const uint32_t samplerCount = static_cast<uint32_t>(mSamplers.Size());
67 if(samplerCount < index + 1)
69 mSamplers.Resize(index + 1);
70 for(uint32_t i(samplerCount); i <= index; ++i)
72 mSamplers[i] = nullptr;
76 mSamplers[index] = sampler;
78 if(index < static_cast<uint32_t>(mTextures.Size()))
80 // Send a message to the RenderManagerReserveMessageSlot
81 using DerivedType = MessageValue1<RenderManager, Render::TextureKey>;
83 // Reserve some memory inside the render queue
84 uint32_t* slot = mRenderMessageDispatcher->ReserveMessageSlot(sizeof(DerivedType));
86 // Construct message in the render queue memory; note that delete should not be called on the return value
87 new(slot) DerivedType(&mRenderMessageDispatcher->GetRenderManager(), &RenderManager::SetTextureUpdated, mTextures[index]);
91 void TextureSet::SetTexture(uint32_t index, const Render::TextureKey& texture)
93 const uint32_t textureCount = static_cast<uint32_t>(mTextures.Size());
94 if(textureCount < index + 1)
96 mTextures.Resize(index + 1);
98 bool samplerExist = true;
99 if(mSamplers.Size() < index + 1)
101 mSamplers.Resize(index + 1);
102 samplerExist = false;
105 for(uint32_t i(textureCount); i <= index; ++i)
107 mTextures[i] = Render::TextureKey{};
111 mSamplers[i] = nullptr;
116 mTextures[index] = texture;
119 mHasAlpha |= texture->HasAlphaChannel();
121 // Send a message to the RenderManagerReserveMessageSlot
122 using DerivedType = MessageValue1<RenderManager, Render::TextureKey>;
124 // Reserve some memory inside the render queue
125 uint32_t* slot = mRenderMessageDispatcher->ReserveMessageSlot(sizeof(DerivedType));
127 // Construct message in the render queue memory; note that delete should not be called on the return value
128 new(slot) DerivedType(&mRenderMessageDispatcher->GetRenderManager(), &RenderManager::SetTextureUpdated, texture);
132 bool TextureSet::HasAlpha() const
137 void TextureSet::SetRenderMessageDispatcher(RenderMessageDispatcher* renderMessageDispatcher)
139 mRenderMessageDispatcher = renderMessageDispatcher;
142 uint32_t TextureSet::GetMemoryPoolCapacity()
144 return GetTextureSetMemoryPool().GetCapacity();
147 } // namespace SceneGraph
149 } // namespace Internal