[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-item.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_ITEM_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_ITEM_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 // INTERNAL INCLUDES
22
23 #include <dali/internal/render/common/render-item-key.h>
24 #include <dali/internal/update/nodes/node.h>
25 #include <dali/public-api/actors/layer.h>
26 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali/public-api/math/matrix.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace Render
34 {
35 class Renderer;
36 }
37
38 namespace SceneGraph
39 {
40 /**
41  * A RenderItem contains all the data needed for rendering
42  */
43 struct RenderItem
44 {
45   /**
46    * Construct a new RenderItem
47    * @return A pointer to a new RenderItem.
48    */
49   static RenderItem* New();
50
51   /**
52    * Construct a new RenderItem
53    * @return A key to a new RenderItem
54    */
55   static RenderItemKey NewKey();
56
57   /**
58    * Non-virtual destructor; RenderItem is not suitable as a base class.
59    */
60   ~RenderItem();
61
62   /**
63    * Get a pointer to the given object in the associated memory pool.
64    * @param[in] key A key to the memory pool object
65    * @return a ptr to the given object, or nullptr if not found/invalid
66    */
67   static RenderItem* Get(RenderItemKey::KeyType key);
68
69   /**
70    * Get the key of the given renderer in the associated memory pool.
71    * @param[in] renderer the given renderer
72    * @return The key in the associated memory pool.
73    */
74   static RenderItemKey GetKey(const RenderItem& renderer);
75
76   /**
77    * Get the key of the given renderer in the associated memory pool.
78    * @param[in] renderer the given renderer
79    * @return The key in the associated memory pool, or -1 if not
80    * found.
81    */
82   static RenderItemKey GetKey(RenderItem* renderer);
83
84   /**
85    * Produce a 2D AABB in transformed space
86    * See below for caveats.
87    *
88    * @param[in]    transformMatrix   The matrix for converting to a different space
89    * @param[in]    position          The center position of the render item
90    * @param[in]    size              The size of the render item
91    */
92   static ClippingBox CalculateTransformSpaceAABB(const Matrix& transformMatrix, const Vector3& position, const Vector3& size);
93
94   /**
95    * @brief This method is an optimized calculation of a viewport-space AABB (Axis-Aligned-Bounding-Box).
96    *
97    * We use the model-view-matrix, but we do not use projection. Therefore we assume Z = 0.
98    * As the box is Axis-Aligned (in viewport space) rotations on Z axis are correctly delt with by expanding the box as necessary.
99    * Rotations on X & Y axis will resize the AABB, but it will not handle the projection error due to the new coordinates having non-zero Z values.
100    *
101    * Note: We pass in the viewport dimensions rather than allow the caller to modify the raw AABB in order to optimally generate the final result.
102    *
103    * Note: ASSUMES THAT THE VIEWPORT COVERS THE SCREEN AND THAT THE CANVAS SIZE AND VIEWPORT SIZE ARE THE SAME!!!!!  (Not the case for magnifier)
104    *
105    * @param[in]    modelViewMatrix   The model view matrix
106    * @param[in]    position          The center position of the render item
107    * @param[in]    size              The size of the render item
108    * @param[in]    viewportWidth     The width of the viewport to calculate for
109    * @param[in]    viewportHeight    The height of the viewport to calculate for
110    * @return                         The AABB coordinates in viewport-space (x, y, width, height)
111    */
112   static ClippingBox CalculateViewportSpaceAABB(const Matrix& modelViewMatrix, const Vector3& position, const Vector3& size, const int viewportWidth, const int viewportHeight);
113
114   /**
115    * Overriden delete operator.
116    * Deletes the RenderItem from its global memory pool
117    * @param[in] A pointer to the RenderItem to delete.
118    */
119   void operator delete(void* ptr);
120
121   Matrix              mModelMatrix;
122   Matrix              mModelViewMatrix;
123   Vector3             mScale;
124   Vector3             mSize;
125   Vector4             mUpdateArea; ///< Update area hint is provided for damaged area calculation. (x, y, width, height)
126   Render::RendererKey mRenderer;
127   Node*               mNode;
128   const void*         mTextureSet; ///< Used for sorting only
129   int                 mDepthIndex;
130   bool                mIsOpaque : 1;
131   bool                mIsUpdated : 1;
132
133   /**
134    * Get the capacity of the global pool.
135    */
136   static uint32_t GetMemoryPoolCapacity();
137
138 private:
139   /**
140    * Private constructor. See RenderItem::New
141    */
142   RenderItem();
143
144   // RenderItems should not be copied as they are heavy
145   RenderItem(const RenderItem& item) = delete;
146   RenderItem& operator=(const RenderItem& item) = delete;
147 };
148
149 } // namespace SceneGraph
150
151 } // namespace Internal
152
153 } // namespace Dali
154
155 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_ITEM_H