• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <string.h>
3 #include <weston.h>
4 #include <ivi-layout-export.h>
5 #include <ivi-layout-private.h>
6 #include "ivi-controller.h"
7 #include "screen-info.h"
8 
9 #define LOG(fmt, ...)  weston_log("screen-info " fmt "\n", ##__VA_ARGS__)
10 
11 static struct ivishell *shell;
12 
13 struct iviscreen {
14     struct wl_list link;
15     struct ivishell *shell;
16     uint32_t id_screen;
17     struct weston_output *output;
18     struct wl_list resource_list;
19 };
20 
get_screens_info()21 struct screen_info **get_screens_info()
22 {
23     struct iviscreen *iviscrn = NULL;
24     int screen_count_with_null = 1;
25     wl_list_for_each(iviscrn, &shell->list_screen, link) {
26         screen_count_with_null++;
27     }
28 
29     struct screen_info **screens = (struct screen_info **)malloc(
30             screen_count_with_null * sizeof(struct screen_info *));
31 
32     for (int i = 0; i < screen_count_with_null - 1; i++) {
33         screens[i] = (struct screen_info *)malloc(sizeof(struct screen_info));
34     }
35     screens[screen_count_with_null - 1] = NULL;
36 
37     struct ivi_layout_layer **layer_list = NULL;
38     const struct ivi_layout_interface *lyt = shell->interface;
39     int layer_count, surf_cnt;
40 
41     int screen_i = 0;
42     wl_list_for_each(iviscrn, &shell->list_screen, link) {
43         lyt->get_layers_on_screen(
44                 iviscrn->output, &layer_count, &layer_list);
45         struct screen_info *iscreen = screens[screen_i++];
46 
47         iscreen->screen_id = iviscrn->id_screen;
48         iscreen->connector_name = (char *)malloc(
49                 strlen(iviscrn->output->name) + 1);
50         strcpy(iscreen->connector_name, iviscrn->output->name);
51         iscreen->width = iviscrn->output->width;
52         iscreen->height = iviscrn->output->height;
53         iscreen->nlayers = layer_count;
54         iscreen->layers = (struct layer_info **)malloc(
55                 layer_count * sizeof(struct layer_info *));
56         for (int i = 0; i < layer_count; i++) {
57             iscreen->layers[i] = (struct layer_info *)malloc(
58                 sizeof(struct layer_info));
59         }
60 
61         for (int i = 0; i < layer_count; i++) {
62             struct ivi_layout_layer *layer = layer_list[i];
63             struct ivi_layout_layer_properties *p = &layer->prop;
64             struct ivi_layout_surface **surf_list = NULL;
65             lyt->get_surfaces_on_layer(layer, &surf_cnt, &surf_list);
66 
67             struct layer_info *ilayer = iscreen->layers[i];
68             ilayer->layer_id = lyt->get_id_of_layer(layer);
69             ilayer->dst_x = p->dest_x;
70             ilayer->dst_y = p->dest_y;
71             ilayer->dst_w = p->dest_width;
72             ilayer->dst_h = p->dest_height;
73             ilayer->src_x = p->source_x;
74             ilayer->src_y = p->source_y;
75             ilayer->src_w = p->source_width;
76             ilayer->src_h = p->source_height;
77             ilayer->opacity = wl_fixed_to_double(p->opacity);
78             ilayer->visibility = p->visibility;
79             ilayer->on_screen_id = iscreen->screen_id;
80             ilayer->nsurfaces = surf_cnt;
81             ilayer->surfaces = (struct surface_info **)malloc(
82                     surf_cnt * sizeof(struct surface_info *));
83             for (int j = 0; j < surf_cnt; j++) {
84                 ilayer->surfaces[j] = (struct surface_info *)malloc(
85                         sizeof(struct surface_info));
86             }
87 
88             for (int j = 0; j < surf_cnt; j++) {
89                 struct ivi_layout_surface *surface = surf_list[j];
90                 struct ivi_layout_surface_properties *p = &surface->prop;
91                 struct surface_info *isurface = ilayer->surfaces[j];
92 
93                 isurface->surface_id = lyt->get_id_of_surface(surface);
94                 isurface->dst_x = p->dest_x;
95                 isurface->dst_y = p->dest_y;
96                 isurface->dst_w = p->dest_width;
97                 isurface->dst_h = p->dest_height;
98                 isurface->src_x = p->source_x;
99                 isurface->src_y = p->source_y;
100                 isurface->src_w = p->source_width;
101                 isurface->src_h = p->source_height;
102                 isurface->opacity = wl_fixed_to_double(p->opacity);
103                 isurface->visibility = p->visibility;
104                 isurface->on_layer_id = ilayer->layer_id;
105             }
106         }
107     }
108 
109     return screens;
110 }
111 
free_screens_info(struct screen_info ** screens)112 void free_screens_info(struct screen_info **screens)
113 {
114     for (int i = 0; screens[i]; i++) {
115         struct screen_info *iscreen = screens[i];
116         for (int j = 0; j < iscreen->nlayers; j++) {
117             struct layer_info *ilayer = iscreen->layers[j];
118             for (int k = 0; k < ilayer->nsurfaces; k++) {
119                 struct surface_info *isurface = ilayer->surfaces[k];
120                 free(isurface);
121             }
122             free(ilayer->surfaces);
123             free(ilayer);
124         }
125         free(iscreen->layers);
126         free(iscreen->connector_name);
127         free(iscreen);
128     }
129     free(screens);
130 }
131 
132 static int
load_test_screen_info_module(struct ivishell * shell)133 load_test_screen_info_module(struct ivishell *shell)
134 {
135     struct weston_config *config = wet_get_config(shell->compositor);
136     struct weston_config_section *section;
137     char *test_screen_info_module = NULL;
138 
139     int (*test_screen_info_module_init)(struct ivishell *shell);
140 
141     section = weston_config_get_section(config, "screen-info", NULL, NULL);
142 
143     if (weston_config_section_get_string(section, "test-screen-info-module",
144                                          &test_screen_info_module, NULL) < 0) {
145         /* input events are handled by weston's default grabs */
146         weston_log("ivi-controller: No test-screen-info-module set\n");
147         return 0;
148     }
149 
150     test_screen_info_module_init =
151         wet_load_module_entrypoint(test_screen_info_module, "ivishell_module_init");
152     if (!test_screen_info_module_init)
153         return -1;
154 
155     if (test_screen_info_module_init(shell) != 0) {
156         weston_log("ivi-controller: Initialization of test-screen-info-module fails");
157         return -1;
158     }
159 
160     free(test_screen_info_module);
161 
162     return 0;
163 }
164 
165 WL_EXPORT int
ivishell_module_init(struct ivishell * shell_)166 ivishell_module_init(struct ivishell *shell_)
167 {
168     shell = shell_;
169 
170     if (load_test_screen_info_module(shell) < 0) {
171         return -1;
172     }
173 
174     return 0;
175 }
176