Fixing culling for magnifier use case
[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) 2022 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 #include <dali/internal/update/nodes/node.h>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/math/matrix.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace Render
32 {
33 class Renderer;
34 }
35
36 namespace SceneGraph
37 {
38 /**
39  * A RenderItem contains all the data needed for rendering
40  */
41 struct RenderItem
42 {
43   /**
44    * Construct a new RenderItem
45    * @return A pointer to a new RenderItem.
46    */
47   static RenderItem* New();
48
49   /**
50    * Non-virtual destructor; RenderItem is not suitable as a base class.
51    */
52   ~RenderItem();
53
54   /**
55    * Produce a 2D AABB in transformed space
56    * See below for caveats.
57    *
58    * @param[in]    transformMatrix   The matrix for converting to a different space
59    * @param[in]    size              The size of the render item
60    */
61   static ClippingBox CalculateTransformSpaceAABB(const Matrix& transformMatrix, const Vector3& size);
62
63   /**
64    * @brief This method is an optimized calculation of a viewport-space AABB (Axis-Aligned-Bounding-Box).
65    *
66    * We use the model-view-matrix, but we do not use projection. Therefore we assume Z = 0.
67    * As the box is Axis-Aligned (in viewport space) rotations on Z axis are correctly delt with by expanding the box as necessary.
68    * 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.
69    *
70    * 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.
71    *
72    * Note: ASSUMES THAT THE VIEWPORT COVERS THE SCREEN AND THAT THE CANVAS SIZE AND VIEWPORT SIZE ARE THE SAME!!!!!  (Not the case for magnifier)
73    *
74    * @param[in]    modelViewMatrix   The model view matrix
75    * @param[in]    size              The size of the render item
76    * @param[in]    viewportWidth     The width of the viewport to calculate for
77    * @param[in]    viewportHeight    The height of the viewport to calculate for
78    * @return                         The AABB coordinates in viewport-space (x, y, width, height)
79    */
80   static ClippingBox CalculateViewportSpaceAABB(const Matrix& modelViewMatrix, const Vector3& size, const int viewportWidth, const int viewportHeight);
81
82   /**
83    * Overriden delete operator.
84    * Deletes the RenderItem from its global memory pool
85    * @param[in] A pointer to the RenderItem to delete.
86    */
87   void operator delete(void* ptr);
88
89   Matrix            mModelMatrix;
90   Matrix            mModelViewMatrix;
91   Vector4           mColor;
92   Vector3           mSize;
93   Vector3           mUpdateSize;
94   Render::Renderer* mRenderer;
95   Node*             mNode;
96   const void*       mTextureSet; //< Used for sorting only
97   int               mDepthIndex;
98   bool              mIsOpaque : 1;
99   bool              mIsUpdated : 1;
100
101 private:
102   /**
103    * Private constructor. See RenderItem::New
104    */
105   RenderItem();
106
107   // RenderItems should not be copied as they are heavy
108   RenderItem(const RenderItem& item);
109   RenderItem& operator=(const RenderItem& item);
110 };
111
112 } // namespace SceneGraph
113
114 } // namespace Internal
115
116 } // namespace Dali
117
118 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_ITEM_H