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