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 <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 : mGLES( adaptorInterfaces.GetGlesInterface() ),
40 mEglFactory( &adaptorInterfaces.GetEGLFactoryInterface()),
42 mGraphics( adaptorInterfaces.GetGraphics() ),
43 mSurfaceReplaced( false ),
44 mSurfaceResized( false )
46 // set the initial values before render thread starts
47 mSurface = adaptorInterfaces.GetRenderSurfaceInterface();
51 mDisplayConnection = Dali::DisplayConnection::New( mSurface->GetSurfaceType() );
55 mDisplayConnection = Dali::DisplayConnection::New();
59 RenderHelper::~RenderHelper()
61 if (mDisplayConnection)
63 delete mDisplayConnection;
64 mDisplayConnection = NULL;
67 mEglFactory->Destroy();
71 void RenderHelper::Start()
76 mSurface->StartRender();
81 void RenderHelper::Stop()
86 // Tell surface we have stopped rendering
87 mSurface->StopRender();
92 void RenderHelper::ConsumeEvents()
94 mDisplayConnection->ConsumeEvents();
97 void RenderHelper::InitializeEgl()
100 mEGL = mEglFactory->Create();
102 DALI_ASSERT_ALWAYS( mSurface && "NULL surface" );
104 // Initialize EGL & OpenGL
105 mDisplayConnection->InitializeEgl( *mEGL );
106 mSurface->InitializeEgl( *mEGL );
108 // create the OpenGL context
109 mEGL->CreateContext();
111 // create the OpenGL surface
112 mSurface->CreateEglSurface(*mEGL);
115 mEGL->MakeContextCurrent();
119 void RenderHelper::ReplaceSurface( RenderSurface* newSurface )
122 mSurface->DestroyEglSurface(*mEGL);
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");
130 mDisplayConnection->InitializeEgl(*mEGL);
132 newSurface->ReplaceEGLSurface(*mEGL);
134 // use the new surface from now on
135 mSurface = newSurface;
136 mSurfaceReplaced = true;
140 void RenderHelper::ResizeSurface()
142 mSurfaceResized = true;
145 void RenderHelper::ShutdownEgl()
150 // give a chance to destroy the OpenGL surface that created externally
151 mSurface->DestroyEglSurface( *mEGL );
156 // delete the GL context / egl surface
157 mEGL->TerminateGles();
161 bool RenderHelper::PreRender()
163 mGraphics.PreRender( 1 );
167 mSurface->PreRender( *mEGL, mGLES, mSurfaceResized );
174 void RenderHelper::PostRender( bool renderToFbo )
176 mGraphics.PostRender( 1 );
178 // Inform the gl implementation that rendering has finished before informing the surface
190 // Inform the surface that rendering this frame has finished.
191 mSurface->PostRender( *mEGL, mGLES, mDisplayConnection, mSurfaceReplaced, mSurfaceResized );
194 mSurfaceReplaced = false;
195 mSurfaceResized = false;
199 } // namespace Adaptor
201 } // namespace Internal