cbgfx: allow draw_bitmap to render outside canvas
[coreboot.git] / payloads / libpayload / include / cbgfx.h
blob2d6b6e938ab027012d33fb2e9aa2a0cc0c13adc2
1 /*
2 * This file is part of the libpayload project.
4 * Copyright (C) 2015 Google, Inc.
5 */
7 #include <libpayload.h>
8 #include <arch/types.h>
9 #include <stddef.h>
12 * API error codes
14 #define CBGFX_SUCCESS 0
15 /* unknown error */
16 #define CBGFX_ERROR_UNKNOWN 1
17 /* failed to initialize cbgfx library */
18 #define CBGFX_ERROR_INIT 2
19 /* drawing beyond screen boundary */
20 #define CBGFX_ERROR_SCREEN_BOUNDARY 3
21 /* drawing beyond canvas boundary */
22 #define CBGFX_ERROR_CANVAS_BOUNDARY 4
23 /* bitmap error: signature mismatch */
24 #define CBGFX_ERROR_BITMAP_SIGNATURE 0x10
25 /* bitmap error: unsupported format */
26 #define CBGFX_ERROR_BITMAP_FORMAT 0x11
27 /* bitmap error: invalid data */
28 #define CBGFX_ERROR_BITMAP_DATA 0x12
29 /* bitmap error: scaling out of range */
30 #define CBGFX_ERROR_SCALE_OUT_OF_RANGE 0x13
32 struct fraction {
33 int32_t nume;
34 int32_t deno;
37 struct scale {
38 struct fraction x;
39 struct fraction y;
42 struct vector {
43 union {
44 int32_t x;
45 int32_t width;
47 union {
48 int32_t y;
49 int32_t height;
53 struct rect {
54 struct vector offset;
55 struct vector size;
58 struct rgb_color {
59 uint8_t red;
60 uint8_t green;
61 uint8_t blue;
65 * Resolution of scale parameters used to describe height, width, coordinate,
66 * etc. relative to the canvas. For example, if it's 100, scales range from 0 to
67 * 100%.
69 #define CANVAS_SCALE 100
72 * The coordinate system is expected to have (0, 0) at top left corner with
73 * y values increasing towards bottom of screen.
77 * draw a box filled with a color on screen
79 * box: .offset points the coordinate of the top left corner and .size specifies
80 * width and height of the box. Both are relative to the canvas size thus scale
81 * from 0 to CANVAS_SCALE (0 to 100%).
82 * rgb: RGB color of the box.
84 * return: CBGFX_* error codes
86 int draw_box(const struct rect *box, const struct rgb_color *rgb);
89 * Clear the canvas
91 int clear_canvas(struct rgb_color *rgb);
94 * Draw a bitmap image on screen.
96 * top_left_rel: coordinate of the top left corner of the image relative to the
97 * canvas (0 - CANVAS_SCALE). If scale_rel is zero, this is treated as absolute
98 * coordinate.
99 * scale_rel: scale factor relative to the canvas width (0 - CANVAS_SCALE). If
100 * this is zero, scaling is turned off and the image is rendered with the
101 * original size.
102 * bitmap: pointer to the bitmap data, starting from the file header.
103 * size: size of the bitmap data
105 * return: CBGFX_* error codes
107 int draw_bitmap(const struct vector *top_left_rel,
108 size_t scale_rel, const void *bitmap, size_t size);