Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-tracker.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/internal/render/common/render-tracker.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/integration-api/gl-sync-abstraction.h>
22 #include <dali/internal/render/common/render-tracker-debug.h>
23
24 // EXTERNAL INCLUDES
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace SceneGraph
31 {
32
33
34 RenderTracker::RenderTracker(Integration::GlSyncAbstraction& glSyncAbstraction)
35 : mGlSyncAbstraction(glSyncAbstraction),
36   mSyncTrigger(0),
37   mSyncObject(NULL)
38 {
39   TRACKER_LOG(Debug::Verbose);
40 }
41
42 RenderTracker::~RenderTracker()
43 {
44   TRACKER_LOG(Debug::Verbose);
45   if( mSyncObject )
46   {
47     mGlSyncAbstraction.DestroySyncObject( mSyncObject );
48     mSyncObject = NULL;
49   }
50 }
51
52 void RenderTracker::CreateSyncObject()
53 {
54   TRACKER_LOG(Debug::General);
55
56   // Destroy any previous sync object
57   if( mSyncObject )
58   {
59      mGlSyncAbstraction.DestroySyncObject( mSyncObject );
60      mSyncObject = NULL;
61   }
62   ResetSyncFlag();
63   mSyncObject = mGlSyncAbstraction.CreateSyncObject( );
64 }
65
66 void RenderTracker::PollSyncObject()
67 {
68   if( mSyncObject && mSyncObject->IsSynced() )
69   {
70     SetSyncFlag();
71     mGlSyncAbstraction.DestroySyncObject( mSyncObject );
72     mSyncObject = NULL;
73
74     TRACKER_LOG_FMT(Debug::General, " Synced\n");
75     return;
76   }
77   TRACKER_LOG_FMT(Debug::General, " Not Synced\n");
78 }
79
80 bool RenderTracker::IsSynced()
81 {
82   int x = __sync_val_compare_and_swap(&mSyncTrigger, 0xFF, 0x0);
83
84   TRACKER_LOG_FMT(Debug::General, " = %s\n", x!=0?"T":"F");
85   return x != 0;
86 }
87
88 void RenderTracker::ResetSyncFlag()
89 {
90   TRACKER_LOG(Debug::General);
91   (void)__sync_lock_test_and_set(&mSyncTrigger, 0x0);
92 }
93
94 void RenderTracker::SetSyncFlag()
95 {
96   (void)__sync_lock_test_and_set(&mSyncTrigger, 0xFF);
97 }
98
99 } // SceneGraph
100 } // Internal
101 } // Dali