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 void vegaMask(VGHandle mask
, VGMaskOperation operation
,
42 VGint width
, VGint height
)
44 struct vg_context
*ctx
= vg_current_context();
46 if (width
<=0 || height
<= 0) {
47 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
51 if (operation
< VG_CLEAR_MASK
|| operation
> VG_SUBTRACT_MASK
) {
52 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
57 vg_validate_state(ctx
);
59 if (operation
== VG_CLEAR_MASK
) {
60 mask_fill(x
, y
, width
, height
, 0.f
);
61 } else if (operation
== VG_FILL_MASK
) {
62 mask_fill(x
, y
, width
, height
, 1.f
);
63 } else if (vg_object_is_valid((void*)mask
, VG_OBJECT_IMAGE
)) {
64 struct vg_image
*image
= (struct vg_image
*)mask
;
65 mask_using_image(image
, operation
, x
, y
, width
, height
);
66 } else if (vg_object_is_valid((void*)mask
, VG_OBJECT_MASK
)) {
67 struct vg_mask_layer
*layer
= (struct vg_mask_layer
*)mask
;
68 mask_using_layer(layer
, operation
, x
, y
, width
, height
);
70 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
74 void vegaClear(VGint x
, VGint y
,
75 VGint width
, VGint height
)
77 struct vg_context
*ctx
= vg_current_context();
78 struct st_framebuffer
*stfb
= ctx
->draw_buffer
;
80 if (width
<= 0 || height
<= 0) {
81 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
85 vg_validate_state(ctx
);
87 debug_printf("Clear [%d, %d, %d, %d] with [%f, %f, %f, %f]\n",
89 ctx
->state
.vg
.clear_color
[0],
90 ctx
->state
.vg
.clear_color
[1],
91 ctx
->state
.vg
.clear_color
[2],
92 ctx
->state
.vg
.clear_color
[3]);
95 /* check for a whole surface clear */
96 if (!ctx
->state
.vg
.scissoring
&&
97 (x
== 0 && y
== 0 && width
== stfb
->width
&& height
== stfb
->height
)) {
98 ctx
->pipe
->clear(ctx
->pipe
, PIPE_CLEAR_COLOR
| PIPE_CLEAR_DEPTHSTENCIL
,
99 ctx
->state
.vg
.clear_color
, 1., 0);
100 } else if (renderer_clear_begin(ctx
->renderer
)) {
101 /* XXX verify coord round-off */
102 renderer_clear(ctx
->renderer
, x
, y
, width
, height
, ctx
->state
.vg
.clear_color
);
103 renderer_clear_end(ctx
->renderer
);
108 #ifdef OPENVG_VERSION_1_1
111 void vegaRenderToMask(VGPath path
,
112 VGbitfield paintModes
,
113 VGMaskOperation operation
)
115 struct vg_context
*ctx
= vg_current_context();
117 if (path
== VG_INVALID_HANDLE
) {
118 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
121 if (!paintModes
|| (paintModes
&(~(VG_STROKE_PATH
|VG_FILL_PATH
)))) {
122 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
125 if (operation
< VG_CLEAR_MASK
||
126 operation
> VG_SUBTRACT_MASK
) {
127 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
130 if (!vg_object_is_valid((void*)path
, VG_OBJECT_PATH
)) {
131 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
135 vg_validate_state(ctx
);
137 mask_render_to((struct path
*)path
, paintModes
, operation
);
140 VGMaskLayer
vegaCreateMaskLayer(VGint width
, VGint height
)
142 struct vg_context
*ctx
= vg_current_context();
144 if (width
<= 0 || height
<= 0 ||
145 width
> vgGeti(VG_MAX_IMAGE_WIDTH
) ||
146 height
> vgGeti(VG_MAX_IMAGE_HEIGHT
)) {
147 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
148 return VG_INVALID_HANDLE
;
151 return (VGMaskLayer
)mask_layer_create(width
, height
);
154 void vegaDestroyMaskLayer(VGMaskLayer maskLayer
)
156 struct vg_mask_layer
*mask
= 0;
157 struct vg_context
*ctx
= vg_current_context();
159 if (maskLayer
== VG_INVALID_HANDLE
) {
160 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
163 if (!vg_object_is_valid((void*)maskLayer
, VG_OBJECT_MASK
)) {
164 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
168 mask
= (struct vg_mask_layer
*)maskLayer
;
169 mask_layer_destroy(mask
);
172 void vegaFillMaskLayer(VGMaskLayer maskLayer
,
174 VGint width
, VGint height
,
177 struct vg_mask_layer
*mask
= 0;
178 struct vg_context
*ctx
= vg_current_context();
180 if (maskLayer
== VG_INVALID_HANDLE
) {
181 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
185 if (value
< 0 || value
> 1) {
186 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
190 if (width
<= 0 || height
<= 0) {
191 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
194 if (x
< 0 || y
< 0 || (x
+ width
) < 0 || (y
+ height
) < 0) {
195 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
199 if (!vg_object_is_valid((void*)maskLayer
, VG_OBJECT_MASK
)) {
200 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
204 mask
= (struct vg_mask_layer
*)maskLayer
;
206 if (x
+ width
> mask_layer_width(mask
) ||
207 y
+ height
> mask_layer_height(mask
)) {
208 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
212 vg_validate_state(ctx
);
214 mask_layer_fill(mask
, x
, y
, width
, height
, value
);
217 void vegaCopyMask(VGMaskLayer maskLayer
,
220 VGint width
, VGint height
)
222 struct vg_context
*ctx
= vg_current_context();
223 struct vg_mask_layer
*mask
= 0;
225 if (maskLayer
== VG_INVALID_HANDLE
) {
226 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
229 if (width
<= 0 || height
<= 0) {
230 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
233 if (!vg_object_is_valid((void*)maskLayer
, VG_OBJECT_MASK
)) {
234 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
238 vg_validate_state(ctx
);
240 mask
= (struct vg_mask_layer
*)maskLayer
;
241 mask_copy(mask
, sx
, sy
, dx
, dy
, width
, height
);