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