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
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 **************************************************************************/
32 #include "pipe/p_compiler.h"
33 #include "util/u_inlines.h"
35 #include "util/u_memory.h"
36 #include "util/u_math.h"
37 #include "util/u_sampler.h"
39 #include "cso_cache/cso_context.h"
42 struct vg_object base
;
52 VGColorRampSpreadMode spread
;
53 VGuint color_data
[1024];
62 struct pipe_sampler_view
*sampler_view
;
63 struct pipe_sampler_state sampler
;
69 VGboolean color_ramps_premultiplied
;
73 struct pipe_sampler_view
*sampler_view
;
74 VGTilingMode tiling_mode
;
75 struct pipe_sampler_state sampler
;
78 /* XXX next 3 all unneded? */
79 struct pipe_resource
*cbuf
;
80 struct pipe_shader_state fs_state
;
84 static INLINE VGuint
mix_pixels(VGuint p1
, VGuint a
, VGuint p2
, VGuint b
)
86 VGuint t
= (p1
& 0xff00ff) * a
+ (p2
& 0xff00ff) * b
;
87 t
>>= 8; t
&= 0xff00ff;
89 p1
= ((p1
>> 8) & 0xff00ff) * a
+ ((p2
>> 8) & 0xff00ff) * b
;
90 p1
&= 0xff00ff00; p1
|= t
;
95 static INLINE VGuint
float4_to_argb(const VGfloat
*clr
)
97 return float_to_ubyte(clr
[3]) << 24 |
98 float_to_ubyte(clr
[0]) << 16 |
99 float_to_ubyte(clr
[1]) << 8 |
100 float_to_ubyte(clr
[2]) << 0;
103 static INLINE
void create_gradient_data(const VGfloat
*ramp_stops
,
110 VGfloat fpos
= 0, incr
= 1.f
/ size
;
113 while (fpos
< ramp_stops
[0]) {
114 data
[pos
] = float4_to_argb(ramp_stops
+ 1);
119 for (i
= 0; i
< num
- 1; ++i
) {
121 VGint rnext
= 5 * (i
+ 1);
122 VGfloat delta
= 1.f
/(ramp_stops
[rnext
] - ramp_stops
[rcur
]);
123 while (fpos
< ramp_stops
[rnext
] && pos
< size
) {
124 VGint dist
= 256 * ((fpos
- ramp_stops
[rcur
]) * delta
);
125 VGint idist
= 256 - dist
;
126 VGuint current_color
= float4_to_argb(ramp_stops
+ rcur
+ 1);
127 VGuint next_color
= float4_to_argb(ramp_stops
+ rnext
+ 1);
128 data
[pos
] = mix_pixels(current_color
, idist
,
135 last_color
= float4_to_argb(ramp_stops
+ ((num
- 1) * 5 + 1));
137 data
[pos
] = last_color
;
140 data
[size
-1] = last_color
;
143 static INLINE
struct pipe_resource
*create_gradient_texture(struct vg_paint
*p
)
145 struct pipe_context
*pipe
= p
->base
.ctx
->pipe
;
146 struct pipe_screen
*screen
= pipe
->screen
;
147 struct pipe_resource
*tex
= 0;
148 struct pipe_resource templ
;
150 memset(&templ
, 0, sizeof(templ
));
151 templ
.target
= PIPE_TEXTURE_1D
;
152 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
153 templ
.last_level
= 0;
157 templ
.array_size
= 1;
158 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
;
160 tex
= screen
->resource_create(screen
, &templ
);
162 { /* upload color_data */
163 struct pipe_transfer
*transfer
;
165 pipe_transfer_map(p
->base
.ctx
->pipe
, tex
, 0, 0,
166 PIPE_TRANSFER_WRITE
, 0, 0, 1024, 1,
168 memcpy(map
, p
->gradient
.color_data
, sizeof(VGint
)*1024);
169 pipe
->transfer_unmap(pipe
, transfer
);
175 static INLINE
struct pipe_sampler_view
*create_gradient_sampler_view(struct vg_paint
*p
)
177 struct pipe_context
*pipe
= p
->base
.ctx
->pipe
;
178 struct pipe_resource
*texture
;
179 struct pipe_sampler_view view_templ
;
180 struct pipe_sampler_view
*view
;
182 texture
= create_gradient_texture(p
);
187 u_sampler_view_default_template(&view_templ
, texture
, texture
->format
);
188 view
= pipe
->create_sampler_view(pipe
, texture
, &view_templ
);
189 /* want the texture to go away if the view is freed */
190 pipe_resource_reference(&texture
, NULL
);
195 struct vg_paint
* paint_create(struct vg_context
*ctx
)
197 struct vg_paint
*paint
= CALLOC_STRUCT(vg_paint
);
198 const VGfloat default_color
[] = {0.0f
, 0.0f
, 0.0f
, 1.0f
};
199 const VGfloat def_ling
[] = {0.0f
, 0.0f
, 1.0f
, 0.0f
};
200 const VGfloat def_radg
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
};
201 vg_init_object(&paint
->base
, ctx
, VG_OBJECT_PAINT
);
202 vg_context_add_object(ctx
, &paint
->base
);
204 paint
->type
= VG_PAINT_TYPE_COLOR
;
205 memcpy(paint
->solid
.color
, default_color
,
206 4 * sizeof(VGfloat
));
207 paint
->gradient
.spread
= VG_COLOR_RAMP_SPREAD_PAD
;
208 memcpy(paint
->gradient
.linear
.coords
, def_ling
,
209 4 * sizeof(VGfloat
));
210 memcpy(paint
->gradient
.radial
.vals
, def_radg
,
211 5 * sizeof(VGfloat
));
213 paint
->gradient
.sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
214 paint
->gradient
.sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
215 paint
->gradient
.sampler
.min_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
;
216 paint
->gradient
.sampler
.mag_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
;
217 paint
->gradient
.sampler
.normalized_coords
= 1;
219 memcpy(&paint
->pattern
.sampler
,
220 &paint
->gradient
.sampler
,
221 sizeof(struct pipe_sampler_state
));
226 void paint_destroy(struct vg_paint
*paint
)
228 struct vg_context
*ctx
= paint
->base
.ctx
;
229 pipe_sampler_view_reference(&paint
->gradient
.sampler_view
, NULL
);
230 if (paint
->pattern
.sampler_view
)
231 pipe_sampler_view_reference(&paint
->pattern
.sampler_view
, NULL
);
233 vg_context_remove_object(ctx
, &paint
->base
);
234 vg_free_object(&paint
->base
);
237 free(paint
->gradient
.ramp_stopsi
);
238 free(paint
->gradient
.ramp_stops
);
242 void paint_set_color(struct vg_paint
*paint
,
243 const VGfloat
*color
)
245 paint
->solid
.color
[0] = color
[0];
246 paint
->solid
.color
[1] = color
[1];
247 paint
->solid
.color
[2] = color
[2];
248 paint
->solid
.color
[3] = color
[3];
250 paint
->solid
.colori
[0] = FLT_TO_INT(color
[0]);
251 paint
->solid
.colori
[1] = FLT_TO_INT(color
[1]);
252 paint
->solid
.colori
[2] = FLT_TO_INT(color
[2]);
253 paint
->solid
.colori
[3] = FLT_TO_INT(color
[3]);
256 static INLINE
void paint_color_buffer(struct vg_paint
*paint
, void *buffer
)
258 VGfloat
*map
= (VGfloat
*)buffer
;
259 memcpy(buffer
, paint
->solid
.color
, 4 * sizeof(VGfloat
));
266 static INLINE
void paint_linear_gradient_buffer(struct vg_paint
*paint
,
267 const struct matrix
*inv
,
270 VGfloat
*map
= (VGfloat
*)buffer
;
273 map
[0] = paint
->gradient
.linear
.coords
[2] - paint
->gradient
.linear
.coords
[0];
274 map
[1] = paint
->gradient
.linear
.coords
[3] - paint
->gradient
.linear
.coords
[1];
275 dd
= (map
[0] * map
[0] + map
[1] * map
[1]);
277 map
[2] = (dd
> 0.0f
) ? 1.f
/ dd
: 0.f
;
286 matrix_load_identity(&mat
);
287 /* VEGA_LINEAR_GRADIENT_SHADER expects the first point to be at (0, 0) */
288 matrix_translate(&mat
, -paint
->gradient
.linear
.coords
[0], -paint
->gradient
.linear
.coords
[1]);
289 matrix_mult(&mat
, inv
);
291 map
[8] = mat
.m
[0]; map
[9] = mat
.m
[3]; map
[10] = mat
.m
[6]; map
[11] = 0.f
;
292 map
[12] = mat
.m
[1]; map
[13] = mat
.m
[4]; map
[14] = mat
.m
[7]; map
[15] = 0.f
;
293 map
[16] = mat
.m
[2]; map
[17] = mat
.m
[5]; map
[18] = mat
.m
[8]; map
[19] = 0.f
;
296 debug_printf("Coords (%f, %f, %f, %f)\n",
297 map
[0], map
[1], map
[2], map
[3]);
302 static INLINE
void paint_radial_gradient_buffer(struct vg_paint
*paint
,
303 const struct matrix
*inv
,
306 const VGfloat
*center
= &paint
->gradient
.radial
.vals
[0];
307 const VGfloat
*focal
= &paint
->gradient
.radial
.vals
[2];
308 VGfloat rr
= paint
->gradient
.radial
.vals
[4];
309 VGfloat
*map
= (VGfloat
*)buffer
;
310 VGfloat dd
, new_focal
[2];
314 map
[0] = center
[0] - focal
[0];
315 map
[1] = center
[1] - focal
[1];
316 dd
= map
[0] * map
[0] + map
[1] * map
[1];
318 /* focal point must lie inside the circle */
319 if (0.998f
* rr
< dd
) {
322 scale
= (dd
> 0.0f
) ? sqrt(0.998f
* rr
/ dd
) : 0.0f
;
326 new_focal
[0] = center
[0] - map
[0];
327 new_focal
[1] = center
[1] - map
[1];
328 dd
= map
[0] * map
[0] + map
[1] * map
[1];
332 map
[2] = (rr
> dd
) ? rr
- dd
: 1.0f
;
342 matrix_load_identity(&mat
);
343 matrix_translate(&mat
, -focal
[0], -focal
[1]);
344 matrix_mult(&mat
, inv
);
346 map
[8] = mat
.m
[0]; map
[9] = mat
.m
[3]; map
[10] = mat
.m
[6]; map
[11] = 0.f
;
347 map
[12] = mat
.m
[1]; map
[13] = mat
.m
[4]; map
[14] = mat
.m
[7]; map
[15] = 0.f
;
348 map
[16] = mat
.m
[2]; map
[17] = mat
.m
[5]; map
[18] = mat
.m
[8]; map
[19] = 0.f
;
352 debug_printf("Coords (%f, %f, %f, %f)\n",
353 map
[0], map
[1], map
[2], map
[3]);
358 static INLINE
void paint_pattern_buffer(struct vg_paint
*paint
,
359 const struct matrix
*inv
,
362 VGfloat
*map
= (VGfloat
*)buffer
;
363 memcpy(map
, paint
->solid
.color
, 4 * sizeof(VGfloat
));
367 map
[6] = paint
->pattern
.sampler_view
->texture
->width0
;
368 map
[7] = paint
->pattern
.sampler_view
->texture
->height0
;
372 memcpy(&mat
, inv
, sizeof(*inv
));
374 map
[8] = mat
.m
[0]; map
[9] = mat
.m
[3]; map
[10] = mat
.m
[6]; map
[11] = 0.f
;
375 map
[12] = mat
.m
[1]; map
[13] = mat
.m
[4]; map
[14] = mat
.m
[7]; map
[15] = 0.f
;
376 map
[16] = mat
.m
[2]; map
[17] = mat
.m
[5]; map
[18] = mat
.m
[8]; map
[19] = 0.f
;
380 void paint_set_type(struct vg_paint
*paint
, VGPaintType type
)
385 void paint_set_ramp_stops(struct vg_paint
*paint
, const VGfloat
*stops
,
388 const VGfloat default_stops
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
,
389 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
};
391 const VGint num_stops
= num
/ 5;
394 paint
->gradient
.num_stops
= num
;
396 free(paint
->gradient
.ramp_stops
);
397 paint
->gradient
.ramp_stops
= malloc(sizeof(VGfloat
)*num
);
398 memcpy(paint
->gradient
.ramp_stops
, stops
, sizeof(VGfloat
)*num
);
402 /* stops must be in increasing order. the last stop is 1.0. if the
403 * first one is bigger than 1 then the whole sequence is invalid*/
405 stops
= default_stops
;
408 last_coord
= stops
[0];
409 for (i
= 1; i
< num_stops
; ++i
) {
411 VGfloat coord
= stops
[idx
];
412 if (!floatsEqual(last_coord
, coord
) && coord
< last_coord
) {
413 stops
= default_stops
;
420 create_gradient_data(stops
, num
/ 5, paint
->gradient
.color_data
,
423 if (paint
->gradient
.sampler_view
) {
424 pipe_sampler_view_reference(&paint
->gradient
.sampler_view
, NULL
);
425 paint
->gradient
.sampler_view
= NULL
;
428 paint
->gradient
.sampler_view
= create_gradient_sampler_view(paint
);
431 void paint_set_colori(struct vg_paint
*p
,
434 p
->solid
.color
[0] = ((rgba
>> 24) & 0xff) / 255.f
;
435 p
->solid
.color
[1] = ((rgba
>> 16) & 0xff) / 255.f
;
436 p
->solid
.color
[2] = ((rgba
>> 8) & 0xff) / 255.f
;
437 p
->solid
.color
[3] = ((rgba
>> 0) & 0xff) / 255.f
;
440 VGuint
paint_colori(struct vg_paint
*p
)
442 #define F2B(f) (float_to_ubyte(f))
444 return ((F2B(p
->solid
.color
[0]) << 24) |
445 (F2B(p
->solid
.color
[1]) << 16) |
446 (F2B(p
->solid
.color
[2]) << 8) |
447 (F2B(p
->solid
.color
[3]) << 0));
451 void paint_set_linear_gradient(struct vg_paint
*paint
,
452 const VGfloat
*coords
)
454 memcpy(paint
->gradient
.linear
.coords
, coords
, sizeof(VGfloat
) * 4);
457 void paint_set_spread_mode(struct vg_paint
*paint
,
460 paint
->gradient
.spread
= mode
;
462 case VG_COLOR_RAMP_SPREAD_PAD
:
463 paint
->gradient
.sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
465 case VG_COLOR_RAMP_SPREAD_REPEAT
:
466 paint
->gradient
.sampler
.wrap_s
= PIPE_TEX_WRAP_REPEAT
;
468 case VG_COLOR_RAMP_SPREAD_REFLECT
:
469 paint
->gradient
.sampler
.wrap_s
= PIPE_TEX_WRAP_MIRROR_REPEAT
;
474 VGColorRampSpreadMode
paint_spread_mode(struct vg_paint
*paint
)
476 return paint
->gradient
.spread
;
479 void paint_set_radial_gradient(struct vg_paint
*paint
,
480 const VGfloat
*values
)
482 memcpy(paint
->gradient
.radial
.vals
, values
, sizeof(VGfloat
) * 5);
485 void paint_set_pattern(struct vg_paint
*paint
,
486 struct vg_image
*img
)
488 if (paint
->pattern
.sampler_view
)
489 pipe_sampler_view_reference(&paint
->pattern
.sampler_view
, NULL
);
491 paint
->pattern
.sampler_view
= NULL
;
492 pipe_sampler_view_reference(&paint
->pattern
.sampler_view
,
496 void paint_set_pattern_tiling(struct vg_paint
*paint
,
499 paint
->pattern
.tiling_mode
= mode
;
503 paint
->pattern
.sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_BORDER
;
504 paint
->pattern
.sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_BORDER
;
507 paint
->pattern
.sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
508 paint
->pattern
.sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
511 paint
->pattern
.sampler
.wrap_s
= PIPE_TEX_WRAP_REPEAT
;
512 paint
->pattern
.sampler
.wrap_t
= PIPE_TEX_WRAP_REPEAT
;
514 case VG_TILE_REFLECT
:
515 paint
->pattern
.sampler
.wrap_s
= PIPE_TEX_WRAP_MIRROR_REPEAT
;
516 paint
->pattern
.sampler
.wrap_t
= PIPE_TEX_WRAP_MIRROR_REPEAT
;
519 debug_assert(!"Unknown tiling mode");
523 void paint_get_color(struct vg_paint
*paint
,
526 color
[0] = paint
->solid
.color
[0];
527 color
[1] = paint
->solid
.color
[1];
528 color
[2] = paint
->solid
.color
[2];
529 color
[3] = paint
->solid
.color
[3];
532 void paint_ramp_stops(struct vg_paint
*paint
, VGfloat
*stops
,
535 memcpy(stops
, paint
->gradient
.ramp_stops
, sizeof(VGfloat
)*num
);
538 void paint_linear_gradient(struct vg_paint
*paint
,
541 memcpy(coords
, paint
->gradient
.linear
.coords
, sizeof(VGfloat
)*4);
544 void paint_radial_gradient(struct vg_paint
*paint
,
547 memcpy(coords
, paint
->gradient
.radial
.vals
, sizeof(VGfloat
)*5);
550 int paint_num_ramp_stops(struct vg_paint
*paint
)
552 return paint
->gradient
.num_stops
;
555 VGPaintType
paint_type(struct vg_paint
*paint
)
560 void paint_set_coloriv(struct vg_paint
*paint
,
563 paint
->solid
.color
[0] = color
[0];
564 paint
->solid
.color
[1] = color
[1];
565 paint
->solid
.color
[2] = color
[2];
566 paint
->solid
.color
[3] = color
[3];
568 paint
->solid
.colori
[0] = color
[0];
569 paint
->solid
.colori
[1] = color
[1];
570 paint
->solid
.colori
[2] = color
[2];
571 paint
->solid
.colori
[3] = color
[3];
574 void paint_get_coloriv(struct vg_paint
*paint
,
577 color
[0] = paint
->solid
.colori
[0];
578 color
[1] = paint
->solid
.colori
[1];
579 color
[2] = paint
->solid
.colori
[2];
580 color
[3] = paint
->solid
.colori
[3];
583 void paint_set_color_ramp_premultiplied(struct vg_paint
*paint
,
586 paint
->gradient
.color_ramps_premultiplied
= set
;
589 VGboolean
paint_color_ramp_premultiplied(struct vg_paint
*paint
)
591 return paint
->gradient
.color_ramps_premultiplied
;
594 void paint_set_ramp_stopsi(struct vg_paint
*paint
, const VGint
*stops
,
598 free(paint
->gradient
.ramp_stopsi
);
599 paint
->gradient
.ramp_stopsi
= malloc(sizeof(VGint
)*num
);
600 memcpy(paint
->gradient
.ramp_stopsi
, stops
, sizeof(VGint
)*num
);
604 void paint_ramp_stopsi(struct vg_paint
*paint
, VGint
*stops
,
607 memcpy(stops
, paint
->gradient
.ramp_stopsi
, sizeof(VGint
)*num
);
610 void paint_set_linear_gradienti(struct vg_paint
*paint
,
613 memcpy(paint
->gradient
.linear
.coordsi
, coords
, sizeof(VGint
) * 4);
616 void paint_linear_gradienti(struct vg_paint
*paint
,
619 memcpy(coords
, paint
->gradient
.linear
.coordsi
, sizeof(VGint
)*4);
622 void paint_set_radial_gradienti(struct vg_paint
*paint
,
625 memcpy(paint
->gradient
.radial
.valsi
, values
, sizeof(VGint
) * 5);
628 void paint_radial_gradienti(struct vg_paint
*paint
,
631 memcpy(coords
, paint
->gradient
.radial
.valsi
, sizeof(VGint
)*5);
634 VGTilingMode
paint_pattern_tiling(struct vg_paint
*paint
)
636 return paint
->pattern
.tiling_mode
;
639 VGint
paint_bind_samplers(struct vg_paint
*paint
, struct pipe_sampler_state
**samplers
,
640 struct pipe_sampler_view
**sampler_views
)
642 struct vg_context
*ctx
= vg_current_context();
644 switch(paint
->type
) {
645 case VG_PAINT_TYPE_LINEAR_GRADIENT
:
646 case VG_PAINT_TYPE_RADIAL_GRADIENT
: {
647 if (paint
->gradient
.sampler_view
) {
648 paint
->gradient
.sampler
.min_img_filter
= image_sampler_filter(ctx
);
649 paint
->gradient
.sampler
.mag_img_filter
= image_sampler_filter(ctx
);
650 samplers
[0] = &paint
->gradient
.sampler
;
651 sampler_views
[0] = paint
->gradient
.sampler_view
;
656 case VG_PAINT_TYPE_PATTERN
: {
657 memcpy(paint
->pattern
.sampler
.border_color
.f
,
658 ctx
->state
.vg
.tile_fill_color
,
659 sizeof(VGfloat
) * 4);
660 paint
->pattern
.sampler
.min_img_filter
= image_sampler_filter(ctx
);
661 paint
->pattern
.sampler
.mag_img_filter
= image_sampler_filter(ctx
);
662 samplers
[0] = &paint
->pattern
.sampler
;
663 sampler_views
[0] = paint
->pattern
.sampler_view
;
673 void paint_resolve_type(struct vg_paint
*paint
)
675 if (paint
->type
== VG_PAINT_TYPE_PATTERN
&&
676 !paint
->pattern
.sampler_view
) {
677 paint
->type
= VG_PAINT_TYPE_COLOR
;
681 VGboolean
paint_is_degenerate(struct vg_paint
*paint
)
687 switch (paint
->type
) {
688 case VG_PAINT_TYPE_LINEAR_GRADIENT
:
689 vals
= paint
->gradient
.linear
.coords
;
690 /* two points are coincident */
691 degen
= (floatsEqual(vals
[0], vals
[2]) &&
692 floatsEqual(vals
[1], vals
[3]));
694 case VG_PAINT_TYPE_RADIAL_GRADIENT
:
695 vals
= paint
->gradient
.radial
.vals
;
697 degen
= (vals
[4] <= 0.0f
);
699 case VG_PAINT_TYPE_COLOR
:
700 case VG_PAINT_TYPE_PATTERN
:
709 VGint
paint_constant_buffer_size(struct vg_paint
*paint
)
711 switch(paint
->type
) {
712 case VG_PAINT_TYPE_COLOR
:
713 return 8 * sizeof(VGfloat
);/*4 color + 4 constants (0.f,1.f,2.f,4.f)*/
715 case VG_PAINT_TYPE_LINEAR_GRADIENT
:
716 return 20 * sizeof(VGfloat
);
718 case VG_PAINT_TYPE_RADIAL_GRADIENT
:
719 return 20 * sizeof(VGfloat
);
721 case VG_PAINT_TYPE_PATTERN
:
722 return 20 * sizeof(VGfloat
);
725 debug_printf("Uknown paint type: %d\n", paint
->type
);
731 void paint_fill_constant_buffer(struct vg_paint
*paint
,
732 const struct matrix
*mat
,
735 switch(paint
->type
) {
736 case VG_PAINT_TYPE_COLOR
:
737 paint_color_buffer(paint
, buffer
);
739 case VG_PAINT_TYPE_LINEAR_GRADIENT
:
740 paint_linear_gradient_buffer(paint
, mat
, buffer
);
742 case VG_PAINT_TYPE_RADIAL_GRADIENT
:
743 paint_radial_gradient_buffer(paint
, mat
, buffer
);
745 case VG_PAINT_TYPE_PATTERN
:
746 paint_pattern_buffer(paint
, mat
, buffer
);
754 VGboolean
paint_is_opaque(struct vg_paint
*paint
)
756 /* TODO add other paint types and make sure PAINT_DIRTY gets set */
757 return (paint
->type
== VG_PAINT_TYPE_COLOR
&&
758 floatsEqual(paint
->solid
.color
[3], 1.0f
));