g3dvl: Use sobel filter for chroma interpolation
[mesa/nouveau-pmpeg.git] / src / gallium / state_trackers / vega / api_masks.c
blob0ddcdfb75c13c83167fba85b5ad258b8fcd1eb0b
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
15 * of the Software.
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 "mask.h"
30 #include "api.h"
31 #include "handle.h"
32 #include "renderer.h"
34 #include "vg_context.h"
35 #include "pipe/p_context.h"
37 void vegaMask(VGHandle mask, VGMaskOperation operation,
38 VGint x, VGint y,
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);
45 return;
48 if (operation < VG_CLEAR_MASK || operation > VG_SUBTRACT_MASK) {
49 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
50 return;
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);
66 } else {
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);
79 return;
82 vg_validate_state(ctx);
83 #if 0
84 debug_printf("Clear [%d, %d, %d, %d] with [%f, %f, %f, %f]\n",
85 x, y, width, height,
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]);
90 #endif
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 union pipe_color_union clear_color;
96 clear_color.f[0] = ctx->state.vg.clear_color[0];
97 clear_color.f[1] = ctx->state.vg.clear_color[1];
98 clear_color.f[2] = ctx->state.vg.clear_color[2];
99 clear_color.f[3] = ctx->state.vg.clear_color[3];
100 ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
101 &clear_color, 1., 0);
102 } else if (renderer_clear_begin(ctx->renderer)) {
103 /* XXX verify coord round-off */
104 renderer_clear(ctx->renderer, x, y, width, height, ctx->state.vg.clear_color);
105 renderer_clear_end(ctx->renderer);
110 #ifdef OPENVG_VERSION_1_1
113 void vegaRenderToMask(VGPath path,
114 VGbitfield paintModes,
115 VGMaskOperation operation)
117 struct vg_context *ctx = vg_current_context();
119 if (path == VG_INVALID_HANDLE) {
120 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
121 return;
123 if (!paintModes || (paintModes&(~(VG_STROKE_PATH|VG_FILL_PATH)))) {
124 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
125 return;
127 if (operation < VG_CLEAR_MASK ||
128 operation > VG_SUBTRACT_MASK) {
129 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
130 return;
132 if (!vg_object_is_valid(path, VG_OBJECT_PATH)) {
133 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
134 return;
137 vg_validate_state(ctx);
139 mask_render_to(handle_to_path(path), paintModes, operation);
142 VGMaskLayer vegaCreateMaskLayer(VGint width, VGint height)
144 struct vg_context *ctx = vg_current_context();
146 if (width <= 0 || height <= 0 ||
147 width > vegaGeti(VG_MAX_IMAGE_WIDTH) ||
148 height > vegaGeti(VG_MAX_IMAGE_HEIGHT)) {
149 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
150 return VG_INVALID_HANDLE;
153 return masklayer_to_handle(mask_layer_create(width, height));
156 void vegaDestroyMaskLayer(VGMaskLayer maskLayer)
158 struct vg_mask_layer *mask = 0;
159 struct vg_context *ctx = vg_current_context();
161 if (maskLayer == VG_INVALID_HANDLE) {
162 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
163 return;
165 if (!vg_object_is_valid(maskLayer, VG_OBJECT_MASK)) {
166 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
167 return;
170 mask = handle_to_masklayer(maskLayer);
171 mask_layer_destroy(mask);
174 void vegaFillMaskLayer(VGMaskLayer maskLayer,
175 VGint x, VGint y,
176 VGint width, VGint height,
177 VGfloat value)
179 struct vg_mask_layer *mask = 0;
180 struct vg_context *ctx = vg_current_context();
182 if (maskLayer == VG_INVALID_HANDLE) {
183 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
184 return;
187 if (value < 0 || value > 1) {
188 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
189 return;
192 if (width <= 0 || height <= 0) {
193 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
194 return;
196 if (x < 0 || y < 0 || (x + width) < 0 || (y + height) < 0) {
197 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
198 return;
201 if (!vg_object_is_valid(maskLayer, VG_OBJECT_MASK)) {
202 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
203 return;
206 mask = handle_to_masklayer(maskLayer);
208 if (x + width > mask_layer_width(mask) ||
209 y + height > mask_layer_height(mask)) {
210 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
211 return;
214 vg_validate_state(ctx);
216 mask_layer_fill(mask, x, y, width, height, value);
219 void vegaCopyMask(VGMaskLayer maskLayer,
220 VGint sx, VGint sy,
221 VGint dx, VGint dy,
222 VGint width, VGint height)
224 struct vg_context *ctx = vg_current_context();
225 struct vg_mask_layer *mask = 0;
227 if (maskLayer == VG_INVALID_HANDLE) {
228 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
229 return;
231 if (width <= 0 || height <= 0) {
232 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
233 return;
235 if (!vg_object_is_valid(maskLayer, VG_OBJECT_MASK)) {
236 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
237 return;
240 vg_validate_state(ctx);
242 mask = handle_to_masklayer(maskLayer);
243 mask_copy(mask, sx, sy, dx, dy, width, height);
246 #endif