[Tizen] Implement partial update
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-surface-frame-buffer.h
1 #ifndef DALI_INTERNAL_RENDER_SURFACE_FRAME_BUFFER_H
2 #define DALI_INTERNAL_RENDER_SURFACE_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 // EXTERNAL INCLUDES
21 #include <atomic>
22
23 // INTERNAL INCLUDES
24 #include <dali/internal/update/manager/update-manager.h>
25 #include <dali/internal/render/renderers/render-frame-buffer.h>
26 #include <dali/integration-api/render-surface.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 class Context;
35
36 namespace Render
37 {
38
39 class SurfaceFrameBuffer : public FrameBuffer
40 {
41 public:
42
43   /**
44    * Constructor
45    * @param[in] surface The render surface
46    */
47   SurfaceFrameBuffer( Integration::RenderSurface* surface );
48
49   /**
50    * Destructor
51    */
52   virtual ~SurfaceFrameBuffer();
53
54   /**
55    * @copydoc Dali::Internal::Renderer::FrameBuffer::Initialize()
56    */
57   void Initialize( Context& context ) override;
58
59   /**
60    * @copydoc Dali::Internal::Renderer::FrameBuffer::Destroy()
61    */
62   void Destroy( Context& context ) override;
63
64   /**
65    * @copydoc Dali::Internal::Renderer::FrameBuffer::GlContextDestroyed()
66    */
67   void GlContextDestroyed() override;
68
69   /**
70    * @copydoc Dali::Internal::Renderer::FrameBuffer::Bind()
71    */
72   void Bind( Context& context ) override;
73
74   /**
75    * @copydoc Dali::Internal::Renderer::FrameBuffer::GetWidth()
76    */
77   uint32_t GetWidth() const override;
78
79   /**
80    * @copydoc Dali::Internal::Renderer::FrameBuffer::GetHeight()
81    */
82   uint32_t GetHeight() const override;
83
84   /**
85    * @copydoc Dali::Internal::Renderer::FrameBuffer::IsSurfaceBacked()
86    */
87   bool IsSurfaceBacked() override { return true; };
88
89   /**
90    * @brief Sets the frame buffer size.
91    * @param[in] width The width size
92    * @param[in] height The height size
93    */
94   void SetSize( uint32_t width, uint32_t height );
95
96   /**
97    * @brief Sets the background color.
98    * @param[in] color The new background color
99    */
100   void SetBackgroundColor( const Vector4& color );
101
102   /**
103    * @copydoc Dali::Internal::FrameBuffer::MarkSurfaceAsInvalid()
104    */
105   void MarkSurfaceAsInvalid() { mIsSurfaceInvalid = true; };
106
107   /**
108    * @brief Gets whether the render surface in this frame buffer is valid or not
109    * @note The render surface becomes invalid when it is deleted in the event thread
110    * @return Whether the render surface is valid or not
111    */
112   bool IsSurfaceValid() const;
113
114 public:
115
116   /**
117    * Called after this frame buffer is rendered in the render manager
118    */
119   void PostRender();
120
121   /**
122    * Gets the context holding the GL state of rendering for the surface
123    * @return the context
124    */
125   Context* GetContext();
126
127   /**
128    * @brief Makes the graphics context current
129    */
130   void MakeContextCurrent();
131
132   /**
133    * @brief Gets the background color of the surface.
134    * @return The background color
135    */
136   Vector4 GetBackgroundColor();
137
138   /**
139    * @brief Sets currentframe damaged rects
140    * @param[in] Sets currentframe damaged rects
141    * @param[out] return merged rect
142    */
143   void SetDamagedRect( const Dali::DamagedRect& damagedRect, Dali::DamagedRect& mergedRect );
144
145   /**
146    * @brief Gets whether partial update is required for partial update
147    * @return whether partial update or not
148    */
149   bool IsPartialUpdateEnabled() const;
150
151   /**
152    * @brief Sets whether partial update is required for partial update
153    * @param[in] value whether partial update or not
154    */
155   void SetPartialUpdateEnabled( bool value );
156
157 private:
158
159   Integration::RenderSurface* mSurface;   ///< The render surface
160   Context*                    mContext;   ///< The context holding the GL state of rendering for the surface backed frame buffer
161
162   uint32_t                    mWidth;
163   uint32_t                    mHeight;
164   Vector4                     mBackgroundColor;
165   bool                        mSizeChanged;
166   bool                        mBackgroundColorChanged;
167   std::atomic<bool>           mIsSurfaceInvalid; ///< This is set only from the event thread and read only from the render thread
168   bool                        mPartialUpdateEnabled; ///< This value is whether partial update is required
169 };
170
171 // Messages for FrameBuffer
172 inline void SetFrameBufferSizeMessage( SceneGraph::UpdateManager& updateManager, SurfaceFrameBuffer* surfaceFrameBuffer, uint32_t width, uint32_t height )
173 {
174   typedef MessageValue2< SurfaceFrameBuffer, uint32_t, uint32_t  > LocalType;
175
176   // Reserve some memory inside the message queue
177   uint32_t* slot = updateManager.ReserveMessageSlot( sizeof( LocalType ) );
178
179   // Construct message in the message queue memory; note that delete should not be called on the return value
180   new (slot) LocalType( surfaceFrameBuffer, &SurfaceFrameBuffer::SetSize, width, height );
181 }
182
183 inline void SetFrameBufferBackgroundColorMessage( SceneGraph::UpdateManager& updateManager, SurfaceFrameBuffer* surfaceFrameBuffer, const Vector4& color )
184 {
185   typedef MessageValue1< SurfaceFrameBuffer, Vector4 > LocalType;
186
187   // Reserve some memory inside the message queue
188   uint32_t* slot = updateManager.ReserveMessageSlot( sizeof( LocalType ) );
189
190   // Construct message in the message queue memory; note that delete should not be called on the return value
191   new (slot) LocalType( surfaceFrameBuffer, &SurfaceFrameBuffer::SetBackgroundColor, color );
192 }
193
194 inline void SetFrameBufferPartialUpdateMessage( SceneGraph::UpdateManager& updateManager, SurfaceFrameBuffer* surfaceFrameBuffer, bool value )
195 {
196   typedef MessageValue1< SurfaceFrameBuffer, bool > LocalType;
197
198   // Reserve some memory inside the message queue
199   uint32_t* slot = updateManager.ReserveMessageSlot( sizeof( LocalType ) );
200
201   // Construct message in the message queue memory; note that delete should not be called on the return value
202   new (slot) LocalType( surfaceFrameBuffer, &SurfaceFrameBuffer::SetPartialUpdateEnabled, value );
203 }
204
205 } // namespace Render
206
207 } // namespace Internal
208
209 } // namespace Dali
210
211
212 #endif // DALI_INTERNAL_RENDER_SURFACE_FRAME_BUFFER_H