source: mainline/uspace/srv/hid/display/ddev.c@ 8edec53

serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8edec53 was 78445be8, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Log message strings should not have a newline at the end

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[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 <stdlib.h>
41#include "display.h"
42#include "ddev.h"
43
[4912dd59]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 */
55errno_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;
[8aef01c]60 errno_t rc;
[4912dd59]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
[8aef01c]72 rc = ds_display_add_ddev(display, ddev);
73 if (rc != EOK) {
74 free(ddev);
75 return rc;
76 }
[4912dd59]77
78 *rddev = ddev;
79 return EOK;
80}
81
[87a7cdb]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 */
89errno_t ds_ddev_open(ds_display_t *display, service_id_t svc_id,
90 ds_ddev_t **rddev)
91{
92 ds_ddev_t *ddev;
[e1f2079]93 ddev_info_t info;
[87a7cdb]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) {
[195b7b3]101 log_msg(LOG_DEFAULT, LVL_ERROR,
[78445be8]102 "Error resolving name of service %lu.",
[87a7cdb]103 (unsigned long) svc_id);
104 return rc;
105 }
106
107 rc = ddev_open(name, &dd);
108 if (rc != EOK) {
[195b7b3]109 log_msg(LOG_DEFAULT, LVL_ERROR,
[78445be8]110 "Error opening display device '%s'.", name);
[87a7cdb]111 free(name);
112 return rc;
113 }
114
[e1f2079]115 rc = ddev_get_info(dd, &info);
116 if (rc != EOK) {
[195b7b3]117 log_msg(LOG_DEFAULT, LVL_ERROR,
[78445be8]118 "Error getting information for display device '%s'.",
[e1f2079]119 name);
120 free(name);
121 ddev_close(dd);
122 return rc;
123 }
124
[195b7b3]125 log_msg(LOG_DEFAULT, LVL_DEBUG, "Device rectangle for '%s': "
[78445be8]126 "%d,%d,%d,%d", name, info.rect.p0.x, info.rect.p0.y,
[e1f2079]127 info.rect.p1.x, info.rect.p1.y);
128
[87a7cdb]129 rc = ddev_get_gc(dd, &gc);
130 if (rc != EOK) {
[195b7b3]131 log_msg(LOG_DEFAULT, LVL_ERROR,
[78445be8]132 "Error getting device context for '%s'.", name);
[87a7cdb]133 ddev_close(dd);
134 free(name);
135 return rc;
136 }
137
[4912dd59]138 rc = ds_ddev_create(display, dd, &info, name, svc_id, gc, &ddev);
139 if (rc != EOK) {
[87a7cdb]140 free(name);
141 ddev_close(dd);
[4912dd59]142 gfx_context_delete(gc);
143 return rc;
[87a7cdb]144 }
145
[5271e4c]146 rc = ds_display_paint(display, NULL);
[c79545e]147 if (rc != EOK)
148 return rc;
149
[87a7cdb]150 *rddev = ddev;
151 return EOK;
152}
153
154/** Destroy display device.
155 *
156 * @param ddev Display device
157 */
158void ds_ddev_close(ds_ddev_t *ddev)
159{
160 ds_display_remove_ddev(ddev);
161 free(ddev);
162}
163
164/** @}
165 */
Note: See TracBrowser for help on using the repository browser.