[Tizen] Fix FrameBuffer sync issue, etc.
[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 // INTERNAL INCLUDES
21 #include <dali/internal/update/manager/update-manager.h>
22 #include <dali/internal/render/renderers/render-frame-buffer.h>
23 #include <dali/integration-api/render-surface.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 class Context;
32
33 namespace Render
34 {
35
36 class SurfaceFrameBuffer : public FrameBuffer
37 {
38 public:
39
40   /**
41    * Constructor
42    * @param[in] surface The render surface
43    */
44   SurfaceFrameBuffer( Integration::RenderSurface* surface );
45
46   /**
47    * Destructor
48    */
49   virtual ~SurfaceFrameBuffer();
50
51   /**
52    * @copydoc Dali::Internal::Renderer::FrameBuffer::Initialize()
53    */
54   void Initialize( Context& context ) override;
55
56   /**
57    * @copydoc Dali::Internal::Renderer::FrameBuffer::Destroy()
58    */
59   void Destroy( Context& context ) override;
60
61   /**
62    * @copydoc Dali::Internal::Renderer::FrameBuffer::GlContextDestroyed()
63    */
64   void GlContextDestroyed() override;
65
66   /**
67    * @copydoc Dali::Internal::Renderer::FrameBuffer::Bind()
68    */
69   void Bind( Context& context ) override;
70
71   /**
72    * @copydoc Dali::Internal::Renderer::FrameBuffer::GetWidth()
73    */
74   uint32_t GetWidth() const override;
75
76   /**
77    * @copydoc Dali::Internal::Renderer::FrameBuffer::GetHeight()
78    */
79   uint32_t GetHeight() const override;
80
81   /**
82    * @copydoc Dali::Internal::Renderer::FrameBuffer::IsSurfaceBacked()
83    */
84   bool IsSurfaceBacked() override { return true; };
85
86   /**
87    * @brief Sets the frame buffer size.
88    * @param[in] width The width size
89    * @param[in] height The height size
90    */
91   void SetSize( uint32_t width, uint32_t height );
92
93   /**
94    * @brief Sets the background color.
95    * @param[in] color The new background color
96    */
97   void SetBackgroundColor( const Vector4& color );
98
99 public:
100
101   /**
102    * Called after this frame buffer is rendered in the render manager
103    */
104   void PostRender();
105
106   /**
107    * Gets the context holding the GL state of rendering for the surface
108    * @return the context
109    */
110   Context* GetContext();
111
112   /**
113    * @brief Gets whether the depth buffer is required
114    * @return TRUE if the depth buffer is required
115    */
116   Integration::DepthBufferAvailable GetDepthBufferRequired();
117
118   /**
119    * @brief Gets whether the stencil buffer is required
120    * @return TRUE if the stencil buffer is required
121    */
122   Integration::StencilBufferAvailable GetStencilBufferRequired();
123
124   /**
125    * @brief Gets the background color of the surface.
126    * @return The background color
127    */
128   Vector4 GetBackgroundColor();
129
130 private:
131
132   Integration::RenderSurface* mSurface;   ///< The render surface
133   Context*                    mContext;   ///< The context holding the GL state of rendering for the surface backed frame buffer
134
135   uint32_t                    mWidth;
136   uint32_t                    mHeight;
137   Vector4                     mBackgroundColor;
138   bool                        mSizeChanged;
139 };
140
141 // Messages for FrameBuffer
142 inline void SetFrameBufferSizeMessage( SceneGraph::UpdateManager& updateManager, SurfaceFrameBuffer* surfaceFrameBuffer, uint32_t width, uint32_t height )
143 {
144   typedef MessageValue2< SurfaceFrameBuffer, uint32_t, uint32_t  > LocalType;
145
146   // Reserve some memory inside the message queue
147   uint32_t* slot = updateManager.ReserveMessageSlot( sizeof( LocalType ) );
148
149   // Construct message in the message queue memory; note that delete should not be called on the return value
150   new (slot) LocalType( surfaceFrameBuffer, &SurfaceFrameBuffer::SetSize, width, height );
151 }
152
153 inline void SetFrameBufferBackgroundColorMessage( SceneGraph::UpdateManager& updateManager, SurfaceFrameBuffer* surfaceFrameBuffer, const Vector4& color )
154 {
155   typedef MessageValue1< SurfaceFrameBuffer, Vector4 > LocalType;
156
157   // Reserve some memory inside the message queue
158   uint32_t* slot = updateManager.ReserveMessageSlot( sizeof( LocalType ) );
159
160   // Construct message in the message queue memory; note that delete should not be called on the return value
161   new (slot) LocalType( surfaceFrameBuffer, &SurfaceFrameBuffer::SetBackgroundColor, color );
162 }
163
164 } // namespace Render
165
166 } // namespace Internal
167
168 } // namespace Dali
169
170
171 #endif // DALI_INTERNAL_RENDER_SURFACE_FRAME_BUFFER_H