| 1 | /*************************************************************** |
|---|
| 2 | ** |
|---|
| 3 | ** Broadcom Corp. Confidential |
|---|
| 4 | ** Copyright 2002 Broadcom Corp. All Rights Reserved. |
|---|
| 5 | ** |
|---|
| 6 | ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED |
|---|
| 7 | ** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM. |
|---|
| 8 | ** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT |
|---|
| 9 | ** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 10 | ** |
|---|
| 11 | ** Description: bgfx core implementation |
|---|
| 12 | ** |
|---|
| 13 | ** Created: 8/22/2002 by Jeffrey P. Fisher |
|---|
| 14 | ** |
|---|
| 15 | ** |
|---|
| 16 | ** |
|---|
| 17 | ****************************************************************/ |
|---|
| 18 | |
|---|
| 19 | #ifndef __bgfx_h__ |
|---|
| 20 | #define __bgfx_h__ |
|---|
| 21 | |
|---|
| 22 | /* Broadcom driver includes */ |
|---|
| 23 | #ifdef LINUX |
|---|
| 24 | #include <stdio.h> |
|---|
| 25 | #include <string.h> |
|---|
| 26 | #include <malloc.h> |
|---|
| 27 | #endif |
|---|
| 28 | #include "bgfx_types.h" |
|---|
| 29 | #include "bgfx_defs.h" |
|---|
| 30 | #include "bgfx_font.h" |
|---|
| 31 | |
|---|
| 32 | /**************************************************************** |
|---|
| 33 | * raw bitmap structure |
|---|
| 34 | * bcm_raw_8_t describes the raw CLUT8 image format supported by SGIL |
|---|
| 35 | * The structure if followed by a 256 entry CLUT, each entry ARGB8888 |
|---|
| 36 | ****************************************************************/ |
|---|
| 37 | typedef struct bcm_raw_8_t |
|---|
| 38 | { |
|---|
| 39 | uint32_t version; /* version number of raw file - for future use */ |
|---|
| 40 | uint32_t type; /* type of raw file - for future use */ |
|---|
| 41 | uint32_t pitch; /* number of bytes per row */ |
|---|
| 42 | uint16_t width; /* number of pixel per row */ |
|---|
| 43 | uint16_t height; /* number of rows */ |
|---|
| 44 | uint8_t color_key; /* color key/transparency color value */ |
|---|
| 45 | uint16_t clut_size; /* number of entries in the ARGB8888 CLUT */ |
|---|
| 46 | }bcm_raw_8_t; |
|---|
| 47 | #define RAW_TYPE 0x52415720 |
|---|
| 48 | #define RAW_VERSION 0x00000001 |
|---|
| 49 | |
|---|
| 50 | #ifdef __cplusplus |
|---|
| 51 | extern "C" { |
|---|
| 52 | #endif |
|---|
| 53 | /**************************************************************** |
|---|
| 54 | * global sgil initialization |
|---|
| 55 | * Initialize SGIL global resources. Should be called prior to using |
|---|
| 56 | * any other SGIL function. prot_p must be an allocated and initialized. |
|---|
| 57 | * It is important that prot_p exists for the entire time |
|---|
| 58 | * SGIL is running and initialized because sgil just copies the reference. |
|---|
| 59 | ****************************************************************/ |
|---|
| 60 | int bgfx_init(bgfx_io_t *io_p, /* io callback functions */ |
|---|
| 61 | bgfx_prot_t *prot_p /* allocated, initialized sgil_prot_t reference */ |
|---|
| 62 | ); |
|---|
| 63 | |
|---|
| 64 | /**************************************************************** |
|---|
| 65 | * global sgil cleanup |
|---|
| 66 | * Free SGIL global resources. Should be called to cleanup all global resources |
|---|
| 67 | * allocated by SGIL. |
|---|
| 68 | ****************************************************************/ |
|---|
| 69 | void bgfx_done(); |
|---|
| 70 | |
|---|
| 71 | /**************************************************************** |
|---|
| 72 | * Initialize an SGIL surface |
|---|
| 73 | * Create an SGIL surface using the node_name passed. width and height can be 0 when |
|---|
| 74 | * creating surfaces with the SGL_SURF_FULLSCREEN flag. All flags other than |
|---|
| 75 | * SGL_SURF_NONE can only be used when creating on-screen surfaces. Surfaces are |
|---|
| 76 | * CLUT8 (8-bpp) surfaces by default but can also be 8888 ARGB (32-bpp) |
|---|
| 77 | * when SGL_SURF_RGB is ored with the flags. |
|---|
| 78 | ****************************************************************/ |
|---|
| 79 | int bgfx_create(bgfx_surf_p p, /* pointer to allocated, uninitialized surface structure */ |
|---|
| 80 | uint16_t width, /* width in pixels of the surface */ |
|---|
| 81 | uint16_t height, /* height in pixels of the surface */ |
|---|
| 82 | uint8_t *ptr, /* ptr to surface memory or NULL if memory needs to be allocated */ |
|---|
| 83 | uint16_t pitch, /* number of bytes per row in the surface */ |
|---|
| 84 | bgfx_palette_t *palette, /* a palette to copy or NULL to use default */ |
|---|
| 85 | uint32_t flags /* flags that define the type of surface to create */ |
|---|
| 86 | ); |
|---|
| 87 | |
|---|
| 88 | /**************************************************************** |
|---|
| 89 | * Free an SGIL surface |
|---|
| 90 | * Should be called to free up resources associated with the surface. |
|---|
| 91 | ****************************************************************/ |
|---|
| 92 | void bgfx_destroy(bgfx_surf_p p /* pointer to initialized surface structure */ |
|---|
| 93 | ); |
|---|
| 94 | |
|---|
| 95 | /**************************************************************** |
|---|
| 96 | * Get surface width,height and flags. |
|---|
| 97 | * Get surface information including width height and flags. |
|---|
| 98 | ****************************************************************/ |
|---|
| 99 | void bgfx_get_info(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 100 | uint16_t *w, /* surface width in pixels */ |
|---|
| 101 | uint16_t *h, /* surface height in pixels */ |
|---|
| 102 | uint16_t *pitch, /* surface width in bytes */ |
|---|
| 103 | uint32_t *flags /* surface flags (see bgfx_create) */ |
|---|
| 104 | ); |
|---|
| 105 | |
|---|
| 106 | /**************************************************************** |
|---|
| 107 | * Get the surface palette (CLUT). |
|---|
| 108 | * Get a copy of the current surface palette. |
|---|
| 109 | ****************************************************************/ |
|---|
| 110 | void bgfx_get_palette(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 111 | bgfx_palette_t *palette_p /* palette to copy surface palette to (CLUT8 ARGB8888)*/ |
|---|
| 112 | ); |
|---|
| 113 | |
|---|
| 114 | /**************************************************************** |
|---|
| 115 | * Set the surface palette (CLUT). |
|---|
| 116 | * Set the surface palette and update the hardware palette. |
|---|
| 117 | ****************************************************************/ |
|---|
| 118 | void bgfx_set_palette(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 119 | bgfx_palette_t *palette_p /* palette to copy to surface palette (CLUT8 ARGB8888)*/ |
|---|
| 120 | ); |
|---|
| 121 | |
|---|
| 122 | /**************************************************************** |
|---|
| 123 | * Set the pixel value. |
|---|
| 124 | * Set the pixel value at x,y location to the value c. |
|---|
| 125 | * When the surface is a CLUT8 surface c should be an 8-bit |
|---|
| 126 | * value. When the surface is an 8888 ARGB surface c should be |
|---|
| 127 | * a 32-bit value. This avoids logic for performing |
|---|
| 128 | * color reduction or format translations. |
|---|
| 129 | ****************************************************************/ |
|---|
| 130 | void bgfx_set_pixel(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 131 | uint16_t x, /* horizontal location in pixels (top/left 0,0) */ |
|---|
| 132 | uint16_t y, /* vertical location in pixels */ |
|---|
| 133 | bgfx_pixel c /* pixel value to set */ |
|---|
| 134 | ); |
|---|
| 135 | |
|---|
| 136 | /**************************************************************** |
|---|
| 137 | * Get the pixel value. |
|---|
| 138 | * Get the pixel value at x,y location. |
|---|
| 139 | * When the surface is a CLUT8 surface c will be an 8-bit |
|---|
| 140 | * value. When the surface is an 8888 ARGB surface c will be |
|---|
| 141 | * a 32-bit value. This avoids logic for performing |
|---|
| 142 | * color reduction or format translations. |
|---|
| 143 | ****************************************************************/ |
|---|
| 144 | bgfx_pixel bgfx_get_pixel(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 145 | uint16_t x, /* horizontal location in pixels (top/left 0,0) */ |
|---|
| 146 | uint16_t y /* vertical location in pixels */ |
|---|
| 147 | ); |
|---|
| 148 | |
|---|
| 149 | /**************************************************************** |
|---|
| 150 | * Draw a horizontal line. |
|---|
| 151 | * Draw a single pixel wide horizontal line with the pixel value. |
|---|
| 152 | ****************************************************************/ |
|---|
| 153 | void bgfx_h_draw_line(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 154 | uint16_t x1, /* horizontal line starting point */ |
|---|
| 155 | uint16_t x2, /* horizontal line ending point */ |
|---|
| 156 | uint16_t y, /* vertical line location */ |
|---|
| 157 | bgfx_pixel c /* pixel value to set */ |
|---|
| 158 | ); |
|---|
| 159 | |
|---|
| 160 | /**************************************************************** |
|---|
| 161 | * Draw a vertical line. |
|---|
| 162 | * Draw a single pixel wide vertical line with the pixel value. |
|---|
| 163 | ****************************************************************/ |
|---|
| 164 | void bgfx_v_draw_line(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 165 | uint16_t x, /* horizontal location in pixels (top/left 0,0) */ |
|---|
| 166 | uint16_t y1, /* vertical line starting point */ |
|---|
| 167 | uint16_t y2, /* vertical line end point */ |
|---|
| 168 | bgfx_pixel c /* pixel value to set */ |
|---|
| 169 | ); |
|---|
| 170 | |
|---|
| 171 | /**************************************************************** |
|---|
| 172 | * Fill a rectanglular region of the surface. |
|---|
| 173 | * Fill the region with with the pixel value. |
|---|
| 174 | ****************************************************************/ |
|---|
| 175 | void bgfx_fill_rect(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 176 | uint16_t x, /* rectangle left location in pixels */ |
|---|
| 177 | uint16_t y, /* rectangle top location in pixels */ |
|---|
| 178 | uint16_t w, /* rectangle width in pixels */ |
|---|
| 179 | uint16_t h, /* rectangle height in pixels */ |
|---|
| 180 | bgfx_pixel c /* pixel value to set */ |
|---|
| 181 | ); |
|---|
| 182 | |
|---|
| 183 | /**************************************************************** |
|---|
| 184 | * Draw the UNI string. |
|---|
| 185 | * Draw the UNI string at the x,y location with |
|---|
| 186 | * the pixel value. Use the functions in sgl_font.h to initialize |
|---|
| 187 | * the font structure. Using preloaded cached fonts will result in best |
|---|
| 188 | * drawing performance. When using 8 -bit grayscale fonts rather than mono fonts |
|---|
| 189 | * the pixel value will be used when the grayscale value is >=75%, c-1 for >= 50% |
|---|
| 190 | * and c-2 for >= 25%. |
|---|
| 191 | ****************************************************************/ |
|---|
| 192 | void bgfx_draw_text(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 193 | uint16_t x, /* horizontal location in pixels (top/left 0,0) */ |
|---|
| 194 | uint16_t y, /* vertical location in pixels */ |
|---|
| 195 | const unsigned long *str_p, /* array of 32-bit unicode characters */ |
|---|
| 196 | int str_len, /* Length of character array */ |
|---|
| 197 | bgfx_font_t *font_p, /* initialized font structure (see sgl_font.h) */ |
|---|
| 198 | bgfx_pixel c, /* pixel value to set */ |
|---|
| 199 | bgfx_text_style style /* Text style */ |
|---|
| 200 | ); |
|---|
| 201 | /**************************************************************** |
|---|
| 202 | * Draw the UNI string. |
|---|
| 203 | * Draw the UNI string at the x,y location with |
|---|
| 204 | * the pixel value. Use the functions in sgl_font.h to initialize |
|---|
| 205 | * the font structure. Using preloaded cached fonts will result in best |
|---|
| 206 | * drawing performance. When using 8 -bit grayscale fonts rather than mono fonts |
|---|
| 207 | * the pixel value will be used when the grayscale value is >=75%, c-1 for >= 50% |
|---|
| 208 | * and c-2 for >= 25%. |
|---|
| 209 | ****************************************************************/ |
|---|
| 210 | void bgfx_draw_text_box(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 211 | uint16_t x, /* horizontal location in pixels (top/left 0,0) */ |
|---|
| 212 | uint16_t y, /* vertical location in pixels */ |
|---|
| 213 | uint16_t width, /* horizontal size in pixels (top/left 0,0) */ |
|---|
| 214 | uint16_t height, /* vertical size in pixels */ |
|---|
| 215 | const unsigned long *str_p, /* array of 32-bit unicode characters */ |
|---|
| 216 | int str_len, /* Length of character array */ |
|---|
| 217 | bgfx_font_t *font_p,/* initialized font structure (see sgl_font.h) */ |
|---|
| 218 | bgfx_pixel c, /* pixel value to set */ |
|---|
| 219 | uint16_t line_spacing /* Space between lines */ |
|---|
| 220 | ); |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | /**************************************************************** |
|---|
| 224 | * Draw bitmap from a file. |
|---|
| 225 | ****************************************************************/ |
|---|
| 226 | int bgfx_render_file(bgfx_surf_p p, /* pointer to initialized surface structure */ |
|---|
| 227 | uint16_t x, /* horizontal location in pixels (top/left 0,0) */ |
|---|
| 228 | uint16_t y, /* vertical location in pixels */ |
|---|
| 229 | void *file_p, /* open CLUT8 binary file point to render directly to the surface */ |
|---|
| 230 | int set_palette /* use this CLUT as the global palette */ |
|---|
| 231 | ); |
|---|
| 232 | |
|---|
| 233 | /**************************************************************** |
|---|
| 234 | * Copy from one surface to the other. |
|---|
| 235 | * Copy the source surface to the destination at x,y location (top/left) |
|---|
| 236 | * The source colorkey value will be used. The source must be a CLUT8 surface |
|---|
| 237 | * but the destination can be CLUT8 or RGB. |
|---|
| 238 | ****************************************************************/ |
|---|
| 239 | int bgfx_blit(bgfx_surf_p p_src, /* pointer to initialized source surface structure */ |
|---|
| 240 | bgfx_surf_p p_dst, /* pointer to initialized destination surface structure */ |
|---|
| 241 | uint16_t x, /* horizontal location in pixels (top/left 0,0) */ |
|---|
| 242 | uint16_t y /* vertical location in pixels */ |
|---|
| 243 | ); |
|---|
| 244 | |
|---|
| 245 | /**************************************************************** |
|---|
| 246 | * Copy a rectangle area from one surface to the other. |
|---|
| 247 | * Copy the source surface at (sx,sy) to the destination at (dx,dy) |
|---|
| 248 | * The source colorkey value will be used. The source must be a CLUT8 surface |
|---|
| 249 | * but the destination can be CLUT8 or RGB. |
|---|
| 250 | ****************************************************************/ |
|---|
| 251 | int bgfx_blit_rect(bgfx_surf_p p_src, /* pointer to initialized source surface structure */ |
|---|
| 252 | bgfx_surf_p p_dst, /* pointer to initialized destination surface structure */ |
|---|
| 253 | uint16_t sx, /* source horizontal location in pixels */ |
|---|
| 254 | uint16_t sy, /* source vertical location in pixels */ |
|---|
| 255 | uint16_t dx, /* destination horizontal location in pixels */ |
|---|
| 256 | uint16_t dy, /* destination vertical location in pixels */ |
|---|
| 257 | uint16_t sw, /* source width in pixel */ |
|---|
| 258 | uint16_t sh); /* source height in pixel */ |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | #ifdef __cplusplus |
|---|
| 264 | } |
|---|
| 265 | #endif |
|---|
| 266 | |
|---|
| 267 | #endif /* __bgfx_h__ */ |
|---|
| 268 | |
|---|