Added memory pool logging
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-texture-set.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 // CLASS HEADER
18 #include "scene-graph-texture-set.h"
19
20 // INTERNAL HEADERS
21 #include <dali/internal/common/internal-constants.h>
22 #include <dali/internal/common/memory-pool-object-allocator.h>
23 #include <dali/internal/render/renderers/render-texture.h>
24 #include <dali/internal/update/rendering/scene-graph-renderer.h>
25
26 namespace //Unnamed namespace
27 {
28 //Memory pool used to allocate new texture sets. Memory used by this pool will be released when shutting down DALi
29 Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet> gTextureSetMemoryPool;
30 } // namespace
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace SceneGraph
37 {
38 TextureSet* TextureSet::New()
39 {
40   return new(gTextureSetMemoryPool.AllocateRawThreadSafe()) TextureSet();
41 }
42
43 TextureSet::TextureSet()
44 : mSamplers(),
45   mHasAlpha(false)
46 {
47 }
48
49 TextureSet::~TextureSet()
50 {
51 }
52
53 void TextureSet::operator delete(void* ptr)
54 {
55   gTextureSetMemoryPool.FreeThreadSafe(static_cast<TextureSet*>(ptr));
56 }
57
58 void TextureSet::SetSampler(uint32_t index, Render::Sampler* sampler)
59 {
60   const uint32_t samplerCount = static_cast<uint32_t>(mSamplers.Size());
61   if(samplerCount < index + 1)
62   {
63     mSamplers.Resize(index + 1);
64     for(uint32_t i(samplerCount); i <= index; ++i)
65     {
66       mSamplers[i] = nullptr;
67     }
68   }
69
70   mSamplers[index] = sampler;
71
72   if(index < static_cast<uint32_t>(mTextures.Size()))
73   {
74     mTextures[index]->SetUpdated(true);
75   }
76 }
77
78 void TextureSet::SetTexture(uint32_t index, Render::Texture* texture)
79 {
80   const uint32_t textureCount = static_cast<uint32_t>(mTextures.Size());
81   if(textureCount < index + 1)
82   {
83     mTextures.Resize(index + 1);
84
85     bool samplerExist = true;
86     if(mSamplers.Size() < index + 1)
87     {
88       mSamplers.Resize(index + 1);
89       samplerExist = false;
90     }
91
92     for(uint32_t i(textureCount); i <= index; ++i)
93     {
94       mTextures[i] = nullptr;
95
96       if(!samplerExist)
97       {
98         mSamplers[i] = nullptr;
99       }
100     }
101   }
102
103   mTextures[index] = texture;
104   if(texture)
105   {
106     mHasAlpha |= texture->HasAlphaChannel();
107     texture->SetUpdated(true);
108   }
109 }
110
111 bool TextureSet::HasAlpha() const
112 {
113   return mHasAlpha;
114 }
115
116 uint32_t TextureSet::GetMemoryPoolCapacity()
117 {
118   return gTextureSetMemoryPool.GetCapacity();
119 }
120
121 } // namespace SceneGraph
122
123 } // namespace Internal
124
125 } // namespace Dali