8b1a0bf33dc39da3ed8f705c97dfcef0650fe842
[platform/core/uifw/dali-adaptor.git] / adaptors / integration-api / x11 / ecore-x-render-surface.h
1 #ifndef __DALI_ECORE_X_RENDER_SURFACE_H__
2 #define __DALI_ECORE_X_RENDER_SURFACE_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <Ecore_X.h>
23 #include <dali/public-api/common/dali-common.h>
24
25 // INTERNAL INCLUDES
26 #include <render-surface.h>
27 #include <ecore-x-types.h>
28 #include <egl-interface.h>
29
30 namespace Dali
31 {
32
33 class TriggerEventInterface;
34
35 namespace ECore
36 {
37
38 /**
39  * Ecore X11 implementation of render surface.
40  * @todo change namespace to ECore_X11 as the class
41  * is no longer pure X11.
42  */
43 class DALI_IMPORT_API EcoreXRenderSurface : public Dali::RenderSurface
44 {
45 public:
46   /**
47     * Uses an X11 surface to render to.
48     * @param [in] positionSize the position and size of the surface
49     * @param [in] surface can be a X-window or X-pixmap (type must be unsigned int).
50     * @param [in] name optional name of surface passed in
51     * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
52     */
53   EcoreXRenderSurface(Dali::PositionSize positionSize,
54                       Any surface,
55                       const std::string& name,
56                       bool isTransparent = false);
57
58   /**
59    * Destructor.
60    * Will delete the display, if it has ownership.
61    * Will delete the window/pixmap if it has owner ship
62    */
63   virtual ~EcoreXRenderSurface();
64
65 protected:
66   /**
67    * Second stage construction
68    * Creates the surface (window, pixmap or native buffer)
69    */
70   void Init( Any surface );
71
72 public: // API
73
74   /**
75    * @brief Sets the render notification trigger to call when render thread is completed a frame
76    *
77    * @param renderNotification to use
78    */
79   void SetRenderNotification(TriggerEventInterface* renderNotification);
80
81   /**
82    * @brief Get window handle
83    *
84    * @return the Ecore X window handle
85    */
86   Ecore_X_Window GetXWindow();
87
88   /**
89    * Get the surface as an Ecore_X_drawable
90    */
91   virtual Ecore_X_Drawable GetDrawable();
92
93   /**
94    * @brief Get the render surface the adaptor is using to render to.
95    *
96    * @return reference to current render surface (eg, pixmap / window)
97    */
98   virtual Any GetSurface() = 0;
99
100 public: // from Dali::RenderSurface
101
102   /**
103    * @copydoc Dali::RenderSurface::GetPositionSize()
104    */
105   virtual PositionSize GetPositionSize() const;
106
107   /**
108    * @copydoc Dali::RenderSurface::InitializeEgl()
109    */
110   virtual void InitializeEgl( EglInterface& egl ) = 0;
111
112   /**
113    * @copydoc Dali::RenderSurface::CreateEglSurface()
114    */
115   virtual void CreateEglSurface( EglInterface& egl ) = 0;
116
117   /**
118    * @copydoc Dali::RenderSurface::DestroyEglSurface()
119    */
120   virtual void DestroyEglSurface( EglInterface& egl ) = 0;
121
122   /**
123    * @copydoc Dali::RenderSurface::ReplaceEGLSurface()
124    */
125   virtual bool ReplaceEGLSurface( EglInterface& egl ) = 0;
126
127   /**
128    * @copydoc Dali::RenderSurface::MoveResize()
129    */
130   virtual void MoveResize( Dali::PositionSize positionSize);
131
132   /**
133    * @copydoc Dali::RenderSurface::SetViewMode()
134    */
135   void SetViewMode( ViewMode viewMode );
136
137   /**
138    * @copydoc Dali::RenderSurface::StartRender()
139    */
140   virtual void StartRender() = 0;
141
142   /**
143    * @copydoc Dali::RenderSurface::PreRender()
144    */
145   virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, bool resizingSurface ) = 0;
146
147   /**
148    * @copydoc Dali::RenderSurface::PostRender()
149    */
150   virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface ) = 0;
151
152   /**
153    * @copydoc Dali::RenderSurface::ReleaseLock()
154    */
155   virtual void ReleaseLock() = 0;
156
157   /**
158    * @copydoc Dali::RenderSurface::GetSurfaceType()
159    */
160   virtual RenderSurface::Type GetSurfaceType();
161
162 private:
163
164   /**
165    * Get the surface id if the surface parameter is not empty
166    * @param surface Any containing a surface id, or can be empty
167    * @return surface id, or zero if surface is empty
168    */
169   unsigned int GetSurfaceId( Any surface ) const;
170
171 protected:
172
173   /**
174    * Create XRenderable
175    */
176   virtual void CreateXRenderable() = 0;
177
178   /**
179    * Use an existing render surface
180    * @param surfaceId the id of the surface
181    */
182   virtual void UseExistingRenderable( unsigned int surfaceId ) = 0;
183
184 protected: // Data
185
186   PositionSize                mPosition;               ///< Position
187   std::string                 mTitle;                  ///< Title of window which shows from "xinfo -topvwins" command
188   TriggerEventInterface*      mRenderNotification;     ///< Render notification trigger
189   ColorDepth                  mColorDepth;             ///< Color depth of surface (32 bit or 24 bit)
190   bool                        mOwnSurface;             ///< Whether we own the surface (responsible for deleting it)
191 };
192
193 } // namespace ECore
194
195 } // namespace Dali
196
197 #endif // __DALI_ECORE_X_RENDER_SURFACE_H__