summaryrefslogtreecommitdiff
path: root/payloads/libpayload/include
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2015-09-28 13:14:43 -0700
committerPatrick Georgi <pgeorgi@google.com>2015-10-27 15:22:24 +0100
commita11e3ff160370b4d1ac838c7b89dcc0163bfe207 (patch)
tree8dd3ac701e572ab9081f800c78b94e6b432d9e73 /payloads/libpayload/include
parentf86515244a94c81484fa72884698acf322a9130f (diff)
downloadcoreboot-a11e3ff160370b4d1ac838c7b89dcc0163bfe207.tar.xz
cbgfx: add pivot option to draw_bitmap
This change adds 'pivot' option to draw_bitmap. It controls the point of the image based on which the image is positioned. For example, if a pivot is set to the center of the image horizontally and vertically, the image is positioned using pos_rel as the center of the image. This feature is necessary, for example, to place a text image in the center of the screen because each image has a different width depending on the language. This change also makes draw_bitmap accept both horizontal and vertical size. If either of them is zero, the other non-zero value is used to derive the size to keep the aspect ratio. Specifying the height is necessary to keep font sizes the same when drawing text images of different lengths. draw_bitmap_direct is a variant of draw_bitmap and it draws an image using a native coordinate and the original size (as opposed to the location and the size relative to the canvas). CL:303074 has real use cases. BUG=none BRANCH=tot TEST=Tested on Samus Change-Id: I5fde69fcb5cc9dc53e827dd9fcf001a0a32748d4 Signed-off-by: Patrick Georgi <pgeorgi@google.com> Original-Commit-Id: 82a0a8b60808410652552ed3a888937724111584 Original-Change-Id: I0b0d9113ebecf14e8c70de7a3562b215f69f2d4c Original-Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/302855 Reviewed-on: http://review.coreboot.org/11927 Tested-by: build bot (Jenkins)
Diffstat (limited to 'payloads/libpayload/include')
-rw-r--r--payloads/libpayload/include/cbgfx.h72
1 files changed, 49 insertions, 23 deletions
diff --git a/payloads/libpayload/include/cbgfx.h b/payloads/libpayload/include/cbgfx.h
index cb037a0897..ffd8534d13 100644
--- a/payloads/libpayload/include/cbgfx.h
+++ b/payloads/libpayload/include/cbgfx.h
@@ -16,10 +16,10 @@
#define CBGFX_ERROR_UNKNOWN 1
/* failed to initialize cbgfx library */
#define CBGFX_ERROR_INIT 2
-/* drawing beyond screen boundary */
-#define CBGFX_ERROR_SCREEN_BOUNDARY 3
-/* drawing beyond canvas boundary */
-#define CBGFX_ERROR_CANVAS_BOUNDARY 4
+/* drawing beyond screen or canvas boundary */
+#define CBGFX_ERROR_BOUNDARY 3
+/* invalid parameter */
+#define CBGFX_ERROR_INVALID_PARAMETER 4
/* bitmap error: signature mismatch */
#define CBGFX_ERROR_BITMAP_SIGNATURE 0x10
/* bitmap error: unsupported format */
@@ -73,7 +73,7 @@ struct rgb_color {
* y values increasing towards bottom of screen.
*/
-/*
+/**
* Load a bitmap file from cbfs
*
* Memory is allocated automatically and it's caller's responsibility to free it
@@ -85,7 +85,7 @@ struct rgb_color {
*/
void *load_bitmap(const char *name, size_t *size);
-/*
+/**
* draw a box filled with a color on screen
*
* box: .offset points the coordinate of the top left corner and .size specifies
@@ -97,29 +97,55 @@ void *load_bitmap(const char *name, size_t *size);
*/
int draw_box(const struct rect *box, const struct rgb_color *rgb);
-/*
+/**
* Clear the canvas
*/
-int clear_canvas(struct rgb_color *rgb);
+int clear_canvas(const struct rgb_color *rgb);
-/*
+/**
* Clear the screen
*/
-int clear_screen(struct rgb_color *rgb);
+int clear_screen(const struct rgb_color *rgb);
-/*
- * Draw a bitmap image on screen.
+/**
+ * Draw a bitmap image using position and size relative to the canvas
*
- * top_left_rel: coordinate of the top left corner of the image relative to the
- * canvas (0 - CANVAS_SCALE). If scale_rel is zero, this is treated as absolute
- * coordinate.
- * scale_rel: scale factor relative to the canvas width (0 - CANVAS_SCALE). If
- * this is zero, scaling is turned off and the image is rendered with the
- * original size.
- * bitmap: pointer to the bitmap data, starting from the file header.
- * size: size of the bitmap data
+ * @param[in] bitmap Pointer to the bitmap data, starting from file header
+ * @param[in] size Size of the bitmap data
+ * @param[in] pos_rel Coordinate of the pivot relative to the canvas
+ * @param[in] pivot Pivot position. Use PIVOT_H_* and PIVOT_V_* flags.
+ * @param[in] dim_rel Width and height of the image relative to the canvas
+ * width and height. They must not exceed 1 (=100%). If one
+ * is zero, it's derived from the other to keep the aspect
+ * ratio.
*
- * return: CBGFX_* error codes
+ * @return CBGFX_* error codes
+ *
+ * 'Pivot' is a point of the image based on which the image is positioned.
+ * For example, if a pivot is set to PIVOT_H_CENTER|PIVOT_V_CENTER, the image is
+ * positioned so that pos_rel matches the center of the image.
*/
-int draw_bitmap(const struct vector *top_left_rel,
- size_t scale_rel, const void *bitmap, size_t size);
+int draw_bitmap(const void *bitmap, size_t size,
+ const struct scale *pos_rel, uint8_t pivot,
+ const struct scale *dim_rel);
+
+/* Pivot flags. See the draw_bitmap description. */
+#define PIVOT_H_LEFT (1 << 0)
+#define PIVOT_H_CENTER (1 << 1)
+#define PIVOT_H_RIGHT (1 << 2)
+#define PIVOT_V_TOP (1 << 3)
+#define PIVOT_V_CENTER (1 << 4)
+#define PIVOT_V_BOTTOM (1 << 5)
+
+/**
+ * Draw a bitmap image at screen coordinate with no scaling
+ *
+ * @param[in] bitmap Pointer to the bitmap data, starting from file header
+ * @param[in] size Size of the bitmap data
+ * @param[in] pos Screen coordinate of upper left corner of the image.
+ *
+ * @return CBGFX_* error codes
+ */
+int draw_bitmap_direct(const void *bitmap, size_t size,
+ const struct vector *pos);
+