Move Added FrameBuffer API to Devel API
[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) 2020 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/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/rendering/frame-buffer.h>
26 #include <dali/devel-api/rendering/frame-buffer-devel.h>
27 #include <dali/internal/event/common/event-thread-services.h>
28 #include <dali/internal/event/rendering/texture-impl.h>
29
30 namespace Dali
31 {
32
33 namespace Integration
34 {
35 class RenderSurface;
36 }
37
38 namespace Internal
39 {
40 namespace Render
41 {
42 class FrameBuffer;
43 }
44
45 class FrameBuffer;
46 typedef IntrusivePtr<FrameBuffer> FrameBufferPtr;
47
48 class FrameBuffer : public BaseObject
49 {
50 public:
51
52   using Mask = Dali::FrameBuffer::Attachment::Mask;
53
54   /**
55    * @brief Create a new FrameBuffer
56    *
57    * @param[in] width       The width of the FrameBuffer
58    * @param[in] height      The height of the FrameBuffer
59    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
60    * @return A smart-pointer to the newly allocated Texture.
61    */
62   static FrameBufferPtr New( uint32_t width, uint32_t height, Mask attachments );
63
64   /**
65    * @brief Create a new FrameBuffer
66    *
67    * @param[in] renderSurface   The render surface
68    * @param[in] attachments     The attachments comprising the format of the FrameBuffer (bit-mask)
69    * @return A smart-pointer to the newly allocated Texture.
70    */
71   static FrameBufferPtr New( Dali::Integration::RenderSurface& renderSurface, Mask attachments );
72
73   /**
74    * A reference counted object may only be deleted by calling Unreference()
75    */
76   virtual ~FrameBuffer();
77
78   /**
79    * @brief Get the FrameBuffer render object
80    *
81    * @return the FrameBuffer render object
82    */
83   Render::FrameBuffer* GetRenderObject() const;
84
85   /**
86    * @copydoc Dali::FrameBuffer::AttachColorTexture()
87    */
88   void AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel, uint32_t layer );
89
90   /**
91    * @copydoc Dali::FrameBuffer::GetColorTexture()
92    */
93   Texture* GetColorTexture(uint8_t index) const;
94
95   /**
96    * @brief Sets the frame buffer size.
97    * @param[in] width The width size
98    * @param[in] height The height size
99    */
100   void SetSize( uint32_t width, uint32_t height );
101
102   /**
103    * @brief Mark the render surface as invalid
104    *
105    * The render surface is maked as invalid when it is deleted.
106    *
107    * @note Only for FrameBuffer backed by a render surface.
108    * @return True if the FrameBuffer is backed by a render surface
109    */
110   void MarkSurfaceAsInvalid();
111
112 private: // implementation
113
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( Integration::RenderSurface* renderSurface = nullptr );
126
127 protected:
128
129 private: // unimplemented methods
130
131   FrameBuffer() = delete;
132   FrameBuffer( const FrameBuffer& ) = delete;
133   FrameBuffer& operator=( const FrameBuffer& ) = delete;
134
135 private: // data
136
137   Internal::EventThreadServices& mEventThreadServices; ///< Used to send messages to the render thread via update thread
138   Internal::Render::FrameBuffer* mRenderObject;        ///< The Render::Texture associated to this texture
139
140   TexturePtr mColor[ Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS ];
141   uint32_t mWidth;
142   uint32_t mHeight;
143   Mask mAttachments;                           ///< Bit-mask of type FrameBuffer::Attachment::Mask
144   uint8_t mColorAttachmentCount;
145
146   bool mIsSurfaceBacked:1;
147
148 };
149
150 } // namespace Internal
151
152 // Helpers for public-api forwarding methods
153 inline Internal::FrameBuffer& GetImplementation(Dali::FrameBuffer& handle)
154 {
155   DALI_ASSERT_ALWAYS(handle && "FrameBuffer handle is empty");
156
157   BaseObject& object = handle.GetBaseObject();
158
159   return static_cast<Internal::FrameBuffer&>(object);
160 }
161
162 inline const Internal::FrameBuffer& GetImplementation(const Dali::FrameBuffer& handle)
163 {
164   DALI_ASSERT_ALWAYS(handle && "FrameBuffer handle is empty");
165
166   const BaseObject& object = handle.GetBaseObject();
167
168   return static_cast<const Internal::FrameBuffer&>(object);
169 }
170
171 } // namespace Dali
172
173 #endif // DALI_INTERNAL_FRAME_BUFFER_H