]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/bhyve/bhyvegc.c
MFV r331400: 8484 Implement aggregate sum and use for arc counters
[FreeBSD/FreeBSD.git] / usr.sbin / bhyve / bhyvegc.c
1 #include <sys/cdefs.h>
2 __FBSDID("$FreeBSD$");
3
4 #include <sys/types.h>
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9
10 #include "bhyvegc.h"
11
12 struct bhyvegc {
13         struct bhyvegc_image    *gc_image;
14         int raw;
15 };
16
17 struct bhyvegc *
18 bhyvegc_init(int width, int height, void *fbaddr)
19 {
20         struct bhyvegc *gc;
21         struct bhyvegc_image *gc_image;
22
23         gc = calloc(1, sizeof (struct bhyvegc));
24
25         gc_image = calloc(1, sizeof(struct bhyvegc_image));
26         gc_image->width = width;
27         gc_image->height = height;
28         if (fbaddr) {
29                 gc_image->data = fbaddr;
30                 gc->raw = 1;
31         } else {
32                 gc_image->data = calloc(width * height, sizeof (uint32_t));
33                 gc->raw = 0;
34         }
35
36         gc->gc_image = gc_image;
37
38         return (gc);
39 }
40
41 void
42 bhyvegc_set_fbaddr(struct bhyvegc *gc, void *fbaddr)
43 {
44         gc->raw = 1;
45         if (gc->gc_image->data && gc->gc_image->data != fbaddr)
46                 free(gc->gc_image->data);
47         gc->gc_image->data = fbaddr;
48 }
49
50 void
51 bhyvegc_resize(struct bhyvegc *gc, int width, int height)
52 {
53         struct bhyvegc_image *gc_image;
54
55         gc_image = gc->gc_image;
56
57         gc_image->width = width;
58         gc_image->height = height;
59         if (!gc->raw) {
60                 gc_image->data = reallocarray(gc_image->data, width * height,
61                     sizeof (uint32_t));
62                 if (gc_image->data != NULL)
63                         memset(gc_image->data, 0, width * height *
64                             sizeof (uint32_t));
65         }
66 }
67
68 struct bhyvegc_image *
69 bhyvegc_get_image(struct bhyvegc *gc)
70 {
71         if (gc == NULL)
72                 return (NULL);
73
74         return (gc->gc_image);
75 }