167360be1179dac84188277508ce5d45a703139a
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / common / render-helper.cpp
1 /*
2  * Copyright (c) 2018 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 : mEglFactory( &adaptorInterfaces.GetEGLFactoryInterface()),
40   mEGL( NULL ),
41   mGraphics( adaptorInterfaces.GetGraphics() ),
42   mSurfaceReplaced( false ),
43   mSurfaceResized( false )
44 {
45   // set the initial values before render thread starts
46   mSurface = adaptorInterfaces.GetRenderSurfaceInterface();
47
48   if( mSurface )
49   {
50     mDisplayConnection = Dali::DisplayConnection::New( mSurface->GetSurfaceType() );
51   }
52   else
53   {
54     mDisplayConnection = Dali::DisplayConnection::New();
55   }
56 }
57
58 RenderHelper::~RenderHelper()
59 {
60   if (mDisplayConnection)
61   {
62     delete mDisplayConnection;
63     mDisplayConnection = NULL;
64   }
65 #if 0
66   mEglFactory->Destroy();
67 #endif
68 }
69
70 void RenderHelper::Start()
71 {
72 #if 0
73   if( mSurface )
74   {
75     mSurface->StartRender();
76   }
77 #endif
78 }
79
80 void RenderHelper::Stop()
81 {
82 #if 0
83   if( mSurface )
84   {
85     // Tell surface we have stopped rendering
86     mSurface->StopRender();
87   }
88 #endif
89 }
90
91 void RenderHelper::ConsumeEvents()
92 {
93   mDisplayConnection->ConsumeEvents();
94 }
95
96 void RenderHelper::InitializeEgl()
97 {
98 #if 0
99   mEGL = mEglFactory->Create();
100
101   DALI_ASSERT_ALWAYS( mSurface && "NULL surface" );
102
103   // Initialize EGL & OpenGL
104   mDisplayConnection->InitializeEgl( *mEGL );
105   mSurface->InitializeEgl( *mEGL );
106
107   // create the OpenGL context
108   mEGL->CreateContext();
109
110   // create the OpenGL surface
111   mSurface->CreateEglSurface(*mEGL);
112
113   // Make it current
114   mEGL->MakeContextCurrent();
115 #endif
116 }
117
118 void RenderHelper::ReplaceSurface( RenderSurface* newSurface )
119 {
120 #if 0
121   mSurface->DestroyEglSurface(*mEGL);
122
123   // This is designed for replacing pixmap surfaces, but should work for window as well
124   // we need to delete the egl surface and renderable (pixmap / window)
125   // Then create a new pixmap/window and new egl surface
126   // If the new surface has a different display connection, then the context will be lost
127   DALI_ASSERT_ALWAYS(newSurface && "NULL surface");
128
129   mDisplayConnection->InitializeEgl(*mEGL);
130
131   newSurface->ReplaceEGLSurface(*mEGL);
132
133   // use the new surface from now on
134   mSurface = newSurface;
135   mSurfaceReplaced = true;
136 #endif
137 }
138
139 void RenderHelper::ResizeSurface()
140 {
141   mSurfaceResized = true;
142 }
143
144 void RenderHelper::ShutdownEgl()
145 {
146 #if 0
147   if( mSurface )
148   {
149     // give a chance to destroy the OpenGL surface that created externally
150     mSurface->DestroyEglSurface( *mEGL );
151
152     mSurface = NULL;
153   }
154
155   // delete the GL context / egl surface
156   mEGL->TerminateGles();
157 #endif
158 }
159
160 bool RenderHelper::PreRender()
161 {
162 #if 0
163   if( mSurface )
164   {
165     mSurface->PreRender( *mEGL, mSurfaceResized );
166   }
167 #endif
168   return true;
169 }
170
171 void RenderHelper::PostRender( bool renderToFbo )
172 {
173 #if 0
174   if( renderToFbo )
175   {
176     //mGLES.Flush();
177     //mGLES.Finish();
178   }
179   else
180   {
181     if( mSurface )
182     {
183       // Inform the surface that rendering this frame has finished.
184       mSurface->PostRender( *mEGL, mDisplayConnection, mSurfaceReplaced, mSurfaceResized );
185     }
186   }
187   mSurfaceReplaced = false;
188   mSurfaceResized = false;
189 #endif
190 }
191
192 } // namespace Adaptor
193
194 } // namespace Internal
195
196 } // namespace Dali