Graphics and Vulkan integration within Adaptor
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / common / render-helper.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/graphics/common/render-helper.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/graphics/graphics.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
27 #include <dali/internal/window-system/common/display-connection.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37
38 RenderHelper::RenderHelper( AdaptorInternalServices& adaptorInterfaces )
39 : mGLES( adaptorInterfaces.GetGlesInterface() ),
40   mEglFactory( &adaptorInterfaces.GetEGLFactoryInterface()),
41   mEGL( NULL ),
42   mGraphics( adaptorInterfaces.GetGraphics() ),
43   mSurfaceReplaced( false ),
44   mSurfaceResized( false )
45 {
46   // set the initial values before render thread starts
47   mSurface = adaptorInterfaces.GetRenderSurfaceInterface();
48
49   if( mSurface )
50   {
51     mDisplayConnection = Dali::DisplayConnection::New( mSurface->GetSurfaceType() );
52   }
53   else
54   {
55     mDisplayConnection = Dali::DisplayConnection::New();
56   }
57 }
58
59 RenderHelper::~RenderHelper()
60 {
61   if (mDisplayConnection)
62   {
63     delete mDisplayConnection;
64     mDisplayConnection = NULL;
65   }
66 #if 0
67   mEglFactory->Destroy();
68 #endif
69 }
70
71 void RenderHelper::Start()
72 {
73 #if 0
74   if( mSurface )
75   {
76     mSurface->StartRender();
77   }
78 #endif
79 }
80
81 void RenderHelper::Stop()
82 {
83 #if 0
84   if( mSurface )
85   {
86     // Tell surface we have stopped rendering
87     mSurface->StopRender();
88   }
89 #endif
90 }
91
92 void RenderHelper::ConsumeEvents()
93 {
94   mDisplayConnection->ConsumeEvents();
95 }
96
97 void RenderHelper::InitializeEgl()
98 {
99 #if 0
100   mEGL = mEglFactory->Create();
101
102   DALI_ASSERT_ALWAYS( mSurface && "NULL surface" );
103
104   // Initialize EGL & OpenGL
105   mDisplayConnection->InitializeEgl( *mEGL );
106   mSurface->InitializeEgl( *mEGL );
107
108   // create the OpenGL context
109   mEGL->CreateContext();
110
111   // create the OpenGL surface
112   mSurface->CreateEglSurface(*mEGL);
113
114   // Make it current
115   mEGL->MakeContextCurrent();
116 #endif
117 }
118
119 void RenderHelper::ReplaceSurface( RenderSurface* newSurface )
120 {
121 #if 0
122   mSurface->DestroyEglSurface(*mEGL);
123
124   // This is designed for replacing pixmap surfaces, but should work for window as well
125   // we need to delete the egl surface and renderable (pixmap / window)
126   // Then create a new pixmap/window and new egl surface
127   // If the new surface has a different display connection, then the context will be lost
128   DALI_ASSERT_ALWAYS(newSurface && "NULL surface");
129
130   mDisplayConnection->InitializeEgl(*mEGL);
131
132   newSurface->ReplaceEGLSurface(*mEGL);
133
134   // use the new surface from now on
135   mSurface = newSurface;
136   mSurfaceReplaced = true;
137 #endif
138 }
139
140 void RenderHelper::ResizeSurface()
141 {
142   mSurfaceResized = true;
143 }
144
145 void RenderHelper::ShutdownEgl()
146 {
147 #if 0
148   if( mSurface )
149   {
150     // give a chance to destroy the OpenGL surface that created externally
151     mSurface->DestroyEglSurface( *mEGL );
152
153     mSurface = NULL;
154   }
155
156   // delete the GL context / egl surface
157   mEGL->TerminateGles();
158 #endif
159 }
160
161 bool RenderHelper::PreRender()
162 {
163   mGraphics.PreRender( 1 );
164 #if 0
165   if( mSurface )
166   {
167     mSurface->PreRender( *mEGL, mGLES, mSurfaceResized );
168   }
169   mGLES.PreRender();
170 #endif
171   return true;
172 }
173
174 void RenderHelper::PostRender( bool renderToFbo )
175 {
176   mGraphics.PostRender( 1 );
177 #if 0
178   // Inform the gl implementation that rendering has finished before informing the surface
179   mGLES.PostRender();
180
181   if( renderToFbo )
182   {
183     mGLES.Flush();
184     mGLES.Finish();
185   }
186   else
187   {
188     if( mSurface )
189     {
190       // Inform the surface that rendering this frame has finished.
191       mSurface->PostRender( *mEGL, mGLES, mDisplayConnection, mSurfaceReplaced, mSurfaceResized );
192     }
193   }
194   mSurfaceReplaced = false;
195   mSurfaceResized = false;
196 #endif
197 }
198
199 } // namespace Adaptor
200
201 } // namespace Internal
202
203 } // namespace Dali