[dali_2.3.31] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / frame-buffer-impl.h
1 #ifndef DALI_INTERNAL_FRAME_BUFFER_H
2 #define DALI_INTERNAL_FRAME_BUFFER_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 // INTERNAL INCLUDES
22 #include <dali/devel-api/rendering/frame-buffer-devel.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/event/rendering/texture-impl.h>
25 #include <dali/public-api/common/dali-common.h>   // DALI_ASSERT_ALWAYS
26 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
27 #include <dali/public-api/object/base-object.h>
28 #include <dali/public-api/rendering/frame-buffer.h>
29
30 namespace Dali
31 {
32 using Mask = Dali::FrameBuffer::Attachment::Mask;
33
34 namespace Internal
35 {
36 namespace Render
37 {
38 class FrameBuffer;
39 }
40
41 class FrameBuffer;
42 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
43
44 class FrameBuffer : public BaseObject
45 {
46 public:
47   using Mask = Dali::FrameBuffer::Attachment::Mask;
48
49   /**
50    * @brief Create a new FrameBuffer
51    *
52    * @param[in] width       The width of the FrameBuffer
53    * @param[in] height      The height of the FrameBuffer
54    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
55    * @return A smart-pointer to the newly allocated Texture.
56    */
57   static FrameBufferPtr New(uint32_t width, uint32_t height, Mask attachments);
58
59   /**
60    * A reference counted object may only be deleted by calling Unreference()
61    */
62   ~FrameBuffer() override;
63
64   /**
65    * @brief Get the FrameBuffer render object
66    *
67    * @return the FrameBuffer render object
68    */
69   Render::FrameBuffer* GetRenderObject() const;
70
71   /**
72    * @copydoc Dali::FrameBuffer::AttachColorTexture()
73    */
74   void AttachColorTexture(TexturePtr texture, uint32_t mipmapLevel, uint32_t layer);
75
76   /**
77    * @copydoc Dali::DevelFrameBuffer::AttachDepthTexture()
78    */
79   void AttachDepthTexture(TexturePtr texture, uint32_t mipmapLevel);
80
81   /**
82    * @copydoc Dali::DevelFrameBuffer::AttachDepthStencilTexture()
83    */
84   void AttachDepthStencilTexture(TexturePtr texture, uint32_t mipmapLevel);
85
86   /**
87    * @copydoc Dali::DevelFrameBuffer::SetMultiSamplingLevel()
88    */
89   void SetMultiSamplingLevel(uint8_t multiSamplingLevel);
90
91   /**
92    * @copydoc Dali::FrameBuffer::GetColorTexture()
93    */
94   Texture* GetColorTexture(uint8_t index) const;
95
96   /**
97    * @copydoc Dali::DevelFrameBuffer::GetDepthTexture()
98    */
99   Texture* GetDepthTexture() const;
100
101   /**
102    * @copydoc Dali::DevelFrameBuffer::GetDepthStencilTexture()
103    */
104   Texture* GetDepthStencilTexture() const;
105
106   /**
107    * @brief Sets the frame buffer size.
108    * @param[in] width The width size
109    * @param[in] height The height size
110    */
111   void SetSize(uint32_t width, uint32_t height);
112
113 private: // implementation
114   /**
115    * Constructor
116    * @param[in] width       The width of the FrameBuffer
117    * @param[in] height      The height of the FrameBuffer
118    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
119    */
120   FrameBuffer(uint32_t width, uint32_t height, Mask attachments);
121
122   /**
123    * Second stage initialization of the Texture
124    */
125   void Initialize();
126
127 protected:
128 private: // unimplemented methods
129   FrameBuffer()                   = delete;
130   FrameBuffer(const FrameBuffer&) = delete;
131   FrameBuffer& operator=(const FrameBuffer&) = delete;
132
133 private:                                               // data
134   Internal::EventThreadServices& mEventThreadServices; ///< Used to send messages to the render thread via update thread
135   Internal::Render::FrameBuffer* mRenderObject;        ///< The Render::Texture associated to this texture
136
137   TexturePtr mColor[Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS];
138   TexturePtr mDepth;
139   TexturePtr mStencil;
140   uint32_t   mWidth;
141   uint32_t   mHeight;
142   Mask       mAttachments; ///< Bit-mask of type FrameBuffer::Attachment::Mask
143   uint8_t    mColorAttachmentCount;
144 };
145
146 } // namespace Internal
147
148 // Helpers for public-api forwarding methods
149 inline Internal::FrameBuffer& GetImplementation(Dali::FrameBuffer& handle)
150 {
151   DALI_ASSERT_ALWAYS(handle && "FrameBuffer handle is empty");
152
153   BaseObject& object = handle.GetBaseObject();
154
155   return static_cast<Internal::FrameBuffer&>(object);
156 }
157
158 inline const Internal::FrameBuffer& GetImplementation(const Dali::FrameBuffer& handle)
159 {
160   DALI_ASSERT_ALWAYS(handle && "FrameBuffer handle is empty");
161
162   const BaseObject& object = handle.GetBaseObject();
163
164   return static_cast<const Internal::FrameBuffer&>(object);
165 }
166
167 } // namespace Dali
168
169 #endif // DALI_INTERNAL_FRAME_BUFFER_H