| 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 backend
|
|---|
| 34 | *
|
|---|
| 35 | * This implements a graphics context via HelenOS IPC.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <ipcgfx/client.h>
|
|---|
| 39 | #include <ipcgfx/ipc/gc.h>
|
|---|
| 40 | #include <gfx/color.h>
|
|---|
| 41 | #include <gfx/context.h>
|
|---|
| 42 | #include <stdlib.h>
|
|---|
| 43 | #include "../private/client.h"
|
|---|
| 44 |
|
|---|
| 45 | static errno_t ipc_gc_set_color(void *, gfx_color_t *);
|
|---|
| 46 | static errno_t ipc_gc_fill_rect(void *, gfx_rect_t *);
|
|---|
| 47 |
|
|---|
| 48 | gfx_context_ops_t ipc_gc_ops = {
|
|---|
| 49 | .set_color = ipc_gc_set_color,
|
|---|
| 50 | .fill_rect = ipc_gc_fill_rect
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 | /** Set color on IPC GC.
|
|---|
| 54 | *
|
|---|
| 55 | * Set drawing color on IPC GC.
|
|---|
| 56 | *
|
|---|
| 57 | * @param arg IPC GC
|
|---|
| 58 | * @param color Color
|
|---|
| 59 | *
|
|---|
| 60 | * @return EOK on success or an error code
|
|---|
| 61 | */
|
|---|
| 62 | static errno_t ipc_gc_set_color(void *arg, gfx_color_t *color)
|
|---|
| 63 | {
|
|---|
| 64 | ipc_gc_t *ipcgc = (ipc_gc_t *) arg;
|
|---|
| 65 | async_exch_t *exch;
|
|---|
| 66 | uint16_t r, g, b;
|
|---|
| 67 | errno_t rc;
|
|---|
| 68 |
|
|---|
| 69 | gfx_color_get_rgb_i16(color, &r, &g, &b);
|
|---|
| 70 |
|
|---|
| 71 | exch = async_exchange_begin(ipcgc->sess);
|
|---|
| 72 | rc = async_req_3_0(exch, GC_SET_RGB_COLOR, r, g, b);
|
|---|
| 73 | async_exchange_end(exch);
|
|---|
| 74 |
|
|---|
| 75 | return rc;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | /** Fill rectangle on IPC GC.
|
|---|
| 79 | *
|
|---|
| 80 | * @param arg IPC GC
|
|---|
| 81 | * @param rect Rectangle
|
|---|
| 82 | *
|
|---|
| 83 | * @return EOK on success or an error code
|
|---|
| 84 | */
|
|---|
| 85 | static errno_t ipc_gc_fill_rect(void *arg, gfx_rect_t *rect)
|
|---|
| 86 | {
|
|---|
| 87 | ipc_gc_t *ipcgc = (ipc_gc_t *) arg;
|
|---|
| 88 | async_exch_t *exch;
|
|---|
| 89 | errno_t rc;
|
|---|
| 90 |
|
|---|
| 91 | exch = async_exchange_begin(ipcgc->sess);
|
|---|
| 92 | rc = async_req_4_0(exch, GC_FILL_RECT, rect->p0.x, rect->p0.y,
|
|---|
| 93 | rect->p1.x, rect->p1.y);
|
|---|
| 94 | async_exchange_end(exch);
|
|---|
| 95 |
|
|---|
| 96 | return rc;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | /** Create IPC GC.
|
|---|
| 100 | *
|
|---|
| 101 | * Create graphics context for rendering via IPC.
|
|---|
| 102 | *
|
|---|
| 103 | * @param sess Async session
|
|---|
| 104 | * @param rgc Place to store pointer to new GC.
|
|---|
| 105 | *
|
|---|
| 106 | * @return EOK on success or an error code
|
|---|
| 107 | */
|
|---|
| 108 | errno_t ipc_gc_create(async_sess_t *sess, ipc_gc_t **rgc)
|
|---|
| 109 | {
|
|---|
| 110 | ipc_gc_t *ipcgc = NULL;
|
|---|
| 111 | gfx_context_t *gc = NULL;
|
|---|
| 112 | errno_t rc;
|
|---|
| 113 |
|
|---|
| 114 | ipcgc = calloc(1, sizeof(ipc_gc_t));
|
|---|
| 115 | if (ipcgc == NULL) {
|
|---|
| 116 | rc = ENOMEM;
|
|---|
| 117 | goto error;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | rc = gfx_context_new(&ipc_gc_ops, ipcgc, &gc);
|
|---|
| 121 | if (rc != EOK)
|
|---|
| 122 | goto error;
|
|---|
| 123 |
|
|---|
| 124 | ipcgc->gc = gc;
|
|---|
| 125 | ipcgc->sess = sess;
|
|---|
| 126 | *rgc = ipcgc;
|
|---|
| 127 | return EOK;
|
|---|
| 128 | error:
|
|---|
| 129 | if (ipcgc != NULL)
|
|---|
| 130 | free(ipcgc);
|
|---|
| 131 | gfx_context_delete(gc);
|
|---|
| 132 | return rc;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | /** Delete IPC GC.
|
|---|
| 136 | *
|
|---|
| 137 | * @param ipcgc IPC GC
|
|---|
| 138 | */
|
|---|
| 139 | errno_t ipc_gc_delete(ipc_gc_t *ipcgc)
|
|---|
| 140 | {
|
|---|
| 141 | errno_t rc;
|
|---|
| 142 |
|
|---|
| 143 | rc = gfx_context_delete(ipcgc->gc);
|
|---|
| 144 | if (rc != EOK)
|
|---|
| 145 | return rc;
|
|---|
| 146 |
|
|---|
| 147 | free(ipcgc);
|
|---|
| 148 | return EOK;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /** Get generic graphic context from IPC GC.
|
|---|
| 152 | *
|
|---|
| 153 | * @param ipcgc IPC GC
|
|---|
| 154 | * @return Graphic context
|
|---|
| 155 | */
|
|---|
| 156 | gfx_context_t *ipc_gc_get_ctx(ipc_gc_t *ipcgc)
|
|---|
| 157 | {
|
|---|
| 158 | return ipcgc->gc;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | /** @}
|
|---|
| 162 | */
|
|---|