[Tizen] ecore-wl2: applying ecore-wl2
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl / render-surface-ecore-wl.cpp
1 /*
2  * Copyright (c) 2017 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 <dali/integration-api/wayland/ecore-wl/ecore-wl-render-surface.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/integration-api/wayland/wl-types.h>
27 #include <dali/internal/system/common/trigger-event.h>
28 #include <dali/internal/graphics/gles20/egl-implementation.h>
29
30 namespace Dali
31 {
32
33 #if defined(DEBUG_ENABLED)
34 Debug::Filter* gRenderSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_ECORE_WL_RENDER_SURFACE");
35 #endif
36
37 namespace ECore
38 {
39
40 EcoreWlRenderSurface::EcoreWlRenderSurface(Dali::PositionSize positionSize,
41                                            Any surface,
42                                            const std::string& name,
43                                            bool isTransparent)
44 : mPositionSize( positionSize ),
45   mTitle( name ),
46   mRenderNotification( NULL ),
47   mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
48   mOwnSurface( false )
49 {
50 }
51
52 void EcoreWlRenderSurface::Init( Any surface )
53 {
54   // see if there is a surface in Any surface
55   unsigned int surfaceId  = GetSurfaceId( surface );
56
57   // if the surface is empty, create a new one.
58   if ( surfaceId == 0 )
59   {
60     // we own the surface about to created
61     ecore_wl_init(NULL);
62     mOwnSurface = true;
63     CreateWlRenderable();
64   }
65   else
66   {
67     // XLib should already be initialized so no point in calling XInitThreads
68     UseExistingRenderable( surfaceId );
69   }
70
71 #ifdef DEBUG_ENABLED
72   // prints out 'INFO: DALI: new EcoreWlRenderSurface, created display xx, used existing surface xx
73   // we can not use LOG_INFO because the surface can be created before Dali Core is created.
74   // TODO: Overy tizen 3.0, we don't use X anymore. Change this for Tizen 3.0
75   /*
76   printf( "INFO: DALI: new EcoreWlRenderSurface, %s %s surface %X \n",
77           mOwnSurface?"created":"used existing",
78           Dali::RenderSurface::PIXMAP==mType?" pixmap" :"window",
79           AnyCast<Ecore_X_Drawable>( GetSurface() ) );
80   */
81 #endif
82 }
83
84 EcoreWlRenderSurface::~EcoreWlRenderSurface()
85 {
86   if( mOwnSurface )
87   {
88     ecore_wl_shutdown();
89   }
90 }
91
92 void EcoreWlRenderSurface::SetRenderNotification(TriggerEventInterface* renderNotification)
93 {
94   mRenderNotification = renderNotification;
95 }
96
97 Ecore_Wl_Window* EcoreWlRenderSurface::GetWlWindow()
98 {
99   return 0;
100 }
101
102 Ecore_Wl_Window* EcoreWlRenderSurface::GetDrawable()
103 {
104   return 0;
105 }
106
107 PositionSize EcoreWlRenderSurface::GetPositionSize() const
108 {
109   return mPositionSize;
110 }
111
112 void EcoreWlRenderSurface::MoveResize( Dali::PositionSize positionSize )
113 {
114   // nothing to do in base class
115 }
116
117 void EcoreWlRenderSurface::SetViewMode( ViewMode viewMode )
118 {
119 }
120
121 unsigned int EcoreWlRenderSurface::GetSurfaceId( Any surface ) const
122 {
123   unsigned int surfaceId = 0;
124
125   if ( surface.Empty() == false )
126   {
127     // check we have a valid type
128     DALI_ASSERT_ALWAYS( ( (surface.GetType() == typeid (Ecore_Wl_Window *) ) )
129                         && "Surface type is invalid" );
130
131     surfaceId = AnyCast<unsigned int>( surface );
132   }
133   return surfaceId;
134 }
135
136 RenderSurface::Type EcoreWlRenderSurface::GetSurfaceType()
137 {
138   return RenderSurface::ECORE_RENDER_SURFACE;
139 }
140
141 } // namespace ECore
142
143 } // namespace Dali