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