2 * Copyright (c) 2015 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 "render-helper.h"
22 #include <dali/integration-api/debug.h>
25 #include <base/interfaces/adaptor-internal-services.h>
26 #include <base/display-connection.h>
37 RenderHelper::RenderHelper( AdaptorInternalServices& adaptorInterfaces )
38 : mGLES( adaptorInterfaces.GetGlesInterface() ),
39 mEglFactory( &adaptorInterfaces.GetEGLFactoryInterface()),
41 mSurfaceReplaced( false )
43 // set the initial values before render thread starts
44 mSurface = adaptorInterfaces.GetRenderSurfaceInterface();
48 mDisplayConnection = Dali::DisplayConnection::New( mSurface->GetSurfaceType() );
52 mDisplayConnection = Dali::DisplayConnection::New();
56 RenderHelper::~RenderHelper()
58 if (mDisplayConnection)
60 delete mDisplayConnection;
61 mDisplayConnection = NULL;
64 mEglFactory->Destroy();
67 void RenderHelper::Start()
71 mSurface->StartRender();
75 void RenderHelper::Stop()
79 // Tell surface we have stopped rendering
80 mSurface->StopRender();
84 void RenderHelper::ConsumeEvents()
86 mDisplayConnection->ConsumeEvents();
89 void RenderHelper::InitializeEgl()
91 mEGL = mEglFactory->Create();
93 DALI_ASSERT_ALWAYS( mSurface && "NULL surface" );
95 // Initialize EGL & OpenGL
96 mDisplayConnection->InitializeEgl( *mEGL );
97 mSurface->InitializeEgl( *mEGL );
99 // create the OpenGL context
100 mEGL->CreateContext();
102 // create the OpenGL surface
103 mSurface->CreateEglSurface(*mEGL);
106 mEGL->MakeContextCurrent();
109 void RenderHelper::ReplaceSurface( RenderSurface* newSurface )
111 mSurface->DestroyEglSurface(*mEGL);
113 // This is designed for replacing pixmap surfaces, but should work for window as well
114 // we need to delete the egl surface and renderable (pixmap / window)
115 // Then create a new pixmap/window and new egl surface
116 // If the new surface has a different display connection, then the context will be lost
117 DALI_ASSERT_ALWAYS(newSurface && "NULL surface");
119 mDisplayConnection->InitializeEgl(*mEGL);
121 newSurface->ReplaceEGLSurface(*mEGL);
123 // use the new surface from now on
124 mSurface = newSurface;
125 mSurfaceReplaced = true;
128 void RenderHelper::ShutdownEgl()
132 // give a chance to destroy the OpenGL surface that created externally
133 mSurface->DestroyEglSurface( *mEGL );
138 // delete the GL context / egl surface
139 mEGL->TerminateGles();
142 bool RenderHelper::PreRender()
146 mSurface->PreRender( *mEGL, mGLES );
152 void RenderHelper::PostRender()
154 // Inform the gl implementation that rendering has finished before informing the surface
159 // Inform the surface that rendering this frame has finished.
160 mSurface->PostRender( *mEGL, mGLES, mDisplayConnection, mSurfaceReplaced );
162 mSurfaceReplaced = false;
165 } // namespace Adaptor
167 } // namespace Internal