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

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

Paint desktop background with a solid color

  • Property mode set to 100644
File size: 2.9 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 <stdio.h>
40#include <stdlib.h>
41#include "display.h"
42#include "ddev.h"
43
44/** Open display device.
45 *
46 * @param display Parent display
47 * @param svc_id Service ID
48 * @param rddev Place to store pointer to new display device.
49 * @return EOK on success, ENOMEM if out of memory
50 */
51errno_t ds_ddev_open(ds_display_t *display, service_id_t svc_id,
52 ds_ddev_t **rddev)
53{
54 ds_ddev_t *ddev;
55 gfx_context_t *gc;
56 ddev_t *dd = NULL;
57 char *name = NULL;
58 errno_t rc;
59
60 rc = loc_service_get_name(svc_id, &name);
61 if (rc != EOK) {
62 printf("Error resolving name of service %lu.\n",
63 (unsigned long) svc_id);
64 return rc;
65 }
66
67 rc = ddev_open(name, &dd);
68 if (rc != EOK) {
69 printf("Error opening display device '%s'.\n", name);
70 free(name);
71 return rc;
72 }
73
74 rc = ddev_get_gc(dd, &gc);
75 if (rc != EOK) {
76 printf("Error getting device context for '%s'.\n", name);
77 ddev_close(dd);
78 free(name);
79 return rc;
80 }
81
82 ddev = calloc(1, sizeof(ds_ddev_t));
83 if (ddev == NULL) {
84 free(name);
85 ddev_close(dd);
86 return ENOMEM;
87 }
88
89 ddev->svc_name = name;
90 ddev->svc_id = svc_id;
91 ddev->dd = dd;
92 ddev->gc = gc;
93
94 ds_display_add_ddev(display, ddev);
95
96 rc = ds_display_paint_bg(display, NULL);
97 if (rc != EOK)
98 return rc;
99
100 *rddev = ddev;
101 return EOK;
102}
103
104/** Destroy display device.
105 *
106 * @param ddev Display device
107 */
108void ds_ddev_close(ds_ddev_t *ddev)
109{
110 ds_display_remove_ddev(ddev);
111 free(ddev);
112}
113
114/** @}
115 */
Note: See TracBrowser for help on using the repository browser.