Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / gallium / state_trackers / vega / api_paint.c
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
33 VGPaint vegaCreatePaint(void)
34 {
35 return (VGPaint) paint_create(vg_current_context());
36 }
37
38 void vegaDestroyPaint(VGPaint p)
39 {
40 struct vg_context *ctx = vg_current_context();
41 struct vg_paint *paint;
42
43 if (p == VG_INVALID_HANDLE) {
44 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
45 return;
46 }
47
48 paint = (struct vg_paint *)p;
49 paint_destroy(paint);
50 }
51
52 void 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 = (VGPaint)ctx->default_paint;
59 } else if (!vg_object_is_valid((void*)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 = (struct vg_paint *)paint;
71 }
72 if (paintModes & VG_STROKE_PATH) {
73 ctx->state.vg.stroke_paint = (struct vg_paint *)paint;
74 }
75 }
76
77 VGPaint 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 = (VGPaint)ctx->state.vg.fill_paint;
89 else if (paintMode == VG_STROKE_PATH)
90 paint = (VGPaint)ctx->state.vg.stroke_paint;
91
92 if (paint == (VGPaint)ctx->default_paint)
93 paint = VG_INVALID_HANDLE;
94
95 return paint;
96 }
97
98 void 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((void*)paint, VG_OBJECT_PAINT)) {
108 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
109 return;
110 }
111 {
112 struct vg_paint *p = (struct vg_paint *)paint;
113 paint_set_colori(p, rgba);
114 }
115 }
116
117 VGuint vegaGetColor(VGPaint paint)
118 {
119 struct vg_context *ctx = vg_current_context();
120 struct vg_paint *p;
121 VGuint rgba = 0;
122
123 if (paint == VG_INVALID_HANDLE) {
124 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
125 return rgba;
126 }
127
128 if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) {
129 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
130 return rgba;
131 }
132 p = (struct vg_paint *)paint;
133
134 return paint_colori(p);
135 }
136
137 void vegaPaintPattern(VGPaint paint, VGImage pattern)
138 {
139 struct vg_context *ctx = vg_current_context();
140
141 if (paint == VG_INVALID_HANDLE ||
142 !vg_context_is_object_valid(ctx, VG_OBJECT_PAINT, (void *)paint)) {
143 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
144 return;
145 }
146
147 if (pattern == VG_INVALID_HANDLE) {
148 paint_set_type((struct vg_paint*)paint, VG_PAINT_TYPE_COLOR);
149 return;
150 }
151
152 if (!vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)pattern)) {
153 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
154 return;
155 }
156
157
158 if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT) ||
159 !vg_object_is_valid((void*)pattern, VG_OBJECT_IMAGE)) {
160 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
161 return;
162 }
163 paint_set_pattern((struct vg_paint*)paint,
164 (struct vg_image*)pattern);
165 }
166