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