api_masks.c revision 6b241f532a21990a7849c5a786504f7ac4124f76
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#include "util/u_inlines.h" 36 37#include "util/u_pack_color.h" 38#include "util/u_draw_quad.h" 39 40#define DISABLE_1_1_MASKING 1 41 42void vegaMask(VGHandle mask, VGMaskOperation operation, 43 VGint x, VGint y, 44 VGint width, VGint height) 45{ 46 struct vg_context *ctx = vg_current_context(); 47 48 if (width <=0 || height <= 0) { 49 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 50 return; 51 } 52 53 if (operation < VG_CLEAR_MASK || operation > VG_SUBTRACT_MASK) { 54 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 55 return; 56 } 57 58 59 vg_validate_state(ctx); 60 61 if (operation == VG_CLEAR_MASK) { 62 mask_fill(x, y, width, height, 0.f); 63 } else if (operation == VG_FILL_MASK) { 64 mask_fill(x, y, width, height, 1.f); 65 } else if (vg_object_is_valid((void*)mask, VG_OBJECT_IMAGE)) { 66 struct vg_image *image = (struct vg_image *)mask; 67 mask_using_image(image, operation, x, y, width, height); 68 } else if (vg_object_is_valid((void*)mask, VG_OBJECT_MASK)) { 69#if DISABLE_1_1_MASKING 70 return; 71#else 72 struct vg_mask_layer *layer = (struct vg_mask_layer *)mask; 73 mask_using_layer(layer, operation, x, y, width, height); 74#endif 75 } else { 76 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 77 } 78} 79 80void vegaClear(VGint x, VGint y, 81 VGint width, VGint height) 82{ 83 struct vg_context *ctx = vg_current_context(); 84 struct pipe_framebuffer_state *fb; 85 86 if (width <= 0 || height <= 0) { 87 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 88 return; 89 } 90 91 vg_validate_state(ctx); 92#if 0 93 debug_printf("Clear [%d, %d, %d, %d] with [%f, %f, %f, %f]\n", 94 x, y, width, height, 95 ctx->state.vg.clear_color[0], 96 ctx->state.vg.clear_color[1], 97 ctx->state.vg.clear_color[2], 98 ctx->state.vg.clear_color[3]); 99#endif 100 101 fb = &ctx->state.g3d.fb; 102 /* check for a whole surface clear */ 103 if (!ctx->state.vg.scissoring && 104 (x == 0 && y == 0 && width == fb->width && height == fb->height)) { 105 ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, 106 ctx->state.vg.clear_color, 1., 0); 107 } else if (renderer_clear_begin(ctx->renderer)) { 108 /* XXX verify coord round-off */ 109 renderer_clear(ctx->renderer, x, y, width, height, ctx->state.vg.clear_color); 110 renderer_clear_end(ctx->renderer); 111 } 112} 113 114 115#ifdef OPENVG_VERSION_1_1 116 117 118void vegaRenderToMask(VGPath path, 119 VGbitfield paintModes, 120 VGMaskOperation operation) 121{ 122 struct vg_context *ctx = vg_current_context(); 123 124 if (path == VG_INVALID_HANDLE) { 125 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 126 return; 127 } 128 if (!paintModes || (paintModes&(~(VG_STROKE_PATH|VG_FILL_PATH)))) { 129 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 130 return; 131 } 132 if (operation < VG_CLEAR_MASK || 133 operation > VG_SUBTRACT_MASK) { 134 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 135 return; 136 } 137 if (!vg_object_is_valid((void*)path, VG_OBJECT_PATH)) { 138 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 139 return; 140 } 141 142#if DISABLE_1_1_MASKING 143 return; 144#endif 145 146 vg_validate_state(ctx); 147 148 mask_render_to((struct path *)path, paintModes, operation); 149} 150 151VGMaskLayer vegaCreateMaskLayer(VGint width, VGint height) 152{ 153 struct vg_context *ctx = vg_current_context(); 154 155 if (width <= 0 || height <= 0 || 156 width > vgGeti(VG_MAX_IMAGE_WIDTH) || 157 height > vgGeti(VG_MAX_IMAGE_HEIGHT)) { 158 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 159 return VG_INVALID_HANDLE; 160 } 161 162 return (VGMaskLayer)mask_layer_create(width, height); 163} 164 165void vegaDestroyMaskLayer(VGMaskLayer maskLayer) 166{ 167 struct vg_mask_layer *mask = 0; 168 struct vg_context *ctx = vg_current_context(); 169 170 if (maskLayer == VG_INVALID_HANDLE) { 171 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 172 return; 173 } 174 if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) { 175 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 176 return; 177 } 178 179 mask = (struct vg_mask_layer *)maskLayer; 180 mask_layer_destroy(mask); 181} 182 183void vegaFillMaskLayer(VGMaskLayer maskLayer, 184 VGint x, VGint y, 185 VGint width, VGint height, 186 VGfloat value) 187{ 188 struct vg_mask_layer *mask = 0; 189 struct vg_context *ctx = vg_current_context(); 190 191 if (maskLayer == VG_INVALID_HANDLE) { 192 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 193 return; 194 } 195 196 if (value < 0 || value > 1) { 197 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 198 return; 199 } 200 201 if (width <= 0 || height <= 0) { 202 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 203 return; 204 } 205 if (x < 0 || y < 0 || (x + width) < 0 || (y + height) < 0) { 206 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 207 return; 208 } 209 210 if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) { 211 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 212 return; 213 } 214 215 mask = (struct vg_mask_layer*)maskLayer; 216 217 if (x + width > mask_layer_width(mask) || 218 y + height > mask_layer_height(mask)) { 219 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 220 return; 221 } 222 223#if DISABLE_1_1_MASKING 224 return; 225#endif 226 mask_layer_fill(mask, x, y, width, height, value); 227} 228 229void vegaCopyMask(VGMaskLayer maskLayer, 230 VGint sx, VGint sy, 231 VGint dx, VGint dy, 232 VGint width, VGint height) 233{ 234 struct vg_context *ctx = vg_current_context(); 235 struct vg_mask_layer *mask = 0; 236 237 if (maskLayer == VG_INVALID_HANDLE) { 238 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 239 return; 240 } 241 if (width <= 0 || height <= 0) { 242 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 243 return; 244 } 245 if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) { 246 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 247 return; 248 } 249 250#if DISABLE_1_1_MASKING 251 return; 252#endif 253 254 mask = (struct vg_mask_layer*)maskLayer; 255 mask_copy(mask, sx, sy, dx, dy, width, height); 256} 257 258#endif 259