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"
36 void vegaMask(VGHandle mask
, VGMaskOperation operation
,
38 VGint width
, VGint height
)
40 struct vg_context
*ctx
= vg_current_context();
42 if (width
<=0 || height
<= 0) {
43 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
47 if (operation
< VG_CLEAR_MASK
|| operation
> VG_SUBTRACT_MASK
) {
48 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
53 vg_validate_state(ctx
);
55 if (operation
== VG_CLEAR_MASK
) {
56 mask_fill(x
, y
, width
, height
, 0.f
);
57 } else if (operation
== VG_FILL_MASK
) {
58 mask_fill(x
, y
, width
, height
, 1.f
);
59 } else if (vg_object_is_valid((void*)mask
, VG_OBJECT_IMAGE
)) {
60 struct vg_image
*image
= (struct vg_image
*)mask
;
61 mask_using_image(image
, operation
, x
, y
, width
, height
);
62 } else if (vg_object_is_valid((void*)mask
, VG_OBJECT_MASK
)) {
63 struct vg_mask_layer
*layer
= (struct vg_mask_layer
*)mask
;
64 mask_using_layer(layer
, operation
, x
, y
, width
, height
);
66 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
70 void vegaClear(VGint x
, VGint y
,
71 VGint width
, VGint height
)
73 struct vg_context
*ctx
= vg_current_context();
74 struct st_framebuffer
*stfb
= ctx
->draw_buffer
;
76 if (width
<= 0 || height
<= 0) {
77 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
81 vg_validate_state(ctx
);
83 debug_printf("Clear [%d, %d, %d, %d] with [%f, %f, %f, %f]\n",
85 ctx
->state
.vg
.clear_color
[0],
86 ctx
->state
.vg
.clear_color
[1],
87 ctx
->state
.vg
.clear_color
[2],
88 ctx
->state
.vg
.clear_color
[3]);
91 /* check for a whole surface clear */
92 if (!ctx
->state
.vg
.scissoring
&&
93 (x
== 0 && y
== 0 && width
== stfb
->width
&& height
== stfb
->height
)) {
94 ctx
->pipe
->clear(ctx
->pipe
, PIPE_CLEAR_COLOR
| PIPE_CLEAR_DEPTHSTENCIL
,
95 ctx
->state
.vg
.clear_color
, 1., 0);
96 } else if (renderer_clear_begin(ctx
->renderer
)) {
97 /* XXX verify coord round-off */
98 renderer_clear(ctx
->renderer
, x
, y
, width
, height
, ctx
->state
.vg
.clear_color
);
99 renderer_clear_end(ctx
->renderer
);
104 #ifdef OPENVG_VERSION_1_1
107 void vegaRenderToMask(VGPath path
,
108 VGbitfield paintModes
,
109 VGMaskOperation operation
)
111 struct vg_context
*ctx
= vg_current_context();
113 if (path
== VG_INVALID_HANDLE
) {
114 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
117 if (!paintModes
|| (paintModes
&(~(VG_STROKE_PATH
|VG_FILL_PATH
)))) {
118 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
121 if (operation
< VG_CLEAR_MASK
||
122 operation
> VG_SUBTRACT_MASK
) {
123 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
126 if (!vg_object_is_valid((void*)path
, VG_OBJECT_PATH
)) {
127 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
131 vg_validate_state(ctx
);
133 mask_render_to((struct path
*)path
, paintModes
, operation
);
136 VGMaskLayer
vegaCreateMaskLayer(VGint width
, VGint height
)
138 struct vg_context
*ctx
= vg_current_context();
140 if (width
<= 0 || height
<= 0 ||
141 width
> vgGeti(VG_MAX_IMAGE_WIDTH
) ||
142 height
> vgGeti(VG_MAX_IMAGE_HEIGHT
)) {
143 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
144 return VG_INVALID_HANDLE
;
147 return (VGMaskLayer
)mask_layer_create(width
, height
);
150 void vegaDestroyMaskLayer(VGMaskLayer maskLayer
)
152 struct vg_mask_layer
*mask
= 0;
153 struct vg_context
*ctx
= vg_current_context();
155 if (maskLayer
== VG_INVALID_HANDLE
) {
156 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
159 if (!vg_object_is_valid((void*)maskLayer
, VG_OBJECT_MASK
)) {
160 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
164 mask
= (struct vg_mask_layer
*)maskLayer
;
165 mask_layer_destroy(mask
);
168 void vegaFillMaskLayer(VGMaskLayer maskLayer
,
170 VGint width
, VGint height
,
173 struct vg_mask_layer
*mask
= 0;
174 struct vg_context
*ctx
= vg_current_context();
176 if (maskLayer
== VG_INVALID_HANDLE
) {
177 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
181 if (value
< 0 || value
> 1) {
182 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
186 if (width
<= 0 || height
<= 0) {
187 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
190 if (x
< 0 || y
< 0 || (x
+ width
) < 0 || (y
+ height
) < 0) {
191 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
195 if (!vg_object_is_valid((void*)maskLayer
, VG_OBJECT_MASK
)) {
196 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
200 mask
= (struct vg_mask_layer
*)maskLayer
;
202 if (x
+ width
> mask_layer_width(mask
) ||
203 y
+ height
> mask_layer_height(mask
)) {
204 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
208 vg_validate_state(ctx
);
210 mask_layer_fill(mask
, x
, y
, width
, height
, value
);
213 void vegaCopyMask(VGMaskLayer maskLayer
,
216 VGint width
, VGint height
)
218 struct vg_context
*ctx
= vg_current_context();
219 struct vg_mask_layer
*mask
= 0;
221 if (maskLayer
== VG_INVALID_HANDLE
) {
222 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
225 if (width
<= 0 || height
<= 0) {
226 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
229 if (!vg_object_is_valid((void*)maskLayer
, VG_OBJECT_MASK
)) {
230 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
234 vg_validate_state(ctx
);
236 mask
= (struct vg_mask_layer
*)maskLayer
;
237 mask_copy(mask
, sx
, sy
, dx
, dy
, width
, height
);