api_paint.c revision d41e694cf78ada8c9258f96995115c9da8437894
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 "vg_context.h" 30#include "paint.h" 31#include "api.h" 32#include "handle.h" 33 34 35VGPaint vegaCreatePaint(void) 36{ 37 return paint_to_handle(paint_create(vg_current_context())); 38} 39 40void vegaDestroyPaint(VGPaint p) 41{ 42 struct vg_context *ctx = vg_current_context(); 43 44 if (p == VG_INVALID_HANDLE) { 45 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 46 return; 47 } 48 49 paint_destroy(handle_to_paint(p)); 50} 51 52void vegaSetPaint(VGPaint paint, VGbitfield paintModes) 53{ 54 struct vg_context *ctx = vg_current_context(); 55 56 if (paint == VG_INVALID_HANDLE) { 57 /* restore the default */ 58 paint = paint_to_handle(ctx->default_paint); 59 } else if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) { 60 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 61 return; 62 } 63 64 if (!(paintModes & ((VG_FILL_PATH|VG_STROKE_PATH)))) { 65 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 66 return; 67 } 68 69 if (paintModes & VG_FILL_PATH) { 70 ctx->state.vg.fill_paint = handle_to_paint(paint); 71 } 72 if (paintModes & VG_STROKE_PATH) { 73 ctx->state.vg.stroke_paint = handle_to_paint(paint); 74 } 75} 76 77VGPaint vegaGetPaint(VGPaintMode paintMode) 78{ 79 struct vg_context *ctx = vg_current_context(); 80 VGPaint paint = VG_INVALID_HANDLE; 81 82 if (paintMode < VG_STROKE_PATH || paintMode > VG_FILL_PATH) { 83 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 84 return VG_INVALID_HANDLE; 85 } 86 87 if (paintMode == VG_FILL_PATH) 88 paint = paint_to_handle(ctx->state.vg.fill_paint); 89 else if (paintMode == VG_STROKE_PATH) 90 paint = paint_to_handle(ctx->state.vg.stroke_paint); 91 92 if (paint == paint_to_handle(ctx->default_paint)) 93 paint = VG_INVALID_HANDLE; 94 95 return paint; 96} 97 98void vegaSetColor(VGPaint paint, VGuint rgba) 99{ 100 struct vg_context *ctx = vg_current_context(); 101 102 if (paint == VG_INVALID_HANDLE) { 103 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 104 return; 105 } 106 107 if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) { 108 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 109 return; 110 } 111 112 paint_set_colori(handle_to_paint(paint), rgba); 113} 114 115VGuint vegaGetColor(VGPaint paint) 116{ 117 struct vg_context *ctx = vg_current_context(); 118 struct vg_paint *p; 119 VGuint rgba = 0; 120 121 if (paint == VG_INVALID_HANDLE) { 122 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 123 return rgba; 124 } 125 126 if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) { 127 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 128 return rgba; 129 } 130 p = handle_to_paint(paint); 131 132 return paint_colori(p); 133} 134 135void vegaPaintPattern(VGPaint paint, VGImage pattern) 136{ 137 struct vg_context *ctx = vg_current_context(); 138 139 if (paint == VG_INVALID_HANDLE || 140 !vg_context_is_object_valid(ctx, VG_OBJECT_PAINT, paint)) { 141 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 142 return; 143 } 144 145 if (pattern == VG_INVALID_HANDLE) { 146 paint_set_type(handle_to_paint(paint), VG_PAINT_TYPE_COLOR); 147 return; 148 } 149 150 if (!vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, pattern)) { 151 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 152 return; 153 } 154 155 156 if (!vg_object_is_valid(paint, VG_OBJECT_PAINT) || 157 !vg_object_is_valid(pattern, VG_OBJECT_IMAGE)) { 158 vg_set_error(ctx, VG_BAD_HANDLE_ERROR); 159 return; 160 } 161 paint_set_pattern(handle_to_paint(paint), 162 handle_to_image(pattern)); 163} 164 165