| 1 | /*
|
|---|
| 2 | * Copyright (c) 2019 Jiri Svoboda
|
|---|
| 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
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup libipcgfx
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file GFX IPC server
|
|---|
| 34 | *
|
|---|
| 35 | * Serve a graphics context via HelenOS IPC.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <errno.h>
|
|---|
| 39 | #include <gfx/color.h>
|
|---|
| 40 | #include <gfx/render.h>
|
|---|
| 41 | #include <ipc/bd.h>
|
|---|
| 42 | #include <ipcgfx/ipc/gc.h>
|
|---|
| 43 | #include <ipcgfx/server.h>
|
|---|
| 44 | #include <stdint.h>
|
|---|
| 45 |
|
|---|
| 46 | #include <bd_srv.h>
|
|---|
| 47 |
|
|---|
| 48 | static void gc_set_rgb_color_srv(gfx_context_t *gc, ipc_call_t *call)
|
|---|
| 49 | {
|
|---|
| 50 | uint16_t r, g, b;
|
|---|
| 51 | gfx_color_t *color;
|
|---|
| 52 | errno_t rc;
|
|---|
| 53 |
|
|---|
| 54 | r = ipc_get_arg1(call);
|
|---|
| 55 | g = ipc_get_arg2(call);
|
|---|
| 56 | b = ipc_get_arg3(call);
|
|---|
| 57 |
|
|---|
| 58 | rc = gfx_color_new_rgb_i16(r, g, b, &color);
|
|---|
| 59 | if (rc != EOK) {
|
|---|
| 60 | async_answer_0(call, ENOMEM);
|
|---|
| 61 | return;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | rc = gfx_set_color(gc, color);
|
|---|
| 65 | async_answer_0(call, rc);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | static void gc_fill_rect_srv(gfx_context_t *gc, ipc_call_t *call)
|
|---|
| 69 | {
|
|---|
| 70 | gfx_rect_t rect;
|
|---|
| 71 | errno_t rc;
|
|---|
| 72 |
|
|---|
| 73 | rect.p0.x = ipc_get_arg1(call);
|
|---|
| 74 | rect.p0.y = ipc_get_arg2(call);
|
|---|
| 75 | rect.p1.x = ipc_get_arg3(call);
|
|---|
| 76 | rect.p1.y = ipc_get_arg4(call);
|
|---|
| 77 |
|
|---|
| 78 | rc = gfx_fill_rect(gc, &rect);
|
|---|
| 79 | async_answer_0(call, rc);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | errno_t gc_conn(ipc_call_t *icall, gfx_context_t *gc)
|
|---|
| 83 | {
|
|---|
| 84 | /* Accept the connection */
|
|---|
| 85 | async_accept_0(icall);
|
|---|
| 86 |
|
|---|
| 87 | while (true) {
|
|---|
| 88 | ipc_call_t call;
|
|---|
| 89 | async_get_call(&call);
|
|---|
| 90 | sysarg_t method = ipc_get_imethod(&call);
|
|---|
| 91 |
|
|---|
| 92 | if (!method) {
|
|---|
| 93 | /* The other side has hung up */
|
|---|
| 94 | async_answer_0(&call, EOK);
|
|---|
| 95 | break;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | switch (method) {
|
|---|
| 99 | case GC_SET_RGB_COLOR:
|
|---|
| 100 | gc_set_rgb_color_srv(gc, &call);
|
|---|
| 101 | break;
|
|---|
| 102 | case GC_FILL_RECT:
|
|---|
| 103 | gc_fill_rect_srv(gc, &call);
|
|---|
| 104 | break;
|
|---|
| 105 | default:
|
|---|
| 106 | async_answer_0(&call, EINVAL);
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | return EOK;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | /** @}
|
|---|
| 114 | */
|
|---|