f8323ea05e6f3d6e35bb215bb815a480b45aaf1f
[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 {
49   mWindow.mPosition = positionSize;
50   mWindow.mTitle = name;
51   mWaylandManager = new  Dali::Internal::Adaptor::WaylandManager;
52   mWaylandManager->Initialise();
53 }
54
55 RenderSurface::~RenderSurface()
56 {
57   delete mWaylandManager;
58 }
59
60 void RenderSurface::CreateSurface()
61 {
62   mWaylandManager->CreateSurface( mWindow );
63 }
64
65 Window* RenderSurface::GetWindow()
66 {
67   return &mWindow;
68 }
69
70
71 void RenderSurface::AssignWindowEventInterface( Dali::Internal::Adaptor::WindowEventInterface* eventInterface)
72 {
73   mWaylandManager->AssignWindowEventInterface( eventInterface );
74 }
75
76 PositionSize RenderSurface::GetPositionSize() const
77 {
78   return mWindow.mPosition;
79 }
80
81 void RenderSurface::InitializeEgl( EglInterface& egl )
82 {
83   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
84
85   if (!eglImpl.InitializeGles(static_cast<EGLNativeDisplayType>( mWaylandManager->mDisplay )))
86   {
87     DALI_LOG_ERROR("Failed to initialize GLES.\n");
88   }
89
90   eglImpl.ChooseConfig( true, mColorDepth );
91 }
92
93 void RenderSurface::CreateEglSurface( EglInterface& egl )
94 {
95   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
96
97   CreateSurface();
98
99   mEglWindow = wl_egl_window_create( mWaylandManager->GetSurface(), mWindow.mPosition.width, mWindow.mPosition.height);
100
101   eglImpl.CreateSurfaceWindow( (EGLNativeWindowType)mEglWindow, mColorDepth ); // reinterpret_cast does not compile
102
103 }
104
105 void RenderSurface::DestroyEglSurface( EglInterface& eglIf )
106 {
107   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
108   eglImpl.DestroySurface();
109   wl_egl_window_destroy( mEglWindow );
110   mEglWindow = NULL;
111 }
112
113 bool RenderSurface::ReplaceEGLSurface( EglInterface& egl )
114 {
115   return true;
116 }
117
118 void RenderSurface::MoveResize( Dali::PositionSize positionSize )
119 {
120 }
121
122 void RenderSurface::SetViewMode( ViewMode viewMode )
123 {
124 }
125
126 void RenderSurface::StartRender()
127 {
128 }
129
130 bool RenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& )
131 {
132   return true;
133 }
134
135 void RenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface )
136 {
137   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
138   eglImpl.SwapBuffers();
139 }
140
141 void RenderSurface::StopRender()
142 {
143 }
144
145 void RenderSurface::ReleaseLock()
146 {
147 }
148 void RenderSurface::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
149 {
150 }
151
152 RenderSurface::Type RenderSurface::GetSurfaceType()
153 {
154   return RenderSurface::WAYLAND_RENDER_SURFACE;
155 }
156
157 } // namespace Wayland
158
159 } // namespace Dali