[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / canvas-view / canvas-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_CANVAS_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_CANVAS_VIEW_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/devel-api/adaptor-framework/canvas-renderer/canvas-renderer-drawable.h>
23 #include <dali/devel-api/adaptor-framework/canvas-renderer/canvas-renderer-shape.h>
24 #include <dali/devel-api/adaptor-framework/canvas-renderer/canvas-renderer.h>
25 #include <dali/devel-api/rendering/renderer-devel.h>
26 #include <dali/integration-api/processor-interface.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/devel-api/controls/canvas-view/canvas-view.h>
30 #include <dali-toolkit/internal/controls/canvas-view/canvas-view-rasterize-task.h>
31 #include <dali-toolkit/public-api/controls/control-impl.h>
32
33 namespace Dali
34 {
35 namespace Toolkit
36 {
37 namespace Internal
38 {
39 class CanvasView;
40 class CanvasViewRasterizeThread;
41
42 class CanvasView : public Control, public Integration::Processor
43 {
44 public:
45   /**
46    * Construct a new CanvasView.
47    */
48   CanvasView(const Vector2& viewBox);
49
50   /**
51    * A reference counted object may only be deleted by calling Unreference()
52    */
53   virtual ~CanvasView();
54
55 public:
56   /**
57    * Create a new CanvasView.
58    * @return A smart-pointer to the newly allocated CanvasView.
59    */
60   static Toolkit::CanvasView New(const Vector2& viewBox);
61
62   /**
63    * @copydoc Toolkit::Control::CanvasView::AddDrawable
64    */
65   bool AddDrawable(Dali::CanvasRenderer::Drawable& drawable);
66
67   /**
68    * Called when a property of an object of this type is set.
69    * @param[in] object The object whose property is set.
70    * @param[in] propertyIndex The property index.
71    * @param[in] value The new property value.
72    */
73   static void SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value);
74
75   /**
76    * Called to retrieve a property of an object of this type.
77    * @param[in] object The object whose property is to be retrieved.
78    * @param[in] propertyIndex The property index.
79    * @return The current value of the property.
80    */
81   static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
82
83   /**
84    * @copydoc Toolkit::Control::CanvasView::RemoveDrawable
85    */
86   bool RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable);
87
88   /**
89    * @copydoc Toolkit::Control::CanvasView::RemoveAllDrawables
90    */
91   bool RemoveAllDrawables();
92
93 private: // From Control
94   /**
95    * @copydoc Control::OnRelayout
96    */
97   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
98
99   /**
100    * @copydoc Toolkit::Control::OnSizeSet()
101    */
102   void OnSizeSet(const Vector3& targetSize) override;
103
104   /**
105    * @copydoc Toolkit::Control::OnInitialize
106    */
107   void OnInitialize() override;
108
109   /**
110    * @brief This is the viewbox of the Canvas.
111    * @param[in] viewBox The size of viewbox.
112    * @return Returns True when it's successful. False otherwise.
113    */
114   bool SetViewBox(const Vector2& viewBox);
115
116   /**
117    * @brief This is the viewbox of the Canvas.
118    * @return Returns The size of viewbox.
119    */
120   const Vector2& GetViewBox();
121
122   /**
123    * @brief Set to load the canvas synchronously.
124    *
125    * @param isSynchronous The synchronous
126    */
127   void SetSynchronous(const bool isSynchronous);
128
129   /**
130    * @brief Whether to load the canvas synchronously.
131    *
132    * @return Returns true if synchronously.
133    */
134   const bool IsSynchronous();
135
136   /**
137    * @bried Rasterize the canvas, and add it to the view.
138    *
139    * @param[in] size The target size of the canvas view rasterization.
140    */
141   void AddRasterizationTask();
142
143 protected:
144   /**
145    * @copydoc Dali::Integration::Processor::Process()
146    */
147   void Process(bool postProcessor) override;
148
149   /**
150    * @copydoc Dali::Integration::Processor::GetProcessorName()
151    */
152   std::string_view GetProcessorName() const override
153   {
154     return "CanvasView";
155   }
156
157 public:
158   /**
159    * @bried Apply the rasterized image to the canvas view
160    *
161    * @param[in] task CanvasRendererRasterizingTaskPtr
162    */
163   void ApplyRasterizedImage(CanvasRendererRasterizingTaskPtr task);
164
165 private:
166   CanvasView(const CanvasView&) = delete;
167   CanvasView& operator=(const CanvasView&) = delete;
168
169 private:
170   CanvasRenderer                   mCanvasRenderer;
171   Dali::Texture                    mTexture;
172   TextureSet                       mTextureSet;
173   Vector2                          mSize;
174   CanvasRendererRasterizingTaskPtr mRasterizingTask;
175   bool                             mIsSynchronous;
176 };
177
178 } // namespace Internal
179
180 // Helpers for public-api forwarding methods
181 inline Toolkit::Internal::CanvasView& GetImpl(Toolkit::CanvasView& obj)
182 {
183   DALI_ASSERT_ALWAYS(obj);
184   Dali::RefObject& handle = obj.GetImplementation();
185   return static_cast<Toolkit::Internal::CanvasView&>(handle);
186 }
187
188 inline const Toolkit::Internal::CanvasView& GetImpl(const Toolkit::CanvasView& obj)
189 {
190   DALI_ASSERT_ALWAYS(obj);
191   const Dali::RefObject& handle = obj.GetImplementation();
192   return static_cast<const Toolkit::Internal::CanvasView&>(handle);
193 }
194
195 } // namespace Toolkit
196
197 } // namespace Dali
198
199 #endif // DALI_TOOLKIT_INTERNAL_CANVAS_VIEW_H