2 * Copyright (c) 2017 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 ),
42 mSurfaceResized( false )
44 // set the initial values before render thread starts
45 mSurface = adaptorInterfaces.GetRenderSurfaceInterface();
49 mDisplayConnection = Dali::DisplayConnection::New( mSurface->GetSurfaceType() );
53 mDisplayConnection = Dali::DisplayConnection::New();
57 RenderHelper::~RenderHelper()
59 if (mDisplayConnection)
61 delete mDisplayConnection;
62 mDisplayConnection = NULL;
65 mEglFactory->Destroy();
68 void RenderHelper::Start()
72 mSurface->StartRender();
76 void RenderHelper::Stop()
80 // Tell surface we have stopped rendering
81 mSurface->StopRender();
85 void RenderHelper::ConsumeEvents()
87 mDisplayConnection->ConsumeEvents();
90 void RenderHelper::InitializeEgl()
92 mEGL = mEglFactory->Create();
94 DALI_ASSERT_ALWAYS( mSurface && "NULL surface" );
96 // Initialize EGL & OpenGL
97 mDisplayConnection->InitializeEgl( *mEGL );
98 mSurface->InitializeEgl( *mEGL );
100 // create the OpenGL context
101 mEGL->CreateContext();
103 // create the OpenGL surface
104 mSurface->CreateEglSurface(*mEGL);
107 mEGL->MakeContextCurrent();
110 void RenderHelper::ReplaceSurface( RenderSurface* newSurface )
112 mSurface->DestroyEglSurface(*mEGL);
114 // This is designed for replacing pixmap surfaces, but should work for window as well
115 // we need to delete the egl surface and renderable (pixmap / window)
116 // Then create a new pixmap/window and new egl surface
117 // If the new surface has a different display connection, then the context will be lost
118 DALI_ASSERT_ALWAYS(newSurface && "NULL surface");
120 mDisplayConnection->InitializeEgl(*mEGL);
122 newSurface->ReplaceEGLSurface(*mEGL);
124 // use the new surface from now on
125 mSurface = newSurface;
126 mSurfaceReplaced = true;
129 void RenderHelper::ResizeSurface()
131 mSurfaceResized = true;
134 void RenderHelper::ShutdownEgl()
138 // give a chance to destroy the OpenGL surface that created externally
139 mSurface->DestroyEglSurface( *mEGL );
144 // delete the GL context / egl surface
145 mEGL->TerminateGles();
148 bool RenderHelper::PreRender()
152 mSurface->PreRender( *mEGL, mGLES, mSurfaceResized );
158 void RenderHelper::PostRender()
160 // Inform the gl implementation that rendering has finished before informing the surface
165 // Inform the surface that rendering this frame has finished.
166 mSurface->PostRender( *mEGL, mGLES, mDisplayConnection, mSurfaceReplaced, mSurfaceResized );
168 mSurfaceReplaced = false;
169 mSurfaceResized = false;
172 } // namespace Adaptor
174 } // namespace Internal