[dali_1.1.5] Merge branch 'devel/master'
[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 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 namespace Internal
30 {
31 namespace SceneGraph
32 {
33
34
35 RenderTracker::RenderTracker(Integration::GlSyncAbstraction& glSyncAbstraction)
36 : mGlSyncAbstraction(glSyncAbstraction),
37   mSyncTrigger(0),
38   mSyncObject(NULL)
39 {
40   TRACKER_LOG(Debug::Verbose);
41 }
42
43 RenderTracker::~RenderTracker()
44 {
45   TRACKER_LOG(Debug::Verbose);
46   if( mSyncObject )
47   {
48     mGlSyncAbstraction.DestroySyncObject( mSyncObject );
49     mSyncObject = NULL;
50   }
51 }
52
53 void RenderTracker::CreateSyncObject()
54 {
55   TRACKER_LOG(Debug::General);
56
57   // Destroy any previous sync object
58   if( mSyncObject )
59   {
60      mGlSyncAbstraction.DestroySyncObject( mSyncObject );
61      mSyncObject = NULL;
62   }
63   ResetSyncFlag();
64   mSyncObject = mGlSyncAbstraction.CreateSyncObject( );
65 }
66
67 void RenderTracker::PollSyncObject()
68 {
69   if( mSyncObject && mSyncObject->IsSynced() )
70   {
71     SetSyncFlag();
72     mGlSyncAbstraction.DestroySyncObject( mSyncObject );
73     mSyncObject = NULL;
74
75     TRACKER_LOG_FMT(Debug::General, " Synced\n");
76     return;
77   }
78   TRACKER_LOG_FMT(Debug::General, " Not Synced\n");
79 }
80
81 bool RenderTracker::IsSynced()
82 {
83   int x = __sync_val_compare_and_swap(&mSyncTrigger, 0xFF, 0x0);
84
85   TRACKER_LOG_FMT(Debug::General, " = %s\n", x!=0?"T":"F");
86   return x != 0;
87 }
88
89 void RenderTracker::ResetSyncFlag()
90 {
91   TRACKER_LOG(Debug::General);
92   (void)__sync_lock_test_and_set(&mSyncTrigger, 0x0);
93 }
94
95 void RenderTracker::SetSyncFlag()
96 {
97   (void)__sync_lock_test_and_set(&mSyncTrigger, 0xFF);
98 }
99
100 } // SceneGraph
101 } // Internal
102 } // Dali