| 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 display
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file Display server display device
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <adt/list.h>
|
|---|
| 37 | #include <ddev.h>
|
|---|
| 38 | #include <errno.h>
|
|---|
| 39 | #include <io/log.h>
|
|---|
| 40 | #include <stdlib.h>
|
|---|
| 41 | #include "display.h"
|
|---|
| 42 | #include "ddev.h"
|
|---|
| 43 |
|
|---|
| 44 | /** Create display device object.
|
|---|
| 45 | *
|
|---|
| 46 | * @param display Parent display
|
|---|
| 47 | * @param dd Display device
|
|---|
| 48 | * @param info Display device info
|
|---|
| 49 | * @param svc_id Display device service ID
|
|---|
| 50 | * @param svc_name Display device service name
|
|---|
| 51 | * @param gc Display device GC
|
|---|
| 52 | * @param rddev Place to store pointer to new display device.
|
|---|
| 53 | * @return EOK on success, ENOMEM if out of memory
|
|---|
| 54 | */
|
|---|
| 55 | errno_t ds_ddev_create(ds_display_t *display, ddev_t *dd,
|
|---|
| 56 | ddev_info_t *info, char *svc_name, service_id_t svc_id,
|
|---|
| 57 | gfx_context_t *gc, ds_ddev_t **rddev)
|
|---|
| 58 | {
|
|---|
| 59 | ds_ddev_t *ddev;
|
|---|
| 60 | errno_t rc;
|
|---|
| 61 |
|
|---|
| 62 | ddev = calloc(1, sizeof(ds_ddev_t));
|
|---|
| 63 | if (ddev == NULL)
|
|---|
| 64 | return ENOMEM;
|
|---|
| 65 |
|
|---|
| 66 | ddev->svc_name = svc_name;
|
|---|
| 67 | ddev->svc_id = svc_id;
|
|---|
| 68 | ddev->dd = dd;
|
|---|
| 69 | ddev->gc = gc;
|
|---|
| 70 | ddev->info = *info;
|
|---|
| 71 |
|
|---|
| 72 | rc = ds_display_add_ddev(display, ddev);
|
|---|
| 73 | if (rc != EOK) {
|
|---|
| 74 | free(ddev);
|
|---|
| 75 | return rc;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | *rddev = ddev;
|
|---|
| 79 | return EOK;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | /** Open display device.
|
|---|
| 83 | *
|
|---|
| 84 | * @param display Parent display
|
|---|
| 85 | * @param svc_id Service ID
|
|---|
| 86 | * @param rddev Place to store pointer to new display device.
|
|---|
| 87 | * @return EOK on success, ENOMEM if out of memory
|
|---|
| 88 | */
|
|---|
| 89 | errno_t ds_ddev_open(ds_display_t *display, service_id_t svc_id,
|
|---|
| 90 | ds_ddev_t **rddev)
|
|---|
| 91 | {
|
|---|
| 92 | ds_ddev_t *ddev;
|
|---|
| 93 | ddev_info_t info;
|
|---|
| 94 | gfx_context_t *gc;
|
|---|
| 95 | ddev_t *dd = NULL;
|
|---|
| 96 | char *name = NULL;
|
|---|
| 97 | errno_t rc;
|
|---|
| 98 |
|
|---|
| 99 | rc = loc_service_get_name(svc_id, &name);
|
|---|
| 100 | if (rc != EOK) {
|
|---|
| 101 | log_msg(LOG_DEFAULT, LVL_ERROR,
|
|---|
| 102 | "Error resolving name of service %lu.",
|
|---|
| 103 | (unsigned long) svc_id);
|
|---|
| 104 | return rc;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | rc = ddev_open(name, &dd);
|
|---|
| 108 | if (rc != EOK) {
|
|---|
| 109 | log_msg(LOG_DEFAULT, LVL_ERROR,
|
|---|
| 110 | "Error opening display device '%s'.", name);
|
|---|
| 111 | free(name);
|
|---|
| 112 | return rc;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | rc = ddev_get_info(dd, &info);
|
|---|
| 116 | if (rc != EOK) {
|
|---|
| 117 | log_msg(LOG_DEFAULT, LVL_ERROR,
|
|---|
| 118 | "Error getting information for display device '%s'.",
|
|---|
| 119 | name);
|
|---|
| 120 | free(name);
|
|---|
| 121 | ddev_close(dd);
|
|---|
| 122 | return rc;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Device rectangle for '%s': "
|
|---|
| 126 | "%d,%d,%d,%d", name, info.rect.p0.x, info.rect.p0.y,
|
|---|
| 127 | info.rect.p1.x, info.rect.p1.y);
|
|---|
| 128 |
|
|---|
| 129 | rc = ddev_get_gc(dd, &gc);
|
|---|
| 130 | if (rc != EOK) {
|
|---|
| 131 | log_msg(LOG_DEFAULT, LVL_ERROR,
|
|---|
| 132 | "Error getting device context for '%s'.", name);
|
|---|
| 133 | ddev_close(dd);
|
|---|
| 134 | free(name);
|
|---|
| 135 | return rc;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | rc = ds_ddev_create(display, dd, &info, name, svc_id, gc, &ddev);
|
|---|
| 139 | if (rc != EOK) {
|
|---|
| 140 | free(name);
|
|---|
| 141 | ddev_close(dd);
|
|---|
| 142 | gfx_context_delete(gc);
|
|---|
| 143 | return rc;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | rc = ds_display_paint(display, NULL);
|
|---|
| 147 | if (rc != EOK)
|
|---|
| 148 | return rc;
|
|---|
| 149 |
|
|---|
| 150 | *rddev = ddev;
|
|---|
| 151 | return EOK;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | /** Destroy display device.
|
|---|
| 155 | *
|
|---|
| 156 | * @param ddev Display device
|
|---|
| 157 | */
|
|---|
| 158 | void ds_ddev_close(ds_ddev_t *ddev)
|
|---|
| 159 | {
|
|---|
| 160 | ds_display_remove_ddev(ddev);
|
|---|
| 161 | free(ddev);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | /** @}
|
|---|
| 165 | */
|
|---|