graphics_x_private.h (10797B)
1 /* 2 Copyright (c) 2012, Broadcom Europe Ltd 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are met: 7 * Redistributions of source code must retain the above copyright 8 notice, this list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above copyright 10 notice, this list of conditions and the following disclaimer in the 11 documentation and/or other materials provided with the distribution. 12 * Neither the name of the copyright holder nor the 13 names of its contributors may be used to endorse or promote products 14 derived from this software without specific prior written permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 // Graphics library for VG 29 30 #ifndef GRAPHICS_X_PRIVATE_H 31 #define GRAPHICS_X_PRIVATE_H 32 33 #define VCOS_LOG_CATEGORY (&gx_log_cat) 34 35 #include "EGL/egl.h" 36 #include "EGL/eglext.h" 37 #include "VG/openvg.h" 38 #include "VG/vgu.h" 39 40 #include "vgfont.h" 41 #include "bcm_host.h" 42 43 extern VCOS_LOG_CAT_T gx_log_cat; 44 45 #define LOG_ERR( fmt, arg... ) vcos_log_error( "%s:%d " fmt, __func__, __LINE__, ##arg) 46 47 #define GX_ERROR(format, arg...) if (1) {} else printf( format "\n", ##arg) 48 #define GX_LOG(format, arg...) if (1) {} else printf( format "\n", ##arg) 49 #define GX_TRACE(format, arg...) if (1) {} else printf( format "\n", ##arg) 50 51 typedef struct 52 { 53 EGL_DISPMANX_WINDOW_T egl_win; 54 } GX_NATIVE_WINDOW_T; 55 56 typedef enum 57 { 58 GX_TOP_BOTTOM, 59 GX_BOTTOM_TOP, 60 } GX_RASTER_ORDER_T; 61 62 typedef struct {} GX_PAINT_T; 63 64 typedef struct GX_CLIENT_STATE_T GX_CLIENT_STATE_T; 65 typedef struct { 66 EGLDisplay disp; 67 } GX_DISPLAY_T; 68 69 struct GX_DISPLAY_T 70 { 71 EGLDisplay disp; 72 }; 73 74 typedef enum 75 { 76 GX_WINDOW, GX_PIXMAP, GX_PBUFFER 77 } GX_RES_TYPE; 78 79 #define RES_MAGIC ('G'<<24|'X'<<16|'R'<<8|'S'<<0) 80 #define GX_PRIV_FLAG_FLIP (1<<0) 81 82 /** 83 * Structure encapsulating the per-surface state. 84 ***********************************************************/ 85 typedef struct GRAPHICS_RESOURCE_HANDLE_TABLE_T 86 { 87 union 88 { 89 GX_NATIVE_WINDOW_T native_window; 90 VGImage pixmap; 91 } u; 92 GX_RES_TYPE type; 93 94 uint32_t magic; /** To work around broken create interface */ 95 int context_bound; 96 const char *last_caller; 97 EGLSurface surface; 98 EGLContext context; 99 EGLConfig config; 100 uint32_t screen_id; /** 0-LCD, etc */ 101 uint16_t width; 102 uint16_t height; 103 GRAPHICS_RESOURCE_TYPE_T restype; 104 VC_DISPMAN_TRANSFORM_T transform; 105 106 VC_RECT_T dest; /** destination rectangle in use, for book-keeping */ 107 108 VGfloat alpha; 109 } GRAPHICS_RESOURCE_HANDLE_TABLE_T; 110 111 /** 112 * Structure used to store an EGL client state. 113 ***********************************************************/ 114 struct GX_CLIENT_STATE_T 115 { 116 EGLSurface read_surface; 117 EGLSurface draw_surface; 118 EGLContext context; 119 EGLenum api; 120 GRAPHICS_RESOURCE_HANDLE res; 121 }; 122 123 /** 124 * \fixme add documentation 125 * 126 ***********************************************************/ 127 void gx_priv_init(void); 128 129 /** 130 * \fixme add documentation 131 * 132 ***********************************************************/ 133 void gx_priv_destroy(void); 134 135 /** 136 * \fixme add documentation 137 * 138 * @param col colour 139 * 140 * @param rgba OpenVG paint colour 141 * 142 ***********************************************************/ 143 void gx_priv_colour_to_paint(uint32_t col, VGfloat *rgba); 144 145 /** 146 * Save current EGL client state. 147 * 148 * @param state upon return, holds the saved EGL client state. 149 * 150 * @param res handle to the surface the EGL client state belongs to (may be <code>NULL</code>). 151 * 152 */ 153 void gx_priv_save(GX_CLIENT_STATE_T *state, GRAPHICS_RESOURCE_HANDLE res); 154 155 /** 156 * Restore current EGL client state. 157 * 158 * @param state the EGL client state to restore. 159 * 160 */ 161 void gx_priv_restore(GX_CLIENT_STATE_T *state); 162 163 /** 164 * Create a native window for a surface. 165 * 166 * @param screen_id \fixme 167 * 168 * @param w width of the window 169 * 170 * @param h height of the window 171 * 172 * @param type color/raster format of the resource 173 * 174 * @param win upon successful return, holds a handle to the native window 175 * 176 * @param cookie \fixme 177 * 178 * @return VCOS_SUCCESS on success, or error code. 179 */ 180 int gx_priv_create_native_window(uint32_t screen_id, 181 uint32_t w, uint32_t h, 182 GRAPHICS_RESOURCE_TYPE_T type, 183 GX_NATIVE_WINDOW_T *win, 184 void **cookie); 185 186 /** 187 * Destroy native window bound to surface. 188 * 189 * @param res Handle to surface. 190 * 191 */ 192 void gx_priv_destroy_native_window(GRAPHICS_RESOURCE_HANDLE_TABLE_T *res); 193 194 /** 195 * Initialise font from the given directory. 196 * 197 * @param font_dir path to font 198 * 199 * \fixme only supports Vera.tff at the moment? 200 * 201 * @return VCOS_SUCCESS on success, or error code. 202 */ 203 VCOS_STATUS_T gx_priv_font_init(const char *font_dir); 204 205 /** 206 * \fixme add documentation 207 * 208 ***********************************************************/ 209 void gx_priv_font_term(void); 210 211 /** 212 * Fill an area of a surface with a single colour. 213 * 214 * @param res Handle to surface. 215 * 216 * @param x x-offset of area to fill 217 * 218 * @param y y-offset of area to fill 219 * 220 * @param width width of area to fill 221 * 222 * @param height height of area to fill 223 * 224 * @param fill_colour fill colour 225 * 226 ***********************************************************/ 227 VCOS_STATUS_T gx_priv_resource_fill(GRAPHICS_RESOURCE_HANDLE res, 228 uint32_t x, 229 uint32_t y, 230 uint32_t width, 231 uint32_t height, 232 uint32_t fill_colour ); 233 234 /** 235 * Render text into a surface 236 * 237 * @param disp Handle to display. 238 * 239 * @param res Handle to surface. 240 * 241 * @param x x-offset 242 * 243 * @param y y-offset 244 * 245 * @param width bounding rectangle width 246 * 247 * @param height bounding rectangle height 248 * 249 * @param fg_colour foreground color 250 * 251 * @param bg_colour background color 252 * 253 * @param text text to render 254 * 255 * @param text_length length of text 256 * 257 * @param text_size size of text 258 * 259 ***********************************************************/ 260 VCOS_STATUS_T gx_priv_render_text( GX_DISPLAY_T *disp, 261 GRAPHICS_RESOURCE_HANDLE res, 262 int32_t x, 263 int32_t y, 264 uint32_t width, 265 uint32_t height, 266 uint32_t fg_colour, 267 uint32_t bg_colour, 268 const char *text, 269 uint32_t text_length, 270 uint32_t text_size ); 271 272 /** 273 * Flush a surface. 274 * 275 * @param res Handle to surface. 276 * 277 ***********************************************************/ 278 void gx_priv_flush(GRAPHICS_RESOURCE_HANDLE res); 279 280 /** 281 * Called after the EGL/VG initialisation of a window has completed 282 * following its creation. 283 * 284 * @param res ??? 285 * 286 * @param cookie ??? 287 * 288 ***********************************************************/ 289 void gx_priv_finish_native_window(GRAPHICS_RESOURCE_HANDLE_TABLE_T *res, 290 void *cookie); 291 292 /** 293 * Flush font cache. 294 * 295 ***********************************************************/ 296 void gx_font_cache_flush(void); 297 298 /** 299 * Read a bitmap (.BMP) image from the given file. 300 * 301 * @param filename filename (must not be <code>NULL</code>). 302 * 303 * @param width holds the width of the image upon return. 304 * 305 * @param height holds the height of the image upon return. 306 * 307 * @param pitch_bytes holds the pitch of the image data (in bytes) upon return. 308 * 309 * @param restype holds the type of the image upon return. 310 * 311 * @param vg_format holds the OpenVG image format upon return. 312 * 313 * @param flags holds flags describing image properties upon return. 314 * 315 * @param image_data_size holds size of the image data upon return. 316 * 317 * @param pimage_data holds the image data buffer upon return (must not be <code>NULL</code>), 318 * the caller is responsible for releasing the buffer afterwards. 319 * 320 * @return 0 if success, non-zero otherwise (in which case the output parameters 321 * may be invalid). 322 * 323 ***********************************************************/ 324 int gx_priv_read_bmp(const char *file_name, 325 uint32_t *width, uint32_t *height, uint32_t *pitch_bytes, 326 GRAPHICS_RESOURCE_TYPE_T *restype, 327 VGImageFormat *vg_format, 328 uint32_t *flags, 329 uint32_t *image_data_size, 330 void **pimage_data); 331 332 /** 333 * Read a Targa (.TGA) image from the given file. 334 * 335 * @param filename filename (must not be <code>NULL</code>). 336 * 337 * @param width holds the width of the image upon return. 338 * 339 * @param height holds the height of the image upon return. 340 * 341 * @param pitch_bytes holds the pitch of the image data (in bytes) upon return. 342 * 343 * @param restype holds the type of the image upon return. 344 * 345 * @param vg_format holds the OpenVG image format upon return. 346 * 347 * @param flags holds flags describing image properties upon return. 348 * 349 * @param image_data_size holds size of the image data upon return. 350 * 351 * @param pimage_data holds the image data buffer upon return (must not be <code>NULL</code>), 352 * the caller is responsible for releasing the memory afterwards. 353 * 354 * @return 0 if success, non-zero otherwise (in which case the output parameters. 355 * may be invalid). 356 * 357 ***********************************************************/ 358 int gx_priv_read_tga(const char *file_name, 359 uint32_t *width, uint32_t *height, uint32_t *pitch_bytes, 360 GRAPHICS_RESOURCE_TYPE_T *restype, 361 VGImageFormat *vg_format, 362 uint32_t *flags, 363 uint32_t *image_data_size, 364 void **pimage_data); 365 366 #endif