e45cf49155eb057677c5fa1967c7a8fdc95f2539
[platform/core/uifw/dali-adaptor.git] / dali / internal / offscreen / common / offscreen-window-impl.h
1 #ifndef DALI_INTERNAL_OFFSCREEN_WINDOW_IMPL_H
2 #define DALI_INTERNAL_OFFSCREEN_WINDOW_IMPL_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <memory>
24
25 // INTERNAL INCLUDES
26 #include <dali/devel-api/adaptor-framework/offscreen-window.h>
27 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
28
29 namespace Dali
30 {
31 class Adaptor;
32 class Layer;
33 class NativeRenderSurface;
34 class TriggerEventInterface;
35
36 namespace Internal
37 {
38 /**
39  * Implementation of the OffscreenWindow class.
40  */
41 class OffscreenWindow : public Dali::Internal::Adaptor::SceneHolder
42 {
43 public:
44   using WindowSize = Dali::OffscreenWindow::WindowSize;
45
46   /**
47    * @brief Create a new OffscreenWindow
48    *
49    * @param[in] width The initial width of the OffscreenWindow
50    * @param[in] height The initial height of the OffscreenWindow
51    * @param[in] surface The native surface handle of your platform
52    * @param[in] isTranslucent Whether the OffscreenWindow is translucent or not
53    */
54   static OffscreenWindow* New(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent);
55
56   OffscreenWindow() = default;
57
58 public:
59   /**
60    * Destructor
61    */
62   ~OffscreenWindow();
63
64   /**
65    * @copydoc Dali::OffscreenWindow::GetLayerCount
66    */
67   uint32_t GetLayerCount() const;
68
69   /**
70    * @copydoc Dali::OffscreenWindow::GetLayer
71    */
72   Dali::Layer GetLayer(uint32_t depth) const;
73
74   /**
75    * @copydoc Dali::OffscreenWindow::GetSize
76    */
77   WindowSize GetSize() const;
78
79   /**
80    * @copydoc Dali::OffscreenWindow::GetNativeHandle
81    */
82   Any GetNativeHandle() const override;
83
84   /**
85    * @copydoc Dali::OffscreenWindow::SetPostRenderCallback
86    */
87   void SetPostRenderCallback(CallbackBase* callback);
88
89   /*
90    * @brief Initialize the OffscreenWindow
91    * @param[in] isDefaultWindow Whether the OffscreenWindow is a default one or not
92    */
93   void Initialize(bool isDefaultWindow);
94
95 private:
96   /**
97    * This function is called after drawing by dali.
98    */
99   void OnPostRender();
100
101   /**
102    * @brief Get the native render surface
103    * @return The render surface
104    */
105   NativeRenderSurface* GetNativeRenderSurface() const;
106
107 private:
108   /**
109    * Private constructor
110    *
111    * @param[in] width The initial width of the OffscreenWindow
112    * @param[in] height The initial height of the OffscreenWindow
113    * @param[in] surface The native surface handle
114    * @param[in] isTranslucent Whether the OffscreenWindow is translucent or not
115    */
116   OffscreenWindow(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent);
117
118   // Undefined
119   OffscreenWindow(const OffscreenWindow&);
120   OffscreenWindow& operator=(OffscreenWindow&);
121
122 private:
123   std::unique_ptr<TriggerEventInterface> mRenderNotification;
124   std::unique_ptr<CallbackBase>          mPostRenderCallback;
125 };
126
127 inline OffscreenWindow& GetImplementation(Dali::OffscreenWindow& offscreenWindow)
128 {
129   DALI_ASSERT_ALWAYS(offscreenWindow && "Dali::OffscreenWindow handle is empty");
130
131   BaseObject& handle = offscreenWindow.GetBaseObject();
132
133   return static_cast<OffscreenWindow&>(handle);
134 }
135
136 inline const OffscreenWindow& GetImplementation(const Dali::OffscreenWindow& offscreenWindow)
137 {
138   DALI_ASSERT_ALWAYS(offscreenWindow && "Dali::OffscreenWindow handle is empty");
139
140   const BaseObject& handle = offscreenWindow.GetBaseObject();
141
142   return static_cast<const OffscreenWindow&>(handle);
143 }
144
145 } // namespace Internal
146
147 } // namespace Dali
148
149 #endif // DALI_INTERNAL_OFFSCREEN_WINDOW_IMPL_H