tizen 2.3 release
[framework/system/deviced.git] / src / display / display-actor.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #include <stdio.h>
21
22 #include "util.h"
23 #include "display-actor.h"
24 #include "core/list.h"
25 #include "core/common.h"
26
27 static dd_list *actor_head;
28
29 void display_add_actor(struct display_actor_ops *actor)
30 {
31         DD_LIST_APPEND(actor_head, actor);
32 }
33
34 static struct display_actor_ops *display_find_actor(enum display_actor_id id)
35 {
36         dd_list *elem;
37         struct display_actor_ops *actor;
38
39         DD_LIST_FOREACH(actor_head, elem, actor) {
40                 if (actor->id == id)
41                         return actor;
42         }
43         return NULL;
44 }
45
46 int display_set_caps(enum display_actor_id id, unsigned int caps)
47 {
48         struct display_actor_ops *actor;
49
50         if (id <= 0 || !caps)
51                 return -EINVAL;
52
53         actor = display_find_actor(id);
54         if (!actor)
55                 return -EINVAL;
56
57         actor->caps |= caps;
58
59         return 0;
60 }
61
62 int display_reset_caps(enum display_actor_id id, unsigned int caps)
63 {
64         struct display_actor_ops *actor;
65
66         if (id <= 0 || !caps)
67                 return -EINVAL;
68
69         actor = display_find_actor(id);
70         if (!actor)
71                 return -EINVAL;
72
73         actor->caps &= ~caps;
74
75         return 0;
76 }
77
78 unsigned int display_get_caps(enum display_actor_id id)
79 {
80         struct display_actor_ops *actor;
81
82         if (id <= 0)
83                 return 0;
84
85         actor = display_find_actor(id);
86         if (!actor)
87                 return 0;
88
89         return actor->caps;
90 }
91
92 int display_has_caps(unsigned int total_caps, unsigned int caps)
93 {
94         if (!total_caps || !caps)
95                 return false;
96
97         if ((total_caps & caps) == caps)
98                 return true;
99
100         return false;
101 }
102