[dali_2.1.30] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / gl-view / drawable-view-native-renderer.h
1 #ifndef DALI_PROJECT_DRAWABLE_VIEW_NATIVE_RENDERER_H
2 #define DALI_PROJECT_DRAWABLE_VIEW_NATIVE_RENDERER_H
3
4 /*
5 * Copyright (c) 2021 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 #include <dali/public-api/signals/callback.h>
22 #include <dali/public-api/signals/render-callback.h>
23 #include <memory>
24
25
26 namespace Dali::Internal
27 {
28 /**
29  * The structure containing the initialization data for the
30  * DrawableViewNativeRenderer instance.
31  */
32 struct NativeRendererCreateInfo
33 {
34   /**
35    * Presentation mode is used only for threaded renderer
36    */
37   enum class PresentationMode
38   {
39     FIFO, // First-in first-out
40     MAILBOX // Only most recent out
41   };
42
43   bool threadEnabled { false };
44   uint32_t maxOffscreenBuffers { 3u };
45   PresentationMode presentationMode {PresentationMode::FIFO};
46 };
47
48 /**
49  * The DrawableViewNativeRenderer is responsible for delegating rendering
50  * either to the own thread (in parallel mode) or calling the GlView render callbacks
51  * directly.
52  *
53  * The parallel mode creates the thread that invokes GLView callbacks directly.
54  * The actual render callback will only pass the input data and blit the result.
55  *
56  * Parallel mode renders always to the offscreen framebuffer.
57  */
58 class DrawableViewNativeRenderer
59 {
60 public:
61   explicit DrawableViewNativeRenderer( const NativeRendererCreateInfo& createInfo );
62   ~DrawableViewNativeRenderer();
63
64   /**
65    * Registers GlView callbacks
66    */
67   void RegisterGlCallbacks( Dali::CallbackBase* onInitCallback,Dali::CallbackBase* onRenderCallback, Dali::CallbackBase* onTerminateCallback );
68
69   /**
70    * Dispatches the GlView init callback
71    * @param renderCallbackInput
72    */
73   void InvokeGlInitCallback( const RenderCallbackInput& renderCallbackInput );
74
75   /**
76    * Dispatches the GlView render callback
77    * @param renderCallbackInput
78    */
79   void InvokeGlRenderCallback(  const RenderCallbackInput& renderCallbackInput  );
80
81   /**
82    * Dispatches the GlView terminate callback
83    * @param[in] renderCallbackInput
84    */
85   void InvokeGlTerminateCallback(  const RenderCallbackInput& renderCallbackInput );
86
87   /**
88    * @brief Resizes the render surface
89    *
90    * @param[in] width Width of surface
91    * @param[in] height Height of surface
92    */
93   void Resize( uint32_t width, uint32_t height );
94
95   /**
96    * @brief Pushes render callback input data into the native renderer thread
97    *
98    * @param[in] renderCallbackInput Valid RenderCallbackInput object
99    */
100   void PushRenderCallbackInputData( const Dali::RenderCallbackInput& renderCallbackInput );
101
102   /**
103    * @brief Terminates thread in parallel mode
104    */
105   void Terminate();
106
107 private:
108
109   struct Impl;
110   std::unique_ptr<Impl> mImpl;
111 };
112 }
113
114 #endif // DALI_PROJECT_DRAWABLE_VIEW_NATIVE_RENDERER_H