glsl2: Add and use new variable mode ir_var_temporary
[mesa/nouveau-pmpeg.git] / src / gallium / state_trackers / vega / api_paint.c
blobd88341b04ff41b2e62212d8720773ee4edc9080f
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 "vg_context.h"
30 #include "paint.h"
31 #include "image.h"
32 #include "api.h"
34 VGPaint vegaCreatePaint(void)
36 return (VGPaint) paint_create(vg_current_context());
39 void vegaDestroyPaint(VGPaint p)
41 struct vg_context *ctx = vg_current_context();
42 struct vg_paint *paint;
44 if (p == VG_INVALID_HANDLE) {
45 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
46 return;
49 paint = (struct vg_paint *)p;
50 paint_destroy(paint);
53 void vegaSetPaint(VGPaint paint, VGbitfield paintModes)
55 struct vg_context *ctx = vg_current_context();
57 if (paint == VG_INVALID_HANDLE) {
58 /* restore the default */
59 paint = (VGPaint)ctx->default_paint;
60 } else if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) {
61 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
62 return;
65 if (!(paintModes & ((VG_FILL_PATH|VG_STROKE_PATH)))) {
66 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
67 return;
70 if (paintModes & VG_FILL_PATH) {
71 ctx->state.vg.fill_paint = (struct vg_paint *)paint;
73 if (paintModes & VG_STROKE_PATH) {
74 ctx->state.vg.stroke_paint = (struct vg_paint *)paint;
78 VGPaint vegaGetPaint(VGPaintMode paintMode)
80 struct vg_context *ctx = vg_current_context();
81 VGPaint paint = VG_INVALID_HANDLE;
83 if (paintMode < VG_STROKE_PATH || paintMode > VG_FILL_PATH) {
84 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
85 return VG_INVALID_HANDLE;
88 if (paintMode == VG_FILL_PATH)
89 paint = (VGPaint)ctx->state.vg.fill_paint;
90 else if (paintMode == VG_STROKE_PATH)
91 paint = (VGPaint)ctx->state.vg.stroke_paint;
93 if (paint == (VGPaint)ctx->default_paint)
94 paint = VG_INVALID_HANDLE;
96 return paint;
99 void vegaSetColor(VGPaint paint, VGuint rgba)
101 struct vg_context *ctx = vg_current_context();
103 if (paint == VG_INVALID_HANDLE) {
104 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
105 return;
108 if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) {
109 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
110 return;
113 struct vg_paint *p = (struct vg_paint *)paint;
114 paint_set_colori(p, rgba);
118 VGuint vegaGetColor(VGPaint paint)
120 struct vg_context *ctx = vg_current_context();
121 struct vg_paint *p;
122 VGuint rgba = 0;
124 if (paint == VG_INVALID_HANDLE) {
125 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
126 return rgba;
129 if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) {
130 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
131 return rgba;
133 p = (struct vg_paint *)paint;
135 return paint_colori(p);
138 void vegaPaintPattern(VGPaint paint, VGImage pattern)
140 struct vg_context *ctx = vg_current_context();
142 if (paint == VG_INVALID_HANDLE ||
143 !vg_context_is_object_valid(ctx, VG_OBJECT_PAINT, (void *)paint)) {
144 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
145 return;
148 if (pattern == VG_INVALID_HANDLE) {
149 paint_set_type((struct vg_paint*)paint, VG_PAINT_TYPE_COLOR);
150 return;
153 if (!vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)pattern)) {
154 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
155 return;
159 if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT) ||
160 !vg_object_is_valid((void*)pattern, VG_OBJECT_IMAGE)) {
161 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
162 return;
164 paint_set_pattern((struct vg_paint*)paint,
165 (struct vg_image*)pattern);