Changeset 587b4cb in mainline
- Timestamp:
- 2019-10-29T02:01:45Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 22faaf2
- Parents:
- 0008c0f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
r0008c0f r587b4cb 48 48 #include <window.h> 49 49 50 /** Clear screen. 51 * 52 * @param gc Graphic context 53 * @param w Screen width 54 * @param h Screen height 55 */ 56 static errno_t clear_scr(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 57 { 58 gfx_color_t *color = NULL; 59 gfx_rect_t rect; 60 errno_t rc; 61 62 rc = gfx_color_new_rgb_i16(0, 0, 0, &color); 63 if (rc != EOK) 64 goto error; 65 66 rc = gfx_set_color(gc, color); 67 if (rc != EOK) 68 goto error; 69 70 rect.p0.x = 0; 71 rect.p0.y = 0; 72 rect.p1.x = w; 73 rect.p1.y = h; 74 75 rc = gfx_fill_rect(gc, &rect); 76 if (rc != EOK) 77 goto error; 78 79 gfx_color_delete(color); 80 return EOK; 81 error: 82 if (color != NULL) 83 gfx_color_delete(color); 84 return rc; 85 } 86 50 87 /** Run rectangle demo on a graphic context. 51 88 * … … 60 97 int i, j; 61 98 errno_t rc; 99 100 rc = clear_scr(gc, w, h); 101 if (rc != EOK) 102 return rc; 62 103 63 104 for (j = 0; j < 10; j++) { … … 90 131 } 91 132 92 /** Run bitmap demo on a graphic context. 93 * 94 * @param gc Graphic context 95 * @param w Width 96 * @param h Height 97 */ 98 static errno_t demo_bitmap(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 99 { 100 gfx_bitmap_t *bitmap; 101 gfx_bitmap_params_t params; 133 /** Fill bitmap with tartan pattern. 134 * 135 * @param bitmap Bitmap 136 * @param w Bitmap width 137 * @param h Bitmap height 138 * @return EOK on success or an error code 139 */ 140 static errno_t bitmap_tartan(gfx_bitmap_t *bitmap, gfx_coord_t w, gfx_coord_t h) 141 { 142 int i, j; 143 pixelmap_t pixelmap; 102 144 gfx_bitmap_alloc_t alloc; 103 int i, j; 104 gfx_coord2_t offs; 105 gfx_rect_t srect; 106 errno_t rc; 107 pixelmap_t pixelmap; 108 109 params.rect.p0.x = 0; 110 params.rect.p0.y = 0; 111 params.rect.p1.x = w; 112 params.rect.p1.y = h; 113 114 rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap); 115 if (rc != EOK) 116 return rc; 145 errno_t rc; 117 146 118 147 rc = gfx_bitmap_get_alloc(bitmap, &alloc); … … 120 149 return rc; 121 150 122 /* Fill bitmap with something.In absence of anything else, use pixelmap */151 /* In absence of anything else, use pixelmap */ 123 152 pixelmap.width = w; 124 153 pixelmap.height = h; … … 133 162 } 134 163 164 return EOK; 165 } 166 167 /** Fill bitmap with moire pattern. 168 * 169 * @param bitmap Bitmap 170 * @param w Bitmap width 171 * @param h Bitmap height 172 * @return EOK on success or an error code 173 */ 174 static errno_t bitmap_moire(gfx_bitmap_t *bitmap, gfx_coord_t w, gfx_coord_t h) 175 { 176 int i, j; 177 int k; 178 pixelmap_t pixelmap; 179 gfx_bitmap_alloc_t alloc; 180 errno_t rc; 181 182 rc = gfx_bitmap_get_alloc(bitmap, &alloc); 183 if (rc != EOK) 184 return rc; 185 186 /* In absence of anything else, use pixelmap */ 187 pixelmap.width = w; 188 pixelmap.height = h; 189 pixelmap.data = alloc.pixels; 190 191 for (i = 0; i < w; i++) { 192 for (j = 0; j < h; j++) { 193 k = i * i + j * j; 194 pixelmap_put_pixel(&pixelmap, i, j, 195 PIXEL(255, k, k, k)); 196 } 197 } 198 199 return EOK; 200 } 201 202 /** Run bitmap demo on a graphic context. 203 * 204 * @param gc Graphic context 205 * @param w Width 206 * @param h Height 207 */ 208 static errno_t demo_bitmap(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 209 { 210 gfx_bitmap_t *bitmap; 211 gfx_bitmap_params_t params; 212 int i, j; 213 gfx_coord2_t offs; 214 gfx_rect_t srect; 215 errno_t rc; 216 217 rc = clear_scr(gc, w, h); 218 if (rc != EOK) 219 return rc; 220 221 params.rect.p0.x = 0; 222 params.rect.p0.y = 0; 223 params.rect.p1.x = w; 224 params.rect.p1.y = h; 225 226 rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap); 227 if (rc != EOK) 228 return rc; 229 230 rc = bitmap_tartan(bitmap, w, h); 231 if (rc != EOK) 232 goto error; 233 135 234 for (j = 0; j < 10; j++) { 136 235 for (i = 0; i < 5; i++) { … … 139 238 srect.p1.x = srect.p0.x + rand() % (w - srect.p0.x); 140 239 srect.p1.y = srect.p0.y + rand() % (h - srect.p0.y); 141 offs.x = rand() % (w - srect.p1.x);142 offs.y = rand() % (h - srect.p1.y);143 240 offs.x = 0; 144 241 offs.y = 0; … … 147 244 if (rc != EOK) 148 245 goto error; 149 fibril_usleep( 500 * 1000);246 fibril_usleep(250 * 1000); 150 247 } 151 248 } … … 159 256 } 160 257 161 /** Run demo loopon a graphic context.258 /** Run second bitmap demo on a graphic context. 162 259 * 163 260 * @param gc Graphic context … … 165 262 * @param h Height 166 263 */ 264 static errno_t demo_bitmap2(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 265 { 266 gfx_bitmap_t *bitmap; 267 gfx_bitmap_params_t params; 268 int i, j; 269 gfx_coord2_t offs; 270 errno_t rc; 271 272 rc = clear_scr(gc, w, h); 273 if (rc != EOK) 274 return rc; 275 276 params.rect.p0.x = 0; 277 params.rect.p0.y = 0; 278 params.rect.p1.x = 40; 279 params.rect.p1.y = 20; 280 281 rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap); 282 if (rc != EOK) 283 return rc; 284 285 rc = bitmap_moire(bitmap, 40, 20); 286 if (rc != EOK) 287 goto error; 288 289 for (j = 0; j < 10; j++) { 290 for (i = 0; i < 10; i++) { 291 offs.x = rand() % (w - 40); 292 offs.y = rand() % (h - 20); 293 294 rc = gfx_bitmap_render(bitmap, NULL, &offs); 295 if (rc != EOK) 296 goto error; 297 } 298 299 fibril_usleep(500 * 1000); 300 } 301 302 gfx_bitmap_destroy(bitmap); 303 304 return EOK; 305 error: 306 gfx_bitmap_destroy(bitmap); 307 return rc; 308 } 309 310 /** Run demo loop on a graphic context. 311 * 312 * @param gc Graphic context 313 * @param w Width 314 * @param h Height 315 */ 167 316 static errno_t demo_loop(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 168 317 { … … 175 324 176 325 rc = demo_bitmap(gc, w, h); 326 if (rc != EOK) 327 return rc; 328 329 rc = demo_bitmap2(gc, w, h); 177 330 if (rc != EOK) 178 331 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.