2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/graphics/common/render-helper.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/graphics/graphics.h>
26 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
27 #include <dali/internal/window-system/common/display-connection.h>
38 RenderHelper::RenderHelper( AdaptorInternalServices& adaptorInterfaces )
39 : mEglFactory( &adaptorInterfaces.GetEGLFactoryInterface()),
41 mGraphics( adaptorInterfaces.GetGraphics() ),
42 mSurfaceReplaced( false ),
43 mSurfaceResized( false )
45 // set the initial values before render thread starts
46 mSurface = adaptorInterfaces.GetRenderSurfaceInterface();
50 mDisplayConnection = Dali::DisplayConnection::New( mSurface->GetSurfaceType() );
54 mDisplayConnection = Dali::DisplayConnection::New();
58 RenderHelper::~RenderHelper()
60 if (mDisplayConnection)
62 delete mDisplayConnection;
63 mDisplayConnection = NULL;
66 mEglFactory->Destroy();
70 void RenderHelper::Start()
75 mSurface->StartRender();
80 void RenderHelper::Stop()
85 // Tell surface we have stopped rendering
86 mSurface->StopRender();
91 void RenderHelper::ConsumeEvents()
93 mDisplayConnection->ConsumeEvents();
96 void RenderHelper::InitializeEgl()
99 mEGL = mEglFactory->Create();
101 DALI_ASSERT_ALWAYS( mSurface && "NULL surface" );
103 // Initialize EGL & OpenGL
104 mDisplayConnection->InitializeEgl( *mEGL );
105 mSurface->InitializeEgl( *mEGL );
107 // create the OpenGL context
108 mEGL->CreateContext();
110 // create the OpenGL surface
111 mSurface->CreateEglSurface(*mEGL);
114 mEGL->MakeContextCurrent();
118 void RenderHelper::ReplaceSurface( RenderSurface* newSurface )
121 mSurface->DestroyEglSurface(*mEGL);
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");
129 mDisplayConnection->InitializeEgl(*mEGL);
131 newSurface->ReplaceEGLSurface(*mEGL);
133 // use the new surface from now on
134 mSurface = newSurface;
135 mSurfaceReplaced = true;
139 void RenderHelper::ResizeSurface()
141 mSurfaceResized = true;
144 void RenderHelper::ShutdownEgl()
149 // give a chance to destroy the OpenGL surface that created externally
150 mSurface->DestroyEglSurface( *mEGL );
155 // delete the GL context / egl surface
156 mEGL->TerminateGles();
160 bool RenderHelper::PreRender()
165 mSurface->PreRender( *mEGL, mSurfaceResized );
171 void RenderHelper::PostRender( bool renderToFbo )
183 // Inform the surface that rendering this frame has finished.
184 mSurface->PostRender( *mEGL, mDisplayConnection, mSurfaceReplaced, mSurfaceResized );
187 mSurfaceReplaced = false;
188 mSurfaceResized = false;
192 } // namespace Adaptor
194 } // namespace Internal