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"
35 VGPaint
vegaCreatePaint(void)
37 return paint_to_handle(paint_create(vg_current_context()));
40 void vegaDestroyPaint(VGPaint p
)
42 struct vg_context
*ctx
= vg_current_context();
44 if (p
== VG_INVALID_HANDLE
) {
45 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
49 paint_destroy(handle_to_paint(p
));
52 void vegaSetPaint(VGPaint paint
, VGbitfield paintModes
)
54 struct vg_context
*ctx
= vg_current_context();
56 if (paint
== VG_INVALID_HANDLE
) {
57 /* restore the default */
58 paint
= paint_to_handle(ctx
->default_paint
);
59 } else if (!vg_object_is_valid(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
= handle_to_paint(paint
);
72 if (paintModes
& VG_STROKE_PATH
) {
73 ctx
->state
.vg
.stroke_paint
= handle_to_paint(paint
);
76 ctx
->state
.dirty
|= PAINT_DIRTY
;
79 VGPaint
vegaGetPaint(VGPaintMode paintMode
)
81 struct vg_context
*ctx
= vg_current_context();
82 VGPaint paint
= VG_INVALID_HANDLE
;
84 if (paintMode
< VG_STROKE_PATH
|| paintMode
> VG_FILL_PATH
) {
85 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
86 return VG_INVALID_HANDLE
;
89 if (paintMode
== VG_FILL_PATH
)
90 paint
= paint_to_handle(ctx
->state
.vg
.fill_paint
);
91 else if (paintMode
== VG_STROKE_PATH
)
92 paint
= paint_to_handle(ctx
->state
.vg
.stroke_paint
);
94 if (paint
== paint_to_handle(ctx
->default_paint
))
95 paint
= VG_INVALID_HANDLE
;
100 void vegaSetColor(VGPaint paint
, VGuint rgba
)
102 struct vg_context
*ctx
= vg_current_context();
105 if (paint
== VG_INVALID_HANDLE
) {
106 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
110 if (!vg_object_is_valid(paint
, VG_OBJECT_PAINT
)) {
111 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
115 p
= handle_to_paint(paint
);
116 paint_set_colori(p
, rgba
);
118 if (ctx
->state
.vg
.fill_paint
== p
||
119 ctx
->state
.vg
.stroke_paint
== p
)
120 ctx
->state
.dirty
|= PAINT_DIRTY
;
123 VGuint
vegaGetColor(VGPaint paint
)
125 struct vg_context
*ctx
= vg_current_context();
129 if (paint
== VG_INVALID_HANDLE
) {
130 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
134 if (!vg_object_is_valid(paint
, VG_OBJECT_PAINT
)) {
135 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
138 p
= handle_to_paint(paint
);
140 return paint_colori(p
);
143 void vegaPaintPattern(VGPaint paint
, VGImage pattern
)
145 struct vg_context
*ctx
= vg_current_context();
147 if (paint
== VG_INVALID_HANDLE
||
148 !vg_context_is_object_valid(ctx
, VG_OBJECT_PAINT
, paint
)) {
149 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
153 if (pattern
== VG_INVALID_HANDLE
) {
154 paint_set_type(handle_to_paint(paint
), VG_PAINT_TYPE_COLOR
);
158 if (!vg_context_is_object_valid(ctx
, VG_OBJECT_IMAGE
, pattern
)) {
159 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
164 if (!vg_object_is_valid(paint
, VG_OBJECT_PAINT
) ||
165 !vg_object_is_valid(pattern
, VG_OBJECT_IMAGE
)) {
166 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
169 paint_set_pattern(handle_to_paint(paint
),
170 handle_to_image(pattern
));