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"
33 #include "vg_context.h"
34 #include "pipe/p_context.h"
35 #include "util/u_inlines.h"
37 #include "util/u_pack_color.h"
38 #include "util/u_draw_quad.h"
40 #define DISABLE_1_1_MASKING 1
42 void vegaMask(VGHandle mask
, VGMaskOperation operation
,
44 VGint width
, VGint height
)
46 struct vg_context
*ctx
= vg_current_context();
48 if (width
<=0 || height
<= 0) {
49 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
53 if (operation
< VG_CLEAR_MASK
|| operation
> VG_SUBTRACT_MASK
) {
54 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
59 vg_validate_state(ctx
);
61 if (operation
== VG_CLEAR_MASK
) {
62 mask_fill(x
, y
, width
, height
, 0.f
);
63 } else if (operation
== VG_FILL_MASK
) {
64 mask_fill(x
, y
, width
, height
, 1.f
);
65 } else if (vg_object_is_valid((void*)mask
, VG_OBJECT_IMAGE
)) {
66 struct vg_image
*image
= (struct vg_image
*)mask
;
67 mask_using_image(image
, operation
, x
, y
, width
, height
);
68 } else if (vg_object_is_valid((void*)mask
, VG_OBJECT_MASK
)) {
69 #if DISABLE_1_1_MASKING
72 struct vg_mask_layer
*layer
= (struct vg_mask_layer
*)mask
;
73 mask_using_layer(layer
, operation
, x
, y
, width
, height
);
76 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
80 void vegaClear(VGint x
, VGint y
,
81 VGint width
, VGint height
)
83 struct vg_context
*ctx
= vg_current_context();
84 struct st_framebuffer
*stfb
= ctx
->draw_buffer
;
86 if (width
<= 0 || height
<= 0) {
87 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
91 vg_validate_state(ctx
);
93 debug_printf("Clear [%d, %d, %d, %d] with [%f, %f, %f, %f]\n",
95 ctx
->state
.vg
.clear_color
[0],
96 ctx
->state
.vg
.clear_color
[1],
97 ctx
->state
.vg
.clear_color
[2],
98 ctx
->state
.vg
.clear_color
[3]);
101 /* check for a whole surface clear */
102 if (!ctx
->state
.vg
.scissoring
&&
103 (x
== 0 && y
== 0 && width
== stfb
->width
&& height
== stfb
->height
)) {
104 ctx
->pipe
->clear(ctx
->pipe
, PIPE_CLEAR_COLOR
| PIPE_CLEAR_DEPTHSTENCIL
,
105 ctx
->state
.vg
.clear_color
, 1., 0);
106 } else if (renderer_clear_begin(ctx
->renderer
)) {
107 /* XXX verify coord round-off */
108 renderer_clear(ctx
->renderer
, x
, y
, width
, height
, ctx
->state
.vg
.clear_color
);
109 renderer_clear_end(ctx
->renderer
);
114 #ifdef OPENVG_VERSION_1_1
117 void vegaRenderToMask(VGPath path
,
118 VGbitfield paintModes
,
119 VGMaskOperation operation
)
121 struct vg_context
*ctx
= vg_current_context();
123 if (path
== VG_INVALID_HANDLE
) {
124 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
127 if (!paintModes
|| (paintModes
&(~(VG_STROKE_PATH
|VG_FILL_PATH
)))) {
128 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
131 if (operation
< VG_CLEAR_MASK
||
132 operation
> VG_SUBTRACT_MASK
) {
133 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
136 if (!vg_object_is_valid((void*)path
, VG_OBJECT_PATH
)) {
137 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
141 #if DISABLE_1_1_MASKING
145 vg_validate_state(ctx
);
147 mask_render_to((struct path
*)path
, paintModes
, operation
);
150 VGMaskLayer
vegaCreateMaskLayer(VGint width
, VGint height
)
152 struct vg_context
*ctx
= vg_current_context();
154 if (width
<= 0 || height
<= 0 ||
155 width
> vgGeti(VG_MAX_IMAGE_WIDTH
) ||
156 height
> vgGeti(VG_MAX_IMAGE_HEIGHT
)) {
157 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
158 return VG_INVALID_HANDLE
;
161 return (VGMaskLayer
)mask_layer_create(width
, height
);
164 void vegaDestroyMaskLayer(VGMaskLayer maskLayer
)
166 struct vg_mask_layer
*mask
= 0;
167 struct vg_context
*ctx
= vg_current_context();
169 if (maskLayer
== VG_INVALID_HANDLE
) {
170 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
173 if (!vg_object_is_valid((void*)maskLayer
, VG_OBJECT_MASK
)) {
174 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
178 mask
= (struct vg_mask_layer
*)maskLayer
;
179 mask_layer_destroy(mask
);
182 void vegaFillMaskLayer(VGMaskLayer maskLayer
,
184 VGint width
, VGint height
,
187 struct vg_mask_layer
*mask
= 0;
188 struct vg_context
*ctx
= vg_current_context();
190 if (maskLayer
== VG_INVALID_HANDLE
) {
191 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
195 if (value
< 0 || value
> 1) {
196 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
200 if (width
<= 0 || height
<= 0) {
201 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
204 if (x
< 0 || y
< 0 || (x
+ width
) < 0 || (y
+ height
) < 0) {
205 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
209 if (!vg_object_is_valid((void*)maskLayer
, VG_OBJECT_MASK
)) {
210 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
214 mask
= (struct vg_mask_layer
*)maskLayer
;
216 if (x
+ width
> mask_layer_width(mask
) ||
217 y
+ height
> mask_layer_height(mask
)) {
218 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
222 #if DISABLE_1_1_MASKING
225 mask_layer_fill(mask
, x
, y
, width
, height
, value
);
228 void vegaCopyMask(VGMaskLayer maskLayer
,
231 VGint width
, VGint height
)
233 struct vg_context
*ctx
= vg_current_context();
234 struct vg_mask_layer
*mask
= 0;
236 if (maskLayer
== VG_INVALID_HANDLE
) {
237 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
240 if (width
<= 0 || height
<= 0) {
241 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
244 if (!vg_object_is_valid((void*)maskLayer
, VG_OBJECT_MASK
)) {
245 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
249 #if DISABLE_1_1_MASKING
253 mask
= (struct vg_mask_layer
*)maskLayer
;
254 mask_copy(mask
, sx
, sy
, dx
, dy
, width
, height
);