1 /**************************************************************************
3 * Copyright 2009 VMware, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
27 #include "VG/openvg.h"
29 #include "vg_context.h"
33 VGPaint
vgCreatePaint(void)
35 return (VGPaint
) paint_create(vg_current_context());
38 void vgDestroyPaint(VGPaint p
)
40 struct vg_context
*ctx
= vg_current_context();
41 struct vg_paint
*paint
;
43 if (p
== VG_INVALID_HANDLE
) {
44 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
48 paint
= (struct vg_paint
*)p
;
52 void vgSetPaint(VGPaint paint
, VGbitfield paintModes
)
54 struct vg_context
*ctx
= vg_current_context();
56 if (paint
== VG_INVALID_HANDLE
) {
57 /* restore the default */
58 paint
= (VGPaint
)ctx
->default_paint
;
59 } else if (!vg_object_is_valid((void*)paint
, VG_OBJECT_PAINT
)) {
60 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
64 if (!(paintModes
& ((VG_FILL_PATH
|VG_STROKE_PATH
)))) {
65 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
69 if (paintModes
& VG_FILL_PATH
) {
70 ctx
->state
.vg
.fill_paint
= (struct vg_paint
*)paint
;
72 if (paintModes
& VG_STROKE_PATH
) {
73 ctx
->state
.vg
.stroke_paint
= (struct vg_paint
*)paint
;
77 VGPaint
vgGetPaint(VGPaintMode paintMode
)
79 struct vg_context
*ctx
= vg_current_context();
80 VGPaint paint
= VG_INVALID_HANDLE
;
82 if (paintMode
< VG_STROKE_PATH
|| paintMode
> VG_FILL_PATH
) {
83 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
84 return VG_INVALID_HANDLE
;
87 if (paintMode
== VG_FILL_PATH
)
88 paint
= (VGPaint
)ctx
->state
.vg
.fill_paint
;
89 else if (paintMode
== VG_STROKE_PATH
)
90 paint
= (VGPaint
)ctx
->state
.vg
.stroke_paint
;
92 if (paint
== (VGPaint
)ctx
->default_paint
)
93 paint
= VG_INVALID_HANDLE
;
98 void vgSetColor(VGPaint paint
, VGuint rgba
)
100 struct vg_context
*ctx
= vg_current_context();
102 if (paint
== VG_INVALID_HANDLE
) {
103 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
107 if (!vg_object_is_valid((void*)paint
, VG_OBJECT_PAINT
)) {
108 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
112 struct vg_paint
*p
= (struct vg_paint
*)paint
;
113 paint_set_colori(p
, rgba
);
117 VGuint
vgGetColor(VGPaint paint
)
119 struct vg_context
*ctx
= vg_current_context();
123 if (paint
== VG_INVALID_HANDLE
) {
124 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
128 if (!vg_object_is_valid((void*)paint
, VG_OBJECT_PAINT
)) {
129 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
132 p
= (struct vg_paint
*)paint
;
134 return paint_colori(p
);
137 void vgPaintPattern(VGPaint paint
, VGImage pattern
)
139 struct vg_context
*ctx
= vg_current_context();
141 if (paint
== VG_INVALID_HANDLE
||
142 !vg_context_is_object_valid(ctx
, VG_OBJECT_PAINT
, (void *)paint
)) {
143 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
147 if (pattern
== VG_INVALID_HANDLE
) {
148 paint_set_type((struct vg_paint
*)paint
, VG_PAINT_TYPE_COLOR
);
152 if (!vg_context_is_object_valid(ctx
, VG_OBJECT_IMAGE
, (void *)pattern
)) {
153 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
158 if (!vg_object_is_valid((void*)paint
, VG_OBJECT_PAINT
) ||
159 !vg_object_is_valid((void*)pattern
, VG_OBJECT_IMAGE
)) {
160 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
163 paint_set_pattern((struct vg_paint
*)paint
,
164 (struct vg_image
*)pattern
);