ce3c353eedc8ac7884de86c4f2b589ec887ba991
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / egl-graphics.cpp
1 /*
2  * Copyright (c) 2019 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
19 // CLASS HEADER
20 #include <dali/internal/graphics/gles/egl-graphics.h>
21
22 // INTERNAL INCLUDES
23 #include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Adaptor
30 {
31
32 EglGraphics::EglGraphics( )
33 : mMultiSamplingLevel( 0 )
34 {
35 }
36
37 EglGraphics::~EglGraphics()
38 {
39 }
40
41 void EglGraphics::SetGlesVersion( const int32_t glesVersion )
42 {
43   mEglImplementation->SetGlesVersion( glesVersion );
44   mGLES->SetGlesVersion( glesVersion );
45 }
46
47 void EglGraphics::SetIsSurfacelessContextSupported( const bool isSupported )
48 {
49   mGLES->SetIsSurfacelessContextSupported( isSupported );
50 }
51
52 void EglGraphics::Initialize( EnvironmentOptions* environmentOptions )
53 {
54   if( environmentOptions->GetGlesCallTime() > 0 )
55   {
56     mGLES = Utils::MakeUnique< GlProxyImplementation >( *environmentOptions );
57   }
58   else
59   {
60     mGLES.reset ( new GlImplementation() );
61   }
62
63   mDepthBufferRequired = static_cast< Integration::DepthBufferAvailable >( environmentOptions->DepthBufferRequired() );
64   mStencilBufferRequired = static_cast< Integration::StencilBufferAvailable >( environmentOptions->StencilBufferRequired() );
65   mPartialUpdateRequired = static_cast< Integration::PartialUpdateAvailable >( environmentOptions->PartialUpdateRequired() );
66
67   mMultiSamplingLevel = environmentOptions->GetMultiSamplingLevel();
68
69   mEglSync = Utils::MakeUnique< EglSyncImplementation >();
70
71   mEglContextHelper = Utils::MakeUnique< EglContextHelperImplementation >();
72 }
73
74 void EglGraphics::Initialize( bool depth, bool stencil, int msaa )
75 {
76   mDepthBufferRequired = static_cast< Integration::DepthBufferAvailable >( depth );
77   mStencilBufferRequired = static_cast< Integration::StencilBufferAvailable >( stencil );
78
79   mMultiSamplingLevel = msaa;
80
81   mEglSync = Utils::MakeUnique< EglSyncImplementation >();
82
83   mEglContextHelper = Utils::MakeUnique< EglContextHelperImplementation >();
84 }
85
86 EglInterface* EglGraphics::Create()
87 {
88   mEglImplementation = Utils::MakeUnique< EglImplementation >( mMultiSamplingLevel, mDepthBufferRequired, mStencilBufferRequired, mPartialUpdateRequired );
89   mEglImageExtensions = Utils::MakeUnique< EglImageExtensions >( mEglImplementation.get() );
90
91   mEglSync->Initialize( mEglImplementation.get() ); // The sync impl needs the EglDisplay
92
93   mEglContextHelper->Initialize( mEglImplementation.get() ); // The context helper impl needs the EglContext
94
95   return mEglImplementation.get();
96 }
97
98 void EglGraphics::Destroy()
99 {
100 }
101
102 GlImplementation& EglGraphics::GetGlesInterface()
103 {
104   return *mGLES;
105 }
106
107 Integration::GlAbstraction& EglGraphics::GetGlAbstraction() const
108 {
109   DALI_ASSERT_DEBUG( mGLES && "GLImplementation not created" );
110   return *mGLES;
111 }
112
113 EglImplementation& EglGraphics::GetEglImplementation() const
114 {
115   DALI_ASSERT_DEBUG( mEglImplementation && "EGLImplementation not created" );
116   return *mEglImplementation;
117 }
118
119 EglInterface& EglGraphics::GetEglInterface() const
120 {
121   DALI_ASSERT_DEBUG( mEglImplementation && "EGLImplementation not created" );
122   EglInterface* eglInterface = mEglImplementation.get();
123   return *eglInterface;
124 }
125
126 EglSyncImplementation& EglGraphics::GetSyncImplementation()
127 {
128   DALI_ASSERT_DEBUG( mEglSync && "EglSyncImplementation not created" );
129   return *mEglSync;
130 }
131
132 EglContextHelperImplementation& EglGraphics::GetContextHelperImplementation()
133 {
134   DALI_ASSERT_DEBUG( mEglContextHelper && "EglContextHelperImplementation not created" );
135   return *mEglContextHelper;
136 }
137
138 EglImageExtensions* EglGraphics::GetImageExtensions()
139 {
140   DALI_ASSERT_DEBUG( mEglImageExtensions && "EglImageExtensions not created" );
141   return mEglImageExtensions.get();
142 }
143
144 } // Adaptor
145 } // Internal
146 } // Dali