| 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: sgil platform definitions |
|---|
| 12 | ** |
|---|
| 13 | ** Created: 8/22/2002 by Jeffrey P. Fisher |
|---|
| 14 | ** |
|---|
| 15 | ** |
|---|
| 16 | ** |
|---|
| 17 | ****************************************************************/ |
|---|
| 18 | |
|---|
| 19 | /** include files **/ |
|---|
| 20 | #include "bgfx_defs.h" |
|---|
| 21 | |
|---|
| 22 | /** local types, definitions and data **/ |
|---|
| 23 | static int g_bgfx_debug_level = 1; |
|---|
| 24 | static bgfx_io_t *g_p_io = NULL; |
|---|
| 25 | static bgfx_prot_t *g_prot_t = NULL; |
|---|
| 26 | static bgfx_hw_t *g_hw_t = NULL; |
|---|
| 27 | /****************************************************************} |
|---|
| 28 | * INPUTS: none |
|---|
| 29 | * OUTPUTS: none |
|---|
| 30 | * RETURNS: debug level |
|---|
| 31 | * FUNCTION: get the debug level |
|---|
| 32 | * |
|---|
| 33 | ****************************************************************/ |
|---|
| 34 | |
|---|
| 35 | int bgfx_get_debug_level() |
|---|
| 36 | { |
|---|
| 37 | return g_bgfx_debug_level; |
|---|
| 38 | } |
|---|
| 39 | /****************************************************************} |
|---|
| 40 | * INPUTS: debug level |
|---|
| 41 | * OUTPUTS: none |
|---|
| 42 | * RETURNS: none |
|---|
| 43 | * FUNCTION: set the debug level |
|---|
| 44 | * |
|---|
| 45 | ****************************************************************/ |
|---|
| 46 | void bgfx_set_debug_level(int level) |
|---|
| 47 | { |
|---|
| 48 | g_bgfx_debug_level = level; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | /**************************************************************** |
|---|
| 53 | * INPUTS: none |
|---|
| 54 | * OUTPUTS: none |
|---|
| 55 | * RETURNS: none |
|---|
| 56 | * FUNCTION: Called to protect internal global structures. Supplied |
|---|
| 57 | * callback function should function as a mutual exclusion |
|---|
| 58 | * semaphore. |
|---|
| 59 | ****************************************************************/ |
|---|
| 60 | void bgfx_lock(void) |
|---|
| 61 | { |
|---|
| 62 | if (g_prot_t) |
|---|
| 63 | { |
|---|
| 64 | g_prot_t->lock(); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | /**************************************************************** |
|---|
| 68 | * INPUTS: none |
|---|
| 69 | * OUTPUTS: none |
|---|
| 70 | * RETURNS: none |
|---|
| 71 | * FUNCTION: Called to release protection of internal global structures. |
|---|
| 72 | * Supplied callback function should release mutual exclusion |
|---|
| 73 | * semaphore. |
|---|
| 74 | ****************************************************************/ |
|---|
| 75 | void bgfx_unlock(void) |
|---|
| 76 | { |
|---|
| 77 | if (g_prot_t) |
|---|
| 78 | { |
|---|
| 79 | g_prot_t->unlock(); |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | /**************************************************************** |
|---|
| 84 | * INPUTS: same as standard file IO (see fread) |
|---|
| 85 | * OUTPUTS: none |
|---|
| 86 | * RETURNS: none |
|---|
| 87 | * FUNCTION: Read data from the file stream. Supplied callback function |
|---|
| 88 | * should load count elements of size bytes into the supplied |
|---|
| 89 | * buffer and return the number of bytes actualy loaded or |
|---|
| 90 | * value < 0 when an error occurs. |
|---|
| 91 | * |
|---|
| 92 | * |
|---|
| 93 | ****************************************************************/ |
|---|
| 94 | long bgfx_read(void *buffer, long size, long count, void *fp ) |
|---|
| 95 | { |
|---|
| 96 | if (!g_p_io || !g_p_io->read) |
|---|
| 97 | return -1; |
|---|
| 98 | |
|---|
| 99 | return g_p_io->read(buffer,size,count,fp); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | /**************************************************************** |
|---|
| 103 | * INPUTS: same as standard file IO (see fread) |
|---|
| 104 | * OUTPUTS: none |
|---|
| 105 | * RETURNS: none |
|---|
| 106 | * FUNCTION: Read data from the file stream. Supplied callback function |
|---|
| 107 | * should load count elements of size bytes into the supplied |
|---|
| 108 | * buffer and return the number of bytes actualy loaded or |
|---|
| 109 | * value < 0 when an error occurs. |
|---|
| 110 | * |
|---|
| 111 | * |
|---|
| 112 | ****************************************************************/ |
|---|
| 113 | unsigned int bgfx_tell(void *fp ) |
|---|
| 114 | { |
|---|
| 115 | if (!g_p_io || !g_p_io->tell) |
|---|
| 116 | return -1; |
|---|
| 117 | return g_p_io->tell(fp); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | /**************************************************************** |
|---|
| 121 | * INPUTS: same as standard file IO (see fseek) |
|---|
| 122 | * OUTPUTS: none |
|---|
| 123 | * RETURNS: none |
|---|
| 124 | * FUNCTION: Set the current file pointer. (only uses SEEK_SET = 0) |
|---|
| 125 | * |
|---|
| 126 | * |
|---|
| 127 | ****************************************************************/ |
|---|
| 128 | int bgfx_set( void *fp,int offset, int whence) |
|---|
| 129 | { |
|---|
| 130 | if (!g_p_io || !g_p_io->set) |
|---|
| 131 | return -1; |
|---|
| 132 | return g_p_io->set(fp, offset, whence); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | /****************************************************************} |
|---|
| 136 | * INPUTS: io and protection function structures |
|---|
| 137 | * OUTPUTS: none |
|---|
| 138 | * RETURNS: non-zero on failure |
|---|
| 139 | * FUNCTION: initialize sgl, primarily for protection of freetype global |
|---|
| 140 | * structures. |
|---|
| 141 | * |
|---|
| 142 | ****************************************************************/ |
|---|
| 143 | void bgfx_config(bgfx_io_t *io_p,bgfx_prot_t *prot_p,bgfx_hw_t *hw_p) |
|---|
| 144 | { |
|---|
| 145 | g_p_io = io_p; |
|---|
| 146 | g_prot_t = prot_p; |
|---|
| 147 | g_hw_t = hw_p; |
|---|
| 148 | } |
|---|
| 149 | /****************************************************************} |
|---|
| 150 | * INPUTS: ptr - address to flush |
|---|
| 151 | * nbytes - number of bytes |
|---|
| 152 | * OUTPUTS: none |
|---|
| 153 | * RETURNS: none |
|---|
| 154 | * FUNCTION: Perform a cache flush for the address and size specified. |
|---|
| 155 | * |
|---|
| 156 | ****************************************************************/ |
|---|
| 157 | void bgfx_cacheflush(void *ptr,int nbytes) |
|---|
| 158 | { |
|---|
| 159 | /* not implemented in uclibc cacheflush(ptr,nbytes,DCACHE); |
|---|
| 160 | BROKEN syscall(__NR_cacheflush,ptr,nbytes,DCACHE); |
|---|
| 161 | */ |
|---|
| 162 | } |
|---|
| 163 | int bgfx_hw_fill( void *surf, bgfx_rect *r, uint32_t pixel ) |
|---|
| 164 | { |
|---|
| 165 | if (!g_hw_t || !g_hw_t->fill_cb) |
|---|
| 166 | { |
|---|
| 167 | return -1; |
|---|
| 168 | } |
|---|
| 169 | return g_hw_t->fill_cb(surf,r,pixel); |
|---|
| 170 | } |
|---|
| 171 | int bgfx_hw_blit( void *src_surf, bgfx_rect *src_r, |
|---|
| 172 | void *dst_surf, bgfx_rect *dst_r, |
|---|
| 173 | void *out_surf, bgfx_rect *out_r ) |
|---|
| 174 | { |
|---|
| 175 | if (!g_hw_t || !g_hw_t->blit_cb) |
|---|
| 176 | { |
|---|
| 177 | return -1; |
|---|
| 178 | } |
|---|
| 179 | return g_hw_t->blit_cb(src_surf,src_r,dst_surf,dst_r,out_surf,out_r); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | int bgfx_hw_surf_create(uint32_t width, |
|---|
| 183 | uint32_t height, |
|---|
| 184 | int format, |
|---|
| 185 | uint8_t **mem, |
|---|
| 186 | uint32_t *pitch, |
|---|
| 187 | void **p_settop_surf ) |
|---|
| 188 | { |
|---|
| 189 | if (!g_hw_t || !g_hw_t->create_cb) |
|---|
| 190 | { |
|---|
| 191 | return -1; |
|---|
| 192 | } |
|---|
| 193 | return g_hw_t->create_cb(width, height, format, mem, pitch, p_settop_surf); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | void bgfx_hw_surf_destroy(void *p_settop_surf ) |
|---|
| 197 | { |
|---|
| 198 | if (!g_hw_t || !g_hw_t->destroy_cb) |
|---|
| 199 | { |
|---|
| 200 | return; |
|---|
| 201 | } |
|---|
| 202 | g_hw_t->destroy_cb(p_settop_surf); |
|---|
| 203 | } |
|---|
| 204 | bgfx_hw_t *bgfx_hw_get_fcn() |
|---|
| 205 | { |
|---|
| 206 | return g_hw_t; |
|---|
| 207 | } |
|---|