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