Merge "Add CanvasView thread rasterization" into 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 private: // From Control
67   /**
68    * @copydoc Control::OnRelayout
69    */
70   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
71
72   /**
73    * @copydoc Toolkit::Control::OnSizeSet()
74    */
75   void OnSizeSet(const Vector3& targetSize) override;
76
77   /**
78    * @copydoc Toolkit::Control::OnInitialize
79    */
80   void OnInitialize() override;
81
82   /**
83    * @bried Rasterize the canvas, and add it to the view.
84    *
85    * @param[in] size The target size of the canvas view rasterization.
86    */
87   void AddRasterizationTask();
88
89 protected:
90   /**
91    * @copydoc Dali::Integration::Processor::Process()
92    */
93   void Process(bool postProcessor) override;
94
95 public:
96   /**
97    * @bried Apply the rasterized image to the canvas view
98    *
99    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
100    */
101   void ApplyRasterizedImage(PixelData rasterizedPixelData);
102
103 private:
104   CanvasView(const CanvasView&) = delete;
105   CanvasView& operator=(const CanvasView&) = delete;
106
107 private:
108   CanvasRenderer             mCanvasRenderer;
109   Dali::Texture              mTexture;
110   TextureSet                 mTextureSet;
111   Vector2                    mSize;
112   CanvasViewRasterizeThread* mCanvasViewRasterizeThread;
113 };
114
115 } // namespace Internal
116
117 // Helpers for public-api forwarding methods
118 inline Toolkit::Internal::CanvasView& GetImpl(Toolkit::CanvasView& obj)
119 {
120   DALI_ASSERT_ALWAYS(obj);
121   Dali::RefObject& handle = obj.GetImplementation();
122   return static_cast<Toolkit::Internal::CanvasView&>(handle);
123 }
124
125 inline const Toolkit::Internal::CanvasView& GetImpl(const Toolkit::CanvasView& obj)
126 {
127   DALI_ASSERT_ALWAYS(obj);
128   const Dali::RefObject& handle = obj.GetImplementation();
129   return static_cast<const Toolkit::Internal::CanvasView&>(handle);
130 }
131
132 } // namespace Toolkit
133
134 } // namespace Dali
135
136 #endif // DALI_TOOLKIT_INTERNAL_CANVAS_VIEW_H