source: mainline/uspace/srv/hid/display/ddev.c@ 6301a24f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6301a24f was 4912dd59, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Actually fill in fake cursor unit tests (paint, get_rect)

Fixed ds_cursor_paint() to work without GC (fixes post_ptd_event_wnd_switch
test) and fixed ds_cursor_paint() to render bitmap also when called
for the first time (found by the unit test).

  • Property mode set to 100644
File size: 4.0 KB
Line 
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 <stdio.h>
41#include <stdlib.h>
42#include "display.h"
43#include "ddev.h"
44
45/** Create display device object.
46 *
47 * @param display Parent display
48 * @param dd Display device
49 * @param info Display device info
50 * @param svc_id Display device service ID
51 * @param svc_name Display device service name
52 * @param gc Display device GC
53 * @param rddev Place to store pointer to new display device.
54 * @return EOK on success, ENOMEM if out of memory
55 */
56errno_t ds_ddev_create(ds_display_t *display, ddev_t *dd,
57 ddev_info_t *info, char *svc_name, service_id_t svc_id,
58 gfx_context_t *gc, ds_ddev_t **rddev)
59{
60 ds_ddev_t *ddev;
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 ds_display_add_ddev(display, ddev);
73
74 *rddev = ddev;
75 return EOK;
76}
77
78/** Open display device.
79 *
80 * @param display Parent display
81 * @param svc_id Service ID
82 * @param rddev Place to store pointer to new display device.
83 * @return EOK on success, ENOMEM if out of memory
84 */
85errno_t ds_ddev_open(ds_display_t *display, service_id_t svc_id,
86 ds_ddev_t **rddev)
87{
88 ds_ddev_t *ddev;
89 ddev_info_t info;
90 gfx_context_t *gc;
91 ddev_t *dd = NULL;
92 char *name = NULL;
93 errno_t rc;
94
95 rc = loc_service_get_name(svc_id, &name);
96 if (rc != EOK) {
97 printf("Error resolving name of service %lu.\n",
98 (unsigned long) svc_id);
99 return rc;
100 }
101
102 rc = ddev_open(name, &dd);
103 if (rc != EOK) {
104 printf("Error opening display device '%s'.\n", name);
105 free(name);
106 return rc;
107 }
108
109 rc = ddev_get_info(dd, &info);
110 if (rc != EOK) {
111 printf("Error getting information for display device '%s'.\n",
112 name);
113 free(name);
114 ddev_close(dd);
115 return rc;
116 }
117
118 log_msg(LOG_DEFAULT, LVL_NOTE, "Device rectangle for '%s': "
119 "%d,%d,%d,%d\n", name, info.rect.p0.x, info.rect.p0.y,
120 info.rect.p1.x, info.rect.p1.y);
121
122 rc = ddev_get_gc(dd, &gc);
123 if (rc != EOK) {
124 printf("Error getting device context for '%s'.\n", name);
125 ddev_close(dd);
126 free(name);
127 return rc;
128 }
129
130 rc = ds_ddev_create(display, dd, &info, name, svc_id, gc, &ddev);
131 if (rc != EOK) {
132 free(name);
133 ddev_close(dd);
134 gfx_context_delete(gc);
135 return rc;
136 }
137
138 rc = ds_display_paint_bg(display, NULL);
139 if (rc != EOK)
140 return rc;
141
142 *rddev = ddev;
143 return EOK;
144}
145
146/** Destroy display device.
147 *
148 * @param ddev Display device
149 */
150void ds_ddev_close(ds_ddev_t *ddev)
151{
152 ds_display_remove_ddev(ddev);
153 free(ddev);
154}
155
156/** @}
157 */
Note: See TracBrowser for help on using the repository browser.