Changeset 0008c0f in mainline for uspace/lib/ipcgfx/src/server.c
- Timestamp:
- 2019-10-26T23:30:51Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 587b4cb
- Parents:
- 7b882c1f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ipcgfx/src/server.c
r7b882c1f r0008c0f 36 36 */ 37 37 38 #include <as.h> 38 39 #include <errno.h> 40 #include <gfx/bitmap.h> 39 41 #include <gfx/color.h> 40 42 #include <gfx/render.h> … … 43 45 #include <ipcgfx/server.h> 44 46 #include <stdint.h> 45 47 #include <stdlib.h> 46 48 #include <stdio.h> 47 49 48 #include <bd_srv.h> 49 50 static void gc_set_rgb_color_srv(gfx_context_t *gc, ipc_call_t *call) 50 #include "../private/server.h" 51 52 static ipc_gc_srv_bitmap_t *gc_bitmap_lookup(ipc_gc_srv_t *, sysarg_t); 53 54 static void gc_set_rgb_color_srv(ipc_gc_srv_t *srvgc, ipc_call_t *call) 51 55 { 52 56 uint16_t r, g, b; … … 64 68 } 65 69 66 rc = gfx_set_color( gc, color);70 rc = gfx_set_color(srvgc->gc, color); 67 71 async_answer_0(call, rc); 68 72 printf("done with rgb_color_srv\n"); 69 73 } 70 74 71 static void gc_fill_rect_srv( gfx_context_t *gc, ipc_call_t *call)75 static void gc_fill_rect_srv(ipc_gc_srv_t *srvgc, ipc_call_t *call) 72 76 { 73 77 gfx_rect_t rect; … … 79 83 rect.p1.y = ipc_get_arg4(call); 80 84 81 rc = gfx_fill_rect( gc, &rect);85 rc = gfx_fill_rect(srvgc->gc, &rect); 82 86 async_answer_0(call, rc); 83 87 } 84 88 89 static void gc_bitmap_create_srv(ipc_gc_srv_t *srvgc, ipc_call_t *icall) 90 { 91 gfx_bitmap_params_t params; 92 gfx_bitmap_alloc_t alloc; 93 gfx_bitmap_t *bitmap; 94 gfx_coord2_t dim; 95 ipc_gc_srv_bitmap_t *srvbmp = NULL; 96 ipc_call_t call; 97 size_t size; 98 unsigned int flags; 99 void *pixels; 100 errno_t rc; 101 102 if (!async_data_write_receive(&call, &size)) { 103 async_answer_0(&call, EREFUSED); 104 async_answer_0(icall, EREFUSED); 105 return; 106 } 107 108 if (size != sizeof(gfx_bitmap_params_t)) { 109 async_answer_0(&call, EINVAL); 110 async_answer_0(icall, EINVAL); 111 return; 112 } 113 114 rc = async_data_write_finalize(&call, ¶ms, size); 115 if (rc != EOK) { 116 async_answer_0(&call, rc); 117 async_answer_0(icall, rc); 118 return; 119 } 120 121 /* Bitmap dimensions */ 122 gfx_coord2_subtract(¶ms.rect.p1, ¶ms.rect.p0, &dim); 123 124 if (!async_share_out_receive(&call, &size, &flags)) { 125 async_answer_0(icall, EINVAL); 126 return; 127 } 128 129 /* Check size */ 130 if (size != PAGES2SIZE(SIZE2PAGES(dim.x * dim.y * sizeof(uint32_t)))) { 131 printf("size=%zu, expected=%zu\n", size, dim.x * dim.y * sizeof(uint32_t)); 132 async_answer_0(icall, EINVAL); 133 return; 134 } 135 136 rc = async_share_out_finalize(&call, &pixels); 137 if (rc != EOK || pixels == AS_MAP_FAILED) { 138 async_answer_0(icall, ENOMEM); 139 return; 140 } 141 142 alloc.pitch = dim.x * sizeof(uint32_t); 143 alloc.off0 = 0; 144 alloc.pixels = pixels; 145 146 srvbmp = calloc(1, sizeof(ipc_gc_srv_bitmap_t)); 147 if (srvbmp == NULL) { 148 as_area_destroy(pixels); 149 async_answer_0(icall, ENOMEM); 150 return; 151 } 152 153 rc = gfx_bitmap_create(srvgc->gc, ¶ms, &alloc, &bitmap); 154 if (rc != EOK) { 155 free(srvbmp); 156 as_area_destroy(pixels); 157 async_answer_0(icall, rc); 158 return; 159 } 160 161 srvbmp->srvgc = srvgc; 162 list_append(&srvbmp->lbitmaps, &srvgc->bitmaps); 163 srvbmp->bmp = bitmap; 164 srvbmp->bmp_id = srvgc->next_bmp_id++; 165 printf("gc_bitmap_create_srv: storing bmp_id=%lu\n", srvbmp->bmp_id); 166 167 async_answer_1(icall, EOK, srvbmp->bmp_id); 168 } 169 170 static void gc_bitmap_destroy_srv(ipc_gc_srv_t *srvgc, ipc_call_t *call) 171 { 172 sysarg_t bmp_id; 173 ipc_gc_srv_bitmap_t *bitmap; 174 errno_t rc; 175 176 bmp_id = ipc_get_arg1(call); 177 178 bitmap = gc_bitmap_lookup(srvgc, bmp_id); 179 if (bitmap == NULL) { 180 async_answer_0(call, ENOENT); 181 return; 182 } 183 184 rc = gfx_bitmap_destroy(bitmap->bmp); 185 if (rc != EOK) { 186 async_answer_0(call, rc); 187 return; 188 } 189 190 list_remove(&bitmap->lbitmaps); 191 free(bitmap); 192 193 async_answer_0(call, rc); 194 } 195 196 static void gc_bitmap_render_srv(ipc_gc_srv_t *srvgc, ipc_call_t *icall) 197 { 198 ipc_gc_srv_bitmap_t *bitmap; 199 sysarg_t bmp_id; 200 gfx_rect_t srect; 201 gfx_coord2_t offs; 202 ipc_call_t call; 203 size_t size; 204 errno_t rc; 205 206 if (!async_data_write_receive(&call, &size)) { 207 async_answer_0(&call, EREFUSED); 208 async_answer_0(icall, EREFUSED); 209 return; 210 } 211 212 if (size != sizeof(gfx_rect_t)) { 213 async_answer_0(&call, EINVAL); 214 async_answer_0(icall, EINVAL); 215 return; 216 } 217 218 rc = async_data_write_finalize(&call, &srect, size); 219 if (rc != EOK) { 220 async_answer_0(&call, rc); 221 async_answer_0(icall, rc); 222 return; 223 } 224 225 bmp_id = ipc_get_arg1(icall); 226 offs.x = ipc_get_arg2(icall); 227 offs.y = ipc_get_arg3(icall); 228 229 bitmap = gc_bitmap_lookup(srvgc, bmp_id); 230 if (bitmap == NULL) { 231 async_answer_0(icall, ENOENT); 232 return; 233 } 234 235 rc = gfx_bitmap_render(bitmap->bmp, &srect, &offs); 236 async_answer_0(icall, rc); 237 } 238 85 239 errno_t gc_conn(ipc_call_t *icall, gfx_context_t *gc) 86 240 { 241 ipc_gc_srv_t srvgc; 242 87 243 /* Accept the connection */ 88 244 async_accept_0(icall); 89 245 90 246 printf("gc_conn: accepted connection\n"); 247 srvgc.gc = gc; 248 list_initialize(&srvgc.bitmaps); 249 srvgc.next_bmp_id = 1; 91 250 92 251 while (true) { … … 104 263 case GC_SET_RGB_COLOR: 105 264 printf("gc_conn: set_rgb_color\n"); 106 gc_set_rgb_color_srv( gc, &call);265 gc_set_rgb_color_srv(&srvgc, &call); 107 266 printf("gc_conn: done set_rgb_color\n"); 108 267 break; 109 268 case GC_FILL_RECT: 110 269 printf("gc_conn: fill_rect_srv\n"); 111 gc_fill_rect_srv( gc, &call);270 gc_fill_rect_srv(&srvgc, &call); 112 271 printf("gc_conn: done fill_rect_srv\n"); 272 break; 273 case GC_BITMAP_CREATE: 274 printf("gc_conn: bitmap_create_srv\n"); 275 gc_bitmap_create_srv(&srvgc, &call); 276 printf("gc_conn: done bitmap_create_srv\n"); 277 break; 278 case GC_BITMAP_DESTROY: 279 printf("gc_conn: bitmap_destroy_srv\n"); 280 gc_bitmap_destroy_srv(&srvgc, &call); 281 printf("gc_conn: done bitmap_destroy_srv\n"); 282 break; 283 case GC_BITMAP_RENDER: 284 printf("gc_conn: bitmap_render_srv\n"); 285 gc_bitmap_render_srv(&srvgc, &call); 286 printf("gc_conn: done bitmap_render_srv\n"); 113 287 break; 114 288 default: … … 122 296 } 123 297 298 static ipc_gc_srv_bitmap_t *gc_bitmap_lookup(ipc_gc_srv_t *srvgc, 299 sysarg_t bmp_id) 300 { 301 link_t *link; 302 ipc_gc_srv_bitmap_t *bmp; 303 304 link = list_first(&srvgc->bitmaps); 305 while (link != NULL) { 306 bmp = list_get_instance(link, ipc_gc_srv_bitmap_t, lbitmaps); 307 printf("gc_bitmap_lookup: %lu==%lu?\n", bmp->bmp_id, bmp_id); 308 if (bmp->bmp_id == bmp_id) 309 return bmp; 310 link = list_next(link, &srvgc->bitmaps); 311 } 312 313 return NULL; 314 } 315 124 316 /** @} 125 317 */
Note:
See TracChangeset
for help on using the changeset viewer.