[Tizen] Support MultiSampling FrameBuffer
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / gl-extensions-support.h
1 #ifndef DALI_INTERNAL_GL_EXTENSION_SUPPORT_H
2 #define DALI_INTERNAL_GL_EXTENSION_SUPPORT_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <cstdint>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Adaptor
30 {
31 /**
32  * Common extensions support checker type.
33  */
34 using ExtensionCheckerType = uint32_t;
35
36 struct ExtensionSupportedCache
37 {
38   bool isSupported{false};
39   bool cached{false};
40 };
41
42 struct ExtensionSupportedCacheListInterface
43 {
44   ExtensionSupportedCacheListInterface(const uint32_t maxCount)
45   : mCachedItemCount(0u),
46     mMaxCount(maxCount),
47     mData{maxCount}
48   {
49   }
50
51   inline bool NeedFullCheck() const
52   {
53     return mCachedItemCount < mMaxCount;
54   }
55
56   inline void SetSupported(ExtensionCheckerType type, bool isSupported = true)
57   {
58     auto& cache = mData[static_cast<uint32_t>(type)];
59     if(!cache.cached)
60     {
61       cache.cached      = true;
62       cache.isSupported = isSupported;
63       ++mCachedItemCount;
64     }
65   }
66
67   inline bool GetSupported(ExtensionCheckerType type) const
68   {
69     return mData[static_cast<uint32_t>(type)].isSupported;
70   }
71
72   inline bool GetCached(ExtensionCheckerType type) const
73   {
74     return mData[static_cast<uint32_t>(type)].cached;
75   }
76
77   void SetAllUncachedAsNotSupported()
78   {
79     if(NeedFullCheck())
80     {
81       for(auto&& iter : mData)
82       {
83         if(!iter.cached)
84         {
85           iter.isSupported = false;
86           iter.cached      = true;
87         }
88       }
89
90       // Mark all cached.
91       mCachedItemCount = mMaxCount;
92     }
93   }
94
95   uint32_t       mCachedItemCount;
96   const uint32_t mMaxCount;
97
98   std::vector<ExtensionSupportedCache> mData;
99 };
100
101 /**
102  * Gl extensions support checker system.
103  */
104 namespace GlExtensionCache
105 {
106 enum GlExtensionCheckerType
107 {
108   BLEND_EQUATION_ADVANCED = 0,
109   MULTISAMPLED_RENDER_TO_TEXTURE,
110   ///< Append additional extension checker type here.
111   EXTENSION_CHECKER_TYPE_MAX,
112 };
113
114 struct GlExtensionSupportedCacheList : public ExtensionSupportedCacheListInterface
115 {
116   GlExtensionSupportedCacheList()
117   : ExtensionSupportedCacheListInterface(static_cast<size_t>(GlExtensionCheckerType::EXTENSION_CHECKER_TYPE_MAX))
118   {
119   }
120
121   /**
122    * Ensure that we check all gl extension features for this system.
123    */
124   void EnsureGlExtensionSupportedCheck();
125 };
126 } // namespace GlExtensionCache
127
128 } // namespace Adaptor
129
130 } // namespace Internal
131
132 } // namespace Dali
133
134 #endif /* DALI_INTERNAL_GL_EXTENSION_SUPPORT_H */