[973efd36] | 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 | #include <async.h>
|
---|
| 30 | #include <ddev.h>
|
---|
| 31 | #include <errno.h>
|
---|
| 32 | #include <ipc/ddev.h>
|
---|
| 33 | #include <ipc/services.h>
|
---|
| 34 | #include <ipcgfx/client.h>
|
---|
| 35 | #include <loc.h>
|
---|
| 36 | #include <stdlib.h>
|
---|
| 37 |
|
---|
| 38 | /** Open display device.
|
---|
| 39 | *
|
---|
| 40 | * @param ddname Display device service name
|
---|
| 41 | * @param rdisplay Place to store pointer to display session
|
---|
| 42 | * @return EOK on success or an error code
|
---|
| 43 | */
|
---|
| 44 | errno_t ddev_open(const char *ddname, ddev_t **rddev)
|
---|
| 45 | {
|
---|
| 46 | service_id_t ddev_svc;
|
---|
| 47 | ddev_t *ddev;
|
---|
| 48 | errno_t rc;
|
---|
| 49 |
|
---|
| 50 | ddev = calloc(1, sizeof(ddev_t));
|
---|
| 51 | if (ddev == NULL)
|
---|
| 52 | return ENOMEM;
|
---|
| 53 |
|
---|
| 54 | rc = loc_service_get_id(ddname, &ddev_svc, IPC_FLAG_BLOCKING);
|
---|
| 55 | if (rc != EOK) {
|
---|
| 56 | free(ddev);
|
---|
| 57 | return ENOENT;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | ddev->sess = loc_service_connect(ddev_svc, INTERFACE_DDEV,
|
---|
| 61 | IPC_FLAG_BLOCKING);
|
---|
| 62 | if (ddev->sess == NULL) {
|
---|
| 63 | free(ddev);
|
---|
| 64 | return ENOENT;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | *rddev = ddev;
|
---|
| 68 | return EOK;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /** Close display device.
|
---|
| 72 | *
|
---|
| 73 | * @param ddev Display device session
|
---|
| 74 | */
|
---|
| 75 | void ddev_close(ddev_t *ddev)
|
---|
| 76 | {
|
---|
| 77 | async_hangup(ddev->sess);
|
---|
| 78 | free(ddev);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | /** Create graphics context for drawing to display device.
|
---|
| 82 | *
|
---|
| 83 | * @param ddev Display device
|
---|
| 84 | * @param rgc Place to store pointer to new graphics context
|
---|
| 85 | */
|
---|
| 86 | errno_t ddev_get_gc(ddev_t *ddev, gfx_context_t **rgc)
|
---|
| 87 | {
|
---|
| 88 | async_sess_t *sess;
|
---|
| 89 | async_exch_t *exch;
|
---|
[0b63dc2] | 90 | sysarg_t arg2;
|
---|
| 91 | sysarg_t arg3;
|
---|
[973efd36] | 92 | ipc_gc_t *gc;
|
---|
| 93 | errno_t rc;
|
---|
| 94 |
|
---|
| 95 | exch = async_exchange_begin(ddev->sess);
|
---|
[0b63dc2] | 96 | rc = async_req_0_2(exch, DDEV_GET_GC, &arg2, &arg3);
|
---|
| 97 | sess = async_connect_me_to(exch, INTERFACE_GC, arg2, arg3);
|
---|
[973efd36] | 98 | async_exchange_end(exch);
|
---|
| 99 |
|
---|
[0b63dc2] | 100 | if (sess == NULL)
|
---|
| 101 | return EIO;
|
---|
| 102 |
|
---|
[973efd36] | 103 | rc = ipc_gc_create(sess, &gc);
|
---|
| 104 | if (rc != EOK) {
|
---|
| 105 | async_hangup(sess);
|
---|
| 106 | return ENOMEM;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | *rgc = ipc_gc_get_ctx(gc);
|
---|
| 110 | return EOK;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | /** @}
|
---|
| 114 | */
|
---|