Revert "[Tizen] Add codes for Dali Windows Backend"
[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 x = __sync_val_compare_and_swap(&mSyncTrigger, 0xFF, 0x0);
86
87   TRACKER_LOG_FMT(Debug::General, " = %s\n", x!=0?"T":"F");
88   return x != 0;
89 }
90
91 void RenderTracker::ResetSyncFlag()
92 {
93   TRACKER_LOG(Debug::General);
94   (void)__sync_lock_test_and_set(&mSyncTrigger, 0x0);
95 }
96
97 void RenderTracker::SetSyncFlag()
98 {
99   (void)__sync_lock_test_and_set(&mSyncTrigger, 0xFF);
100 }
101
102 } // Render
103
104 } // Internal
105
106 } // Dali