source: mainline/uspace/lib/gfx/src/bitmap.c@ 7bb45e3

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

Future-proof gfx_bitmap_params_t with initialization function

  • Property mode set to 100644
File size: 3.8 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 libgfx
30 * @{
31 */
32/**
33 * @file Bitmap
34 */
35
36#include <gfx/bitmap.h>
37#include <mem.h>
38#include <stdint.h>
39#include <stdlib.h>
40#include "../private/bitmap.h"
41#include "../private/context.h"
42
43/** Initialize bitmap parameters structure.
44 *
45 * Bitmap parameters structure must always be initialized using this function
46 * first.
47 *
48 * @param params Bitmap parameters structure
49 */
50void gfx_bitmap_params_init(gfx_bitmap_params_t *params)
51{
52 memset(params, 0, sizeof(gfx_bitmap_params_t));
53}
54
55/** Allocate bitmap in a graphics context.
56 *
57 * @param gc Graphic context
58 * @param params Bitmap parameters
59 * @param alloc Bitmap allocation info or @c NULL to let GC allocate
60 * pixel storage
61 * @param rbitmap Place to store pointer to new bitmap
62 *
63 * @return EOK on success, EINVAL if parameters are invald,
64 * ENOMEM if insufficient resources, EIO if grahic device connection
65 * was lost
66 */
67errno_t gfx_bitmap_create(gfx_context_t *gc, gfx_bitmap_params_t *params,
68 gfx_bitmap_alloc_t *alloc, gfx_bitmap_t **rbitmap)
69{
70 void *bm_priv;
71 gfx_bitmap_t *bitmap;
72 errno_t rc;
73
74 bitmap = calloc(1, sizeof(gfx_bitmap_t));
75 if (bitmap == NULL)
76 return ENOMEM;
77
78 rc = gc->ops->bitmap_create(gc->arg, params, alloc, &bm_priv);
79 if (rc != EOK)
80 return rc;
81
82 bitmap->gc = gc;
83 bitmap->gc_priv = bm_priv;
84 *rbitmap = bitmap;
85 return EOK;
86}
87
88/** Destroy bitmap from graphics context.
89 *
90 * @param bitmap Bitmap
91 *
92 * @return EOK on success, EIO if grahic device connection was lost
93 */
94errno_t gfx_bitmap_destroy(gfx_bitmap_t *bitmap)
95{
96 errno_t rc;
97
98 rc = bitmap->gc->ops->bitmap_destroy(bitmap->gc_priv);
99 if (rc != EOK)
100 return rc;
101
102 free(bitmap);
103 return EOK;
104}
105
106/** Render bitmap in graphics context.
107 *
108 * @param bitmap Bitmap
109 * @param srect Source rectangle or @c NULL to render entire bitmap
110 * @param offs Bitmap offset or @c NULL for zero offset
111 *
112 * @return EOK on success, EIO if grahic device connection was lost
113 */
114errno_t gfx_bitmap_render(gfx_bitmap_t *bitmap, gfx_rect_t *srect,
115 gfx_coord2_t *offs)
116{
117 return bitmap->gc->ops->bitmap_render(bitmap->gc_priv, srect, offs);
118}
119
120/** Get bitmap allocation info.
121 *
122 * @param bitmap Bitmap
123 * @param alloc Allocation info structure to fill in
124 *
125 * @return EOK on success, EIO if grahic device connection was lost
126 */
127errno_t gfx_bitmap_get_alloc(gfx_bitmap_t *bitmap, gfx_bitmap_alloc_t *alloc)
128{
129 return bitmap->gc->ops->bitmap_get_alloc(bitmap->gc_priv, alloc);
130}
131
132/** @}
133 */
Note: See TracBrowser for help on using the repository browser.