CanvasView: Add RemoveDrawable() API
[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 private: // From Control
88   /**
89    * @copydoc Control::OnRelayout
90    */
91   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
92
93   /**
94    * @copydoc Toolkit::Control::OnSizeSet()
95    */
96   void OnSizeSet(const Vector3& targetSize) override;
97
98   /**
99    * @copydoc Toolkit::Control::OnInitialize
100    */
101   void OnInitialize() override;
102
103   /**
104    * @brief This is the viewbox of the Canvas.
105    * @param[in] viewBox The size of viewbox.
106    * @return Returns True when it's successful. False otherwise.
107    */
108   bool SetViewBox(const Vector2& viewBox);
109
110   /**
111    * @brief This is the viewbox of the Canvas.
112    * @return Returns The size of viewbox.
113    */
114   const Vector2& GetViewBox();
115
116   /**
117    * @bried Rasterize the canvas, and add it to the view.
118    *
119    * @param[in] size The target size of the canvas view rasterization.
120    */
121   void AddRasterizationTask();
122
123 protected:
124   /**
125    * @copydoc Dali::Integration::Processor::Process()
126    */
127   void Process(bool postProcessor) override;
128
129 public:
130   /**
131    * @bried Apply the rasterized image to the canvas view
132    *
133    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
134    */
135   void ApplyRasterizedImage(PixelData rasterizedPixelData);
136
137 private:
138   CanvasView(const CanvasView&) = delete;
139   CanvasView& operator=(const CanvasView&) = delete;
140
141 private:
142   CanvasRenderer             mCanvasRenderer;
143   Dali::Texture              mTexture;
144   TextureSet                 mTextureSet;
145   Vector2                    mSize;
146   CanvasViewRasterizeThread* mCanvasViewRasterizeThread;
147 };
148
149 } // namespace Internal
150
151 // Helpers for public-api forwarding methods
152 inline Toolkit::Internal::CanvasView& GetImpl(Toolkit::CanvasView& obj)
153 {
154   DALI_ASSERT_ALWAYS(obj);
155   Dali::RefObject& handle = obj.GetImplementation();
156   return static_cast<Toolkit::Internal::CanvasView&>(handle);
157 }
158
159 inline const Toolkit::Internal::CanvasView& GetImpl(const Toolkit::CanvasView& obj)
160 {
161   DALI_ASSERT_ALWAYS(obj);
162   const Dali::RefObject& handle = obj.GetImplementation();
163   return static_cast<const Toolkit::Internal::CanvasView&>(handle);
164 }
165
166 } // namespace Toolkit
167
168 } // namespace Dali
169
170 #endif // DALI_TOOLKIT_INTERNAL_CANVAS_VIEW_H