Merge "Fixed Svace Issue" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / render-surface / render-surface-wl.cpp
1 /*
2  * Copyright (c) 2015 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 // CLASS HEADER
19 #include "render-surface-wl.h"
20
21 // EXTERNAL INCLUDES
22 #include <stdio.h>
23 #include <dali/integration-api/gl-abstraction.h>
24 #include <dali/integration-api/debug.h>
25 #include <cstring>
26 #include <unistd.h>
27
28 // INTERNAL INCLUDES
29 #include <base/separate-update-render/thread-synchronization.h>
30 #include <gl/egl-implementation.h>
31 #include <trigger-event.h>
32 #include <base/interfaces/window-event-interface.h>
33 #include <wayland-manager.h>
34
35
36 namespace Dali
37 {
38
39 namespace Wayland
40 {
41
42 RenderSurface::RenderSurface(Dali::PositionSize positionSize,
43                                            Any surface,
44                                            const std::string& name,
45                                            bool isTransparent)
46 : mRenderNotification(NULL),
47   mColorDepth(isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24),
48   mEglWindow(NULL)
49 {
50   mWindow.mPosition = positionSize;
51   mWindow.mTitle = name;
52   mWaylandManager = new  Dali::Internal::Adaptor::WaylandManager;
53   mWaylandManager->Initialise();
54 }
55
56 RenderSurface::~RenderSurface()
57 {
58   delete mWaylandManager;
59 }
60
61 void RenderSurface::CreateSurface()
62 {
63   mWaylandManager->CreateSurface( mWindow );
64 }
65
66 Window* RenderSurface::GetWindow()
67 {
68   return &mWindow;
69 }
70
71
72 void RenderSurface::AssignWindowEventInterface( Dali::Internal::Adaptor::WindowEventInterface* eventInterface)
73 {
74   mWaylandManager->AssignWindowEventInterface( eventInterface );
75 }
76
77 PositionSize RenderSurface::GetPositionSize() const
78 {
79   return mWindow.mPosition;
80 }
81
82 void RenderSurface::InitializeEgl( EglInterface& egl )
83 {
84   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
85
86   if (!eglImpl.InitializeGles(static_cast<EGLNativeDisplayType>( mWaylandManager->mDisplay )))
87   {
88     DALI_LOG_ERROR("Failed to initialize GLES.\n");
89   }
90
91   eglImpl.ChooseConfig( true, mColorDepth );
92 }
93
94 void RenderSurface::CreateEglSurface( EglInterface& egl )
95 {
96   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
97
98   CreateSurface();
99
100   mEglWindow = wl_egl_window_create( mWaylandManager->GetSurface(), mWindow.mPosition.width, mWindow.mPosition.height);
101
102   eglImpl.CreateSurfaceWindow( (EGLNativeWindowType)mEglWindow, mColorDepth ); // reinterpret_cast does not compile
103
104 }
105
106 void RenderSurface::DestroyEglSurface( EglInterface& eglIf )
107 {
108   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
109   eglImpl.DestroySurface();
110   wl_egl_window_destroy( mEglWindow );
111   mEglWindow = NULL;
112 }
113
114 bool RenderSurface::ReplaceEGLSurface( EglInterface& egl )
115 {
116   return true;
117 }
118
119 void RenderSurface::MoveResize( Dali::PositionSize positionSize )
120 {
121 }
122
123 void RenderSurface::SetViewMode( ViewMode viewMode )
124 {
125 }
126
127 void RenderSurface::StartRender()
128 {
129 }
130
131 bool RenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& )
132 {
133   return true;
134 }
135
136 void RenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface )
137 {
138   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
139   eglImpl.SwapBuffers();
140 }
141
142 void RenderSurface::StopRender()
143 {
144 }
145
146 void RenderSurface::ReleaseLock()
147 {
148 }
149 void RenderSurface::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
150 {
151 }
152
153 RenderSurface::Type RenderSurface::GetSurfaceType()
154 {
155   return RenderSurface::WAYLAND_RENDER_SURFACE;
156 }
157
158 } // namespace Wayland
159
160 } // namespace Dali