[dali_2.3.25] Merge branch 'devel/master'
[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) 2023 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    * @copydoc Dali::OffscreenWindow::SetFrameRenderedCallback
91    */
92   void SetFrameRenderedCallback(CallbackBase* callback);
93
94   /*
95    * @brief Initialize the OffscreenWindow
96    * @param[in] isDefaultWindow Whether the OffscreenWindow is a default one or not
97    */
98   void Initialize(bool isDefaultWindow);
99
100 private:
101   /**
102    * This function is called after drawing by dali.
103    */
104   void OnPostRender();
105
106   /**
107    * @brief Get the native render surface
108    * @return The render surface
109    */
110   NativeRenderSurface* GetNativeRenderSurface() const;
111
112 private:
113   /**
114    * Private constructor
115    *
116    * @param[in] width The initial width of the OffscreenWindow
117    * @param[in] height The initial height of the OffscreenWindow
118    * @param[in] surface The native surface handle
119    * @param[in] isTranslucent Whether the OffscreenWindow is translucent or not
120    */
121   OffscreenWindow(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent);
122
123   // Undefined
124   OffscreenWindow(const OffscreenWindow&);
125   OffscreenWindow& operator=(OffscreenWindow&);
126
127 private:
128   std::unique_ptr<TriggerEventInterface> mRenderNotification;
129   std::unique_ptr<CallbackBase>          mPostRenderCallback;
130 };
131
132 inline OffscreenWindow& GetImplementation(Dali::OffscreenWindow& offscreenWindow)
133 {
134   DALI_ASSERT_ALWAYS(offscreenWindow && "Dali::OffscreenWindow handle is empty");
135
136   BaseObject& handle = offscreenWindow.GetBaseObject();
137
138   return static_cast<OffscreenWindow&>(handle);
139 }
140
141 inline const OffscreenWindow& GetImplementation(const Dali::OffscreenWindow& offscreenWindow)
142 {
143   DALI_ASSERT_ALWAYS(offscreenWindow && "Dali::OffscreenWindow handle is empty");
144
145   const BaseObject& handle = offscreenWindow.GetBaseObject();
146
147   return static_cast<const OffscreenWindow&>(handle);
148 }
149
150 } // namespace Internal
151
152 } // namespace Dali
153
154 #endif // DALI_INTERNAL_OFFSCREEN_WINDOW_IMPL_H