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