mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-25 02:41:45 +00:00
Move ACRN Device Model code in a devicemodel/ folder
This is part of the short series of commits that will lead to a unified repository for the ACRN hypervisor, device model and the associated documentation. Signed-off-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
This commit is contained in:
76
devicemodel/core/gc.c
Normal file
76
devicemodel/core/gc.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "gc.h"
|
||||
|
||||
struct gfx_ctx {
|
||||
struct gfx_ctx_image *gc_image;
|
||||
int raw;
|
||||
};
|
||||
|
||||
struct gfx_ctx *
|
||||
gc_init(int width, int height, void *fbaddr)
|
||||
{
|
||||
struct gfx_ctx *gc;
|
||||
struct gfx_ctx_image *gc_image;
|
||||
|
||||
gc = calloc(1, sizeof(struct gfx_ctx));
|
||||
assert(gc != NULL);
|
||||
|
||||
gc_image = calloc(1, sizeof(struct gfx_ctx_image));
|
||||
assert(gc_image != NULL);
|
||||
|
||||
gc_image->width = width;
|
||||
gc_image->height = height;
|
||||
if (fbaddr) {
|
||||
gc_image->data = fbaddr;
|
||||
gc->raw = 1;
|
||||
} else {
|
||||
gc_image->data = calloc(width * height, sizeof(uint32_t));
|
||||
gc->raw = 0;
|
||||
}
|
||||
|
||||
gc->gc_image = gc_image;
|
||||
|
||||
return gc;
|
||||
}
|
||||
|
||||
void
|
||||
gc_set_fbaddr(struct gfx_ctx *gc, void *fbaddr)
|
||||
{
|
||||
gc->raw = 1;
|
||||
if (gc->gc_image->data && gc->gc_image->data != fbaddr)
|
||||
free(gc->gc_image->data);
|
||||
gc->gc_image->data = fbaddr;
|
||||
}
|
||||
|
||||
void
|
||||
gc_resize(struct gfx_ctx *gc, int width, int height)
|
||||
{
|
||||
struct gfx_ctx_image *gc_image;
|
||||
|
||||
gc_image = gc->gc_image;
|
||||
|
||||
gc_image->width = width;
|
||||
gc_image->height = height;
|
||||
if (!gc->raw) {
|
||||
gc_image->data = realloc(gc_image->data,
|
||||
width * height * sizeof(uint32_t));
|
||||
if (gc_image->data != NULL)
|
||||
memset(gc_image->data, 0, width * height *
|
||||
sizeof(uint32_t));
|
||||
}
|
||||
}
|
||||
|
||||
struct gfx_ctx_image *
|
||||
gc_get_image(struct gfx_ctx *gc)
|
||||
{
|
||||
if (gc == NULL)
|
||||
return NULL;
|
||||
|
||||
return gc->gc_image;
|
||||
}
|
Reference in New Issue
Block a user