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"
34 #include "vg_context.h"
35 #include "pipe/p_context.h"
37 void vegaMask(VGHandle mask
, VGMaskOperation operation
,
39 VGint width
, VGint height
)
41 struct vg_context
*ctx
= vg_current_context();
43 if (width
<=0 || height
<= 0) {
44 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
48 if (operation
< VG_CLEAR_MASK
|| operation
> VG_SUBTRACT_MASK
) {
49 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
54 vg_validate_state(ctx
);
56 if (operation
== VG_CLEAR_MASK
) {
57 mask_fill(x
, y
, width
, height
, 0.f
);
58 } else if (operation
== VG_FILL_MASK
) {
59 mask_fill(x
, y
, width
, height
, 1.f
);
60 } else if (vg_object_is_valid(mask
, VG_OBJECT_IMAGE
)) {
61 struct vg_image
*image
= handle_to_image(mask
);
62 mask_using_image(image
, operation
, x
, y
, width
, height
);
63 } else if (vg_object_is_valid(mask
, VG_OBJECT_MASK
)) {
64 struct vg_mask_layer
*layer
= handle_to_masklayer(mask
);
65 mask_using_layer(layer
, operation
, x
, y
, width
, height
);
67 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
71 void vegaClear(VGint x
, VGint y
,
72 VGint width
, VGint height
)
74 struct vg_context
*ctx
= vg_current_context();
75 struct st_framebuffer
*stfb
= ctx
->draw_buffer
;
77 if (width
<= 0 || height
<= 0) {
78 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
82 vg_validate_state(ctx
);
84 debug_printf("Clear [%d, %d, %d, %d] with [%f, %f, %f, %f]\n",
86 ctx
->state
.vg
.clear_color
[0],
87 ctx
->state
.vg
.clear_color
[1],
88 ctx
->state
.vg
.clear_color
[2],
89 ctx
->state
.vg
.clear_color
[3]);
92 /* check for a whole surface clear */
93 if (!ctx
->state
.vg
.scissoring
&&
94 (x
== 0 && y
== 0 && width
== stfb
->width
&& height
== stfb
->height
)) {
95 ctx
->pipe
->clear(ctx
->pipe
, PIPE_CLEAR_COLOR
| PIPE_CLEAR_DEPTHSTENCIL
,
96 ctx
->state
.vg
.clear_color
, 1., 0);
97 } else if (renderer_clear_begin(ctx
->renderer
)) {
98 /* XXX verify coord round-off */
99 renderer_clear(ctx
->renderer
, x
, y
, width
, height
, ctx
->state
.vg
.clear_color
);
100 renderer_clear_end(ctx
->renderer
);
105 #ifdef OPENVG_VERSION_1_1
108 void vegaRenderToMask(VGPath path
,
109 VGbitfield paintModes
,
110 VGMaskOperation operation
)
112 struct vg_context
*ctx
= vg_current_context();
114 if (path
== VG_INVALID_HANDLE
) {
115 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
118 if (!paintModes
|| (paintModes
&(~(VG_STROKE_PATH
|VG_FILL_PATH
)))) {
119 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
122 if (operation
< VG_CLEAR_MASK
||
123 operation
> VG_SUBTRACT_MASK
) {
124 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
127 if (!vg_object_is_valid(path
, VG_OBJECT_PATH
)) {
128 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
132 vg_validate_state(ctx
);
134 mask_render_to(handle_to_path(path
), paintModes
, operation
);
137 VGMaskLayer
vegaCreateMaskLayer(VGint width
, VGint height
)
139 struct vg_context
*ctx
= vg_current_context();
141 if (width
<= 0 || height
<= 0 ||
142 width
> vegaGeti(VG_MAX_IMAGE_WIDTH
) ||
143 height
> vegaGeti(VG_MAX_IMAGE_HEIGHT
)) {
144 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
145 return VG_INVALID_HANDLE
;
148 return masklayer_to_handle(mask_layer_create(width
, height
));
151 void vegaDestroyMaskLayer(VGMaskLayer maskLayer
)
153 struct vg_mask_layer
*mask
= 0;
154 struct vg_context
*ctx
= vg_current_context();
156 if (maskLayer
== VG_INVALID_HANDLE
) {
157 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
160 if (!vg_object_is_valid(maskLayer
, VG_OBJECT_MASK
)) {
161 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
165 mask
= handle_to_masklayer(maskLayer
);
166 mask_layer_destroy(mask
);
169 void vegaFillMaskLayer(VGMaskLayer maskLayer
,
171 VGint width
, VGint height
,
174 struct vg_mask_layer
*mask
= 0;
175 struct vg_context
*ctx
= vg_current_context();
177 if (maskLayer
== VG_INVALID_HANDLE
) {
178 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
182 if (value
< 0 || value
> 1) {
183 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
187 if (width
<= 0 || height
<= 0) {
188 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
191 if (x
< 0 || y
< 0 || (x
+ width
) < 0 || (y
+ height
) < 0) {
192 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
196 if (!vg_object_is_valid(maskLayer
, VG_OBJECT_MASK
)) {
197 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
201 mask
= handle_to_masklayer(maskLayer
);
203 if (x
+ width
> mask_layer_width(mask
) ||
204 y
+ height
> mask_layer_height(mask
)) {
205 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
209 vg_validate_state(ctx
);
211 mask_layer_fill(mask
, x
, y
, width
, height
, value
);
214 void vegaCopyMask(VGMaskLayer maskLayer
,
217 VGint width
, VGint height
)
219 struct vg_context
*ctx
= vg_current_context();
220 struct vg_mask_layer
*mask
= 0;
222 if (maskLayer
== VG_INVALID_HANDLE
) {
223 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
226 if (width
<= 0 || height
<= 0) {
227 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
230 if (!vg_object_is_valid(maskLayer
, VG_OBJECT_MASK
)) {
231 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
235 vg_validate_state(ctx
);
237 mask
= handle_to_masklayer(maskLayer
);
238 mask_copy(mask
, sx
, sy
, dx
, dy
, width
, height
);