Sync UTC harness
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-instruction.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_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 // INTERNAL INCLUDES
22 #include <dali/internal/render/common/render-list.h>
23 #include <dali/internal/render/renderers/render-frame-buffer.h>
24 #include <dali/internal/update/render-tasks/scene-graph-camera.h>
25 #include <dali/public-api/math/matrix.h>
26 #include <dali/public-api/math/viewport.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 namespace Render
33 {
34 class RenderTracker;
35 }
36
37 namespace SceneGraph
38 {
39 /**
40  * A set of rendering instructions consisting of:
41  * - The list(s) of renderers sorted in the correct rendering order.
42  * - The camera related matrices to use when rendering.
43  * - An optional off-screen render target.
44  * There is one RenderInstruction per RenderTarget, all renderers of all layers
45  * get collated onto the single list of lists (mRenderLists)
46  */
47 class RenderInstruction
48 {
49 public:
50   /**
51    * Default constructor so this can be stored in STL containers
52    */
53   RenderInstruction();
54
55   /**
56    * Destructor
57    */
58   ~RenderInstruction();
59
60   RenderInstruction(const RenderInstruction&) = delete;
61
62   RenderInstruction& operator=(const RenderInstruction& rhs) = delete;
63
64   /**
65    * Get the next free Renderlist
66    * @param capacityRequired in this list
67    * @return the renderlist
68    */
69   RenderList& GetNextFreeRenderList(size_t capacityRequired);
70
71   /**
72    * Inform the RenderInstruction that processing for this frame is complete
73    * This method should only be called from Update thread
74    */
75   void UpdateCompleted();
76
77   /**
78    * @return the count of active Renderlists
79    */
80   [[nodiscard]] RenderListContainer::SizeType RenderListCount() const;
81
82   /**
83    * Return the renderlist at given index
84    * @pre index is inside the valid range of initialized lists
85    * @param index of list to return
86    * @return pointer to the renderlist, or null if the index is out of bounds.
87    */
88   [[nodiscard]] const RenderList* GetRenderList(RenderListContainer::SizeType index) const;
89
90   /**
91    * Reset render-instruction
92    * render-lists are cleared but not released, while matrices and other settings reset in
93    * preparation for building a set of instructions for the renderer.
94    *
95    * @param[in] camera to use to get view and projection matrices.
96    * @param[in] offscreenId A resource Id of an off-screen render target, or 0
97    * @param[in] viewport A pointer to a viewport, of NULL.
98    * @param[in] clearColor A pointer to a color to clear with, or NULL if no clear is required.
99    */
100   void Reset(Camera*              camera,
101              Render::FrameBuffer* frameBuffer,
102              const Viewport*      viewport,
103              const Vector4*       clearColor);
104
105   /**
106    * Get the view matrix for rendering
107    * @param index of the rendering side
108    * @return the view matrix
109    */
110   [[nodiscard]] const Matrix* GetViewMatrix(BufferIndex index) const
111   {
112     // inlined as this is called once per frame per render instruction
113     return &mCamera->GetViewMatrix(index);
114   }
115
116   /**
117    * Get the projection matrix for rendering
118    * @param index of the rendering side
119    * @return the projection matrix
120    */
121   [[nodiscard]] const Matrix* GetProjectionMatrix(BufferIndex index) const
122   {
123     // inlined as this is called once per frame per render instruction
124     return &mCamera->GetFinalProjectionMatrix(index);
125   }
126   // for reflection effect
127   [[nodiscard]] const Camera* GetCamera() const
128   {
129     return mCamera;
130   }
131
132 public:                                  // Data
133   Render::RenderTracker* mRenderTracker; ///< Pointer to an optional tracker object (not owned)
134
135   Viewport mViewport;              ///< Optional viewport
136   Vector4  mClearColor;            ///< Optional color to clear with
137   bool     mIsViewportSet : 1;     ///< Flag to determine whether the viewport is set
138   bool     mIsClearColorSet : 1;   ///< Flag to determine whether the clearColor is set
139   bool     mIgnoreRenderToFbo : 1; ///< Whether to ignore the render to FBO option (used to measure the performance above 60 fps)
140
141   Render::FrameBuffer* mFrameBuffer;
142
143 private:                                             // Data
144   Camera*                       mCamera;             ///< camera that is used
145   RenderListContainer           mRenderLists;        ///< container of all render lists
146   RenderListContainer::SizeType mNextFreeRenderList; ///< index for the next free render list
147 };
148
149 } // namespace SceneGraph
150
151 } // namespace Internal
152
153 } // namespace Dali
154
155 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_H