Extract out RenderRequest & common Render functions from RenderThread source files
[platform/core/uifw/dali-adaptor.git] / adaptors / base / render-thread.h
1 #ifndef __DALI_INTERNAL_RENDER_THREAD_H__
2 #define __DALI_INTERNAL_RENDER_THREAD_H__
3
4 /*
5  * Copyright (c) 2015 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 <pthread.h>
23
24 // INTERNAL INCLUDES
25 #include <base/render-helper.h>
26 #include <base/render-request.h>
27 #include <egl-interface.h>
28 #include <render-surface.h> // needed for Dali::RenderSurface
29
30 namespace Dali
31 {
32
33 class RenderSurface;
34
35 namespace Integration
36 {
37 class Core;
38 }
39
40 namespace Internal
41 {
42 namespace Adaptor
43 {
44
45 class AdaptorInternalServices;
46 class ThreadSynchronization;
47 class EnvironmentOptions;
48
49 /**
50  * The render-thread is responsible for calling Core::Render() after each update.
51  */
52 class RenderThread
53 {
54 public:
55
56   /**
57    * Create the render-thread; this will not do anything until Start() is called.
58    * @param[in] sync thread synchronization object
59    * @param[in] adaptorInterfaces base adaptor interface
60    * @param[in] environmentOptions environment options
61    */
62   RenderThread( ThreadSynchronization& sync,
63                 AdaptorInternalServices& adaptorInterfaces,
64                 const EnvironmentOptions& environmentOptions );
65
66   /**
67    * Destructor
68    */
69   ~RenderThread();
70
71 public:
72
73   /**
74    * Starts the render-thread
75    */
76   void Start();
77
78   /**
79    * Stops the render-thread
80    */
81   void Stop();
82
83 private: // Render thread side helpers
84
85   /**
86    * This method is used by the Render thread for rendering the Core to the screen.
87    * Called from render thread
88    * @return true, if the thread finishes properly.
89    */
90   bool Run();
91
92   /**
93    * Check if main thread made any requests, e.g. ReplaceSurface
94    * Called from render thread
95    */
96   void ProcessRequest( RenderRequest* request );
97
98   /**
99    * Helper for the thread calling the entry function.
100    * @param[in] This A pointer to the current RenderThread object
101    */
102   static inline void* InternalThreadEntryFunc( void* This )
103   {
104     ( static_cast<RenderThread*>( This ) )->Run();
105     return NULL;
106   }
107
108 private:
109
110   // Undefined
111   RenderThread( const RenderThread& renderThread );
112
113   // Undefined
114   RenderThread& operator=( const RenderThread& renderThread );
115
116 private: // Data
117
118   ThreadSynchronization&        mThreadSynchronization;  ///< Used to synchronize the all threads
119   Dali::Integration::Core&      mCore;                   ///< Dali core reference
120   pthread_t*                    mThread;                 ///< render thread
121   const EnvironmentOptions&     mEnvironmentOptions;     ///< Environment options
122   RenderHelper                  mRenderHelper;           ///< Helper class for EGL, pre & post rendering
123 };
124
125 } // namespace Adaptor
126
127 } // namespace Internal
128
129 } // namespace Dali
130
131 #endif // __DALI_INTERNAL_RENDER_THREAD_H__