022f12067d615378cbe86da8c1fff32144cce032
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-tracker.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/render/common/render-tracker.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/gl-sync-abstraction.h>
23 #include <dali/internal/render/common/render-tracker-debug.h>
24
25 // EXTERNAL INCLUDES
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Render
34 {
35
36 RenderTracker::RenderTracker()
37 : mGlSyncAbstraction( NULL ),
38   mSyncObject( NULL ),
39   mSyncTrigger( 0 )
40 {
41   TRACKER_LOG(Debug::Verbose);
42 }
43
44 RenderTracker::~RenderTracker()
45 {
46   TRACKER_LOG(Debug::Verbose);
47   if( mSyncObject )
48   {
49     mGlSyncAbstraction->DestroySyncObject( mSyncObject );
50     mSyncObject = NULL;
51   }
52 }
53
54 void RenderTracker::CreateSyncObject( Integration::GlSyncAbstraction& glSyncAbstraction )
55 {
56   mGlSyncAbstraction = &glSyncAbstraction;
57   TRACKER_LOG(Debug::General);
58
59   // Destroy any previous sync object
60   if( mSyncObject )
61   {
62      mGlSyncAbstraction->DestroySyncObject( mSyncObject );
63      mSyncObject = NULL;
64   }
65   ResetSyncFlag();
66   mSyncObject = mGlSyncAbstraction->CreateSyncObject();
67 }
68
69 void RenderTracker::PollSyncObject()
70 {
71   if( mSyncObject && mSyncObject->IsSynced() )
72   {
73     SetSyncFlag();
74     mGlSyncAbstraction->DestroySyncObject( mSyncObject );
75     mSyncObject = NULL;
76
77     TRACKER_LOG_FMT(Debug::General, " Synced\n");
78     return;
79   }
80   TRACKER_LOG_FMT(Debug::General, " Not Synced\n");
81 }
82
83 bool RenderTracker::IsSynced()
84 {
85   int flag = 0xFF;
86   bool ret = mSyncTrigger.compare_exchange_strong( flag, 0 );
87
88   TRACKER_LOG_FMT( Debug::General, " = %s\n", true == ret ? "T" : "F" );
89   return ret;
90 }
91
92 void RenderTracker::ResetSyncFlag()
93 {
94   TRACKER_LOG(Debug::General);
95   int flag = 0xFF;
96   mSyncTrigger.compare_exchange_strong( flag, 0 );
97 }
98
99 void RenderTracker::SetSyncFlag()
100 {
101   int flag = 0;
102   mSyncTrigger.compare_exchange_strong( flag, 0xFF );
103 }
104
105 } // Render
106
107 } // Internal
108
109 } // Dali