[Tizen] Make possible to capture on the old driver devices.
[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 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
48   using Mask = Dali::FrameBuffer::Attachment::Mask;
49
50   /**
51    * @brief Create a new FrameBuffer
52    *
53    * @param[in] width       The width of the FrameBuffer
54    * @param[in] height      The height of the FrameBuffer
55    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
56    * @return A smart-pointer to the newly allocated Texture.
57    */
58   static FrameBufferPtr New( uint32_t width, uint32_t height, Mask attachments );
59
60   /**
61    * A reference counted object may only be deleted by calling Unreference()
62    */
63   ~FrameBuffer() override;
64
65   /**
66    * @brief Get the FrameBuffer render object
67    *
68    * @return the FrameBuffer render object
69    */
70   Render::FrameBuffer* GetRenderObject() const;
71
72   /**
73    * @copydoc Dali::FrameBuffer::AttachColorTexture()
74    */
75   void AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel, uint32_t layer );
76
77   /**
78    * @copydoc Dali::DevelFrameBuffer::AttachDepthTexture()
79    */
80   void AttachDepthTexture( TexturePtr texture, uint32_t mipmapLevel );
81
82   /**
83    * @copydoc Dali::DevelFrameBuffer::AttachDepthStencilTexture()
84    */
85   void AttachDepthStencilTexture( TexturePtr texture, uint32_t mipmapLevel );
86
87   /**
88    * @copydoc Dali::FrameBuffer::GetColorTexture()
89    */
90   Texture* GetColorTexture(uint8_t index) const;
91
92   /**
93    * @copydoc Dali::DevelFrameBuffer::GetDepthTexture()
94    */
95   Texture* GetDepthTexture() const;
96
97   /**
98    * @copydoc Dali::DevelFrameBuffer::GetDepthStencilTexture()
99    */
100   Texture* GetDepthStencilTexture() const;
101
102   /**
103    * @brief Retrieve captured buffer
104    *
105    * @return a pointer of the buffer.
106    */
107   uint8_t* GetRenderedBuffer();
108
109   /**
110    * @copydoc Dali::FrameBuffer::CaptureRenderedResult()
111    */
112   void CaptureRenderedResult();
113
114   /**
115    * @brief Sets the frame buffer size.
116    * @param[in] width The width size
117    * @param[in] height The height size
118    */
119   void SetSize( uint32_t width, uint32_t height );
120
121 private: // implementation
122
123   /**
124    * Constructor
125    * @param[in] width       The width of the FrameBuffer
126    * @param[in] height      The height of the FrameBuffer
127    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
128    */
129   FrameBuffer( uint32_t width, uint32_t height, Mask attachments );
130
131   /**
132    * Second stage initialization of the Texture
133    */
134   void Initialize();
135
136 protected:
137
138 private: // unimplemented methods
139
140   FrameBuffer() = delete;
141   FrameBuffer( const FrameBuffer& ) = delete;
142   FrameBuffer& operator=( const FrameBuffer& ) = delete;
143
144 private: // data
145
146   Internal::EventThreadServices& mEventThreadServices; ///< Used to send messages to the render thread via update thread
147   Internal::Render::FrameBuffer* mRenderObject;        ///< The Render::Texture associated to this texture
148
149   TexturePtr mColor[ Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS ];
150   TexturePtr mDepth;
151   TexturePtr mStencil;
152   uint32_t mWidth;
153   uint32_t mHeight;
154   Mask mAttachments;                           ///< Bit-mask of type FrameBuffer::Attachment::Mask
155   uint8_t mColorAttachmentCount;
156 };
157
158 } // namespace Internal
159
160 // Helpers for public-api forwarding methods
161 inline Internal::FrameBuffer& GetImplementation(Dali::FrameBuffer& handle)
162 {
163   DALI_ASSERT_ALWAYS(handle && "FrameBuffer handle is empty");
164
165   BaseObject& object = handle.GetBaseObject();
166
167   return static_cast<Internal::FrameBuffer&>(object);
168 }
169
170 inline const Internal::FrameBuffer& GetImplementation(const Dali::FrameBuffer& handle)
171 {
172   DALI_ASSERT_ALWAYS(handle && "FrameBuffer handle is empty");
173
174   const BaseObject& object = handle.GetBaseObject();
175
176   return static_cast<const Internal::FrameBuffer&>(object);
177 }
178
179 } // namespace Dali
180
181 #endif // DALI_INTERNAL_FRAME_BUFFER_H