api_masks.c revision a91128030e6c19609f6bb66a871382bbe4e3e2a4
1/************************************************************************** 2 * 3 * Copyright 2009 VMware, Inc. All Rights Reserved. 4 * 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: 12 * 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. 16 * 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. 24 * 25 **************************************************************************/ 26 27#include "VG/openvg.h" 28 29#include "mask.h" 30#include "api.h" 31#include "renderer.h" 32 33#include "vg_context.h" 34#include "pipe/p_context.h" 35 36void vegaMask(VGHandle mask, VGMaskOperation operation, 37 VGint x, VGint y, 38 VGint width, VGint height) 39{ 40 struct vg_context *ctx = vg_current_context(); 41 42 if (width <=0 || height <= 0) { 43 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 44 return; 45 } 46 47 if (operation < VG_CLEAR_MASK || operation > VG_SUBTRACT_MASK) { 48 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 49 return; 50 } 51 52 53 vg_validate_state(ctx); 54 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); 65 } else { 66 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 67 } 68} 69 70void vegaClear(VGint x, VGint y, 71 VGint width, VGint height) 72{ 73 struct vg_context *ctx = vg_current_context(); 74 struct st_framebuffer *stfb = ctx->draw_buffer; 75 76 if (width <= 0 || height <= 0) { 77 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 78 return; 79 } 80 81 vg_validate_state(ctx); 82#if 0 83 debug_printf("Clear [%d, %d, %d, %d] with [%f, %f, %f, %f]\n", 84 x, y, width, height, 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]); 89#endif 90 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); 100 } 101} 102 103 104#ifdef OPENVG_VERSION_1_1 105 106 107void vegaRenderToMask(VGPath path, 108 VGbitfield paintModes, 109 VGMaskOperation operation) 110{ 111 struct vg_context *ctx = vg_current_context(); 112 113 if (path == VG_INVALID_HANDLE) { 114 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 115 return; 116 } 117 if (!paintModes || (paintModes&(~(VG_STROKE_PATH|VG_FILL_PATH)))) { 118 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 119 return; 120 } 121 if (operation < VG_CLEAR_MASK || 122 operation > VG_SUBTRACT_MASK) { 123 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 124 return; 125 } 126 if (!vg_object_is_valid((void*)path, VG_OBJECT_PATH)) { 127 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 128 return; 129 } 130 131 vg_validate_state(ctx); 132 133 mask_render_to((struct path *)path, paintModes, operation); 134} 135 136VGMaskLayer vegaCreateMaskLayer(VGint width, VGint height) 137{ 138 struct vg_context *ctx = vg_current_context(); 139 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; 145 } 146 147 return (VGMaskLayer)mask_layer_create(width, height); 148} 149 150void vegaDestroyMaskLayer(VGMaskLayer maskLayer) 151{ 152 struct vg_mask_layer *mask = 0; 153 struct vg_context *ctx = vg_current_context(); 154 155 if (maskLayer == VG_INVALID_HANDLE) { 156 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 157 return; 158 } 159 if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) { 160 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 161 return; 162 } 163 164 mask = (struct vg_mask_layer *)maskLayer; 165 mask_layer_destroy(mask); 166} 167 168void vegaFillMaskLayer(VGMaskLayer maskLayer, 169 VGint x, VGint y, 170 VGint width, VGint height, 171 VGfloat value) 172{ 173 struct vg_mask_layer *mask = 0; 174 struct vg_context *ctx = vg_current_context(); 175 176 if (maskLayer == VG_INVALID_HANDLE) { 177 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 178 return; 179 } 180 181 if (value < 0 || value > 1) { 182 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 183 return; 184 } 185 186 if (width <= 0 || height <= 0) { 187 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 188 return; 189 } 190 if (x < 0 || y < 0 || (x + width) < 0 || (y + height) < 0) { 191 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 192 return; 193 } 194 195 if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) { 196 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 197 return; 198 } 199 200 mask = (struct vg_mask_layer*)maskLayer; 201 202 if (x + width > mask_layer_width(mask) || 203 y + height > mask_layer_height(mask)) { 204 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 205 return; 206 } 207 208 vg_validate_state(ctx); 209 210 mask_layer_fill(mask, x, y, width, height, value); 211} 212 213void vegaCopyMask(VGMaskLayer maskLayer, 214 VGint sx, VGint sy, 215 VGint dx, VGint dy, 216 VGint width, VGint height) 217{ 218 struct vg_context *ctx = vg_current_context(); 219 struct vg_mask_layer *mask = 0; 220 221 if (maskLayer == VG_INVALID_HANDLE) { 222 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 223 return; 224 } 225 if (width <= 0 || height <= 0) { 226 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 227 return; 228 } 229 if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) { 230 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 231 return; 232 } 233 234 vg_validate_state(ctx); 235 236 mask = (struct vg_mask_layer*)maskLayer; 237 mask_copy(mask, sx, sy, dx, dy, width, height); 238} 239 240#endif 241