[87a7cdb] | 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>
|
---|
[e1f2079] | 39 | #include <io/log.h>
|
---|
[87a7cdb] | 40 | #include <stdio.h>
|
---|
| 41 | #include <stdlib.h>
|
---|
| 42 | #include "display.h"
|
---|
| 43 | #include "ddev.h"
|
---|
| 44 |
|
---|
| 45 | /** Open display device.
|
---|
| 46 | *
|
---|
| 47 | * @param display Parent display
|
---|
| 48 | * @param svc_id Service ID
|
---|
| 49 | * @param rddev Place to store pointer to new display device.
|
---|
| 50 | * @return EOK on success, ENOMEM if out of memory
|
---|
| 51 | */
|
---|
| 52 | errno_t ds_ddev_open(ds_display_t *display, service_id_t svc_id,
|
---|
| 53 | ds_ddev_t **rddev)
|
---|
| 54 | {
|
---|
| 55 | ds_ddev_t *ddev;
|
---|
[e1f2079] | 56 | ddev_info_t info;
|
---|
[87a7cdb] | 57 | gfx_context_t *gc;
|
---|
| 58 | ddev_t *dd = NULL;
|
---|
| 59 | char *name = NULL;
|
---|
| 60 | errno_t rc;
|
---|
| 61 |
|
---|
| 62 | rc = loc_service_get_name(svc_id, &name);
|
---|
| 63 | if (rc != EOK) {
|
---|
| 64 | printf("Error resolving name of service %lu.\n",
|
---|
| 65 | (unsigned long) svc_id);
|
---|
| 66 | return rc;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | rc = ddev_open(name, &dd);
|
---|
| 70 | if (rc != EOK) {
|
---|
| 71 | printf("Error opening display device '%s'.\n", name);
|
---|
| 72 | free(name);
|
---|
| 73 | return rc;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[e1f2079] | 76 | rc = ddev_get_info(dd, &info);
|
---|
| 77 | if (rc != EOK) {
|
---|
| 78 | printf("Error getting information for display device '%s'.\n",
|
---|
| 79 | name);
|
---|
| 80 | free(name);
|
---|
| 81 | ddev_close(dd);
|
---|
| 82 | return rc;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | log_msg(LOG_DEFAULT, LVL_NOTE, "Device rectangle for '%s': "
|
---|
| 86 | "%d,%d,%d,%d\n", name, info.rect.p0.x, info.rect.p0.y,
|
---|
| 87 | info.rect.p1.x, info.rect.p1.y);
|
---|
| 88 |
|
---|
[87a7cdb] | 89 | rc = ddev_get_gc(dd, &gc);
|
---|
| 90 | if (rc != EOK) {
|
---|
| 91 | printf("Error getting device context for '%s'.\n", name);
|
---|
| 92 | ddev_close(dd);
|
---|
| 93 | free(name);
|
---|
| 94 | return rc;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | ddev = calloc(1, sizeof(ds_ddev_t));
|
---|
| 98 | if (ddev == NULL) {
|
---|
| 99 | free(name);
|
---|
| 100 | ddev_close(dd);
|
---|
| 101 | return ENOMEM;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | ddev->svc_name = name;
|
---|
| 105 | ddev->svc_id = svc_id;
|
---|
| 106 | ddev->dd = dd;
|
---|
| 107 | ddev->gc = gc;
|
---|
[e1f2079] | 108 | ddev->info = info;
|
---|
[87a7cdb] | 109 |
|
---|
| 110 | ds_display_add_ddev(display, ddev);
|
---|
| 111 |
|
---|
[c79545e] | 112 | rc = ds_display_paint_bg(display, NULL);
|
---|
| 113 | if (rc != EOK)
|
---|
| 114 | return rc;
|
---|
| 115 |
|
---|
[87a7cdb] | 116 | *rddev = ddev;
|
---|
| 117 | return EOK;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | /** Destroy display device.
|
---|
| 121 | *
|
---|
| 122 | * @param ddev Display device
|
---|
| 123 | */
|
---|
| 124 | void ds_ddev_close(ds_ddev_t *ddev)
|
---|
| 125 | {
|
---|
| 126 | ds_display_remove_ddev(ddev);
|
---|
| 127 | free(ddev);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /** @}
|
---|
| 131 | */
|
---|