License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / update / resources / complete-status-manager.h
1 #ifndef __DALI_INTERNAL_COMPLETE_STATUS_MANAGER_H__
2 #define __DALI_INTERNAL_COMPLETE_STATUS_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 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 #include <dali/public-api/common/map-wrapper.h>
22 #include <dali/integration-api/resource-declarations.h>
23 #include <dali/internal/update/common/scene-graph-buffers.h>
24
25 namespace Dali
26 {
27
28 namespace Integration
29 {
30 class GlSyncAbstraction;
31 }
32
33 namespace Internal
34 {
35 class ResourceManager;
36 class ResourceTracker;
37
38 namespace SceneGraph
39 {
40 class RenderMessageDispatcher;
41 }
42
43 /**
44  * Class to manage resource tracking and completion status.
45  *
46  * Resources that are tracked are usually Framebuffer objects that are
47  * being rendered to by a RenderOnce render task.
48  *
49  * These need to change completion status either when all resources used by
50  * the framebuffer are complete, or when the framebuffer is backed by a native
51  * image and the native image has been written to by GL.
52  *
53  * This class uses ResourceManager to determine the complete status
54  * of non-tracked resources.
55  */
56 class CompleteStatusManager
57 {
58 public:
59   /**
60    * Resource readiness state
61    */
62   enum CompleteState
63   {
64     NOT_READY, ///< Resource is not ready yet
65     COMPLETE,  ///< Resource has finished loading, or is otherwise complete
66     NEVER      ///< Resource will never be complete, e.g. load failed.
67   };
68
69   /**
70    * Constructor.
71    *
72    * @param[in] glSyncAbstraction The GlSyncObject abstraction (for creating RenderTrackers)
73    * @param[in] renderQueue The render queue (For passing ownership of RenderTrackers to RenderManager)
74    * @param[in] renderManager The render manager
75    * @param[in] query Update buffer query
76    * @param[in] resourceManager The resource manager (For handling untracked resources)
77    */
78   CompleteStatusManager( Integration::GlSyncAbstraction& glSyncAbstraction,
79                          SceneGraph::RenderMessageDispatcher& renderMessageDispatcher,
80                          ResourceManager& resourceManager );
81
82   /**
83    * Destructor
84    */
85   ~CompleteStatusManager();
86
87   /**
88    * @param[in] id The resource id to track
89    */
90   void TrackResource( Integration::ResourceId id );
91
92   /**
93    * Stop tracking the resource ID. Will remove any resource / render trackers for this ID.
94    * @param[in] id The resource id to stop tracking
95    */
96   void StopTrackingResource ( Integration::ResourceId id );
97
98   /**
99    * Get the resource tracker associated with this id
100    * @param[in] id The resource id
101    * @return a valid tracker if this resource is being tracked, or NULL.
102    */
103   ResourceTracker* FindResourceTracker( Integration::ResourceId id );
104
105   /**
106    * Gets the complete status of the resource.  If it has a tracker,
107    * it returns the status from the resource tracker, otherwise it
108    * returns the load status from the resource manager
109    *
110    * @param[in] id The resource id @return The complete state of the
111    * resource
112    */
113   CompleteState GetStatus( Integration::ResourceId id );
114
115 private:
116   /**
117    * Factory method to create a ResourceTracker or GlResourceTracker for this resource id.
118    * It creates a ResourceTracker for framebuffers without native images, or a GlResourceTracker
119    * for framebuffers with native images that require Gl FenceSync.
120    * @param[in] id The resource id
121    */
122   ResourceTracker* CreateResourceTracker(Integration::ResourceId id);
123
124   typedef std::map< Integration::ResourceId, ResourceTracker* > TrackedResources;
125   typedef TrackedResources::iterator TrackedResourcesIter;
126
127   Integration::GlSyncAbstraction& mGlSyncAbstraction; ///< The synchronisation interface
128   SceneGraph::RenderMessageDispatcher& mRenderMessageDispatcher; ///< Render thread message dispatcher
129   ResourceManager& mResourceManager;   ///< The resource manager
130   TrackedResources mTrackedResources;  ///< Tracked resources
131 };
132
133 } // Internal
134 } // Dali
135
136 #endif // __DALI_INTERNAL_COMPLETE_STATUS_MANAGER_H__