summaryrefslogtreecommitdiff
path: root/legacy/evas/src/lib/canvas/evas_object_gradient.c
blob: a6af82f916dcd7a3633ae8d73710188c1f3ef85b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
#include "evas_common.h"
#include "evas_private.h"

/* private magic number for gradient objects */
static const char o_type[] = "gradient";

/* private struct for gradient object internal data */
typedef struct _Evas_Object_Gradient      Evas_Object_Gradient;

struct _Evas_Object_Gradient
{
   DATA32            magic;

   struct {
      Evas_Angle     angle;
      int            spread;
      struct {
         Evas_Coord  x, y, w, h;
      } fill;
      struct {
         char       *name;
         char       *params;
      } type;
   unsigned char     gradient_opaque : 1;
   } cur, prev;
   
   unsigned char     changed : 1;
   unsigned char     gradient_changed : 1;

   void             *engine_data;
};

/* private methods for gradient objects */
static void evas_object_gradient_init(Evas_Object *obj);
static void *evas_object_gradient_new(void);
static void evas_object_gradient_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y);
static void evas_object_gradient_free(Evas_Object *obj);
static void evas_object_gradient_render_pre(Evas_Object *obj);
static void evas_object_gradient_render_post(Evas_Object *obj);

static int evas_object_gradient_is_opaque(Evas_Object *obj);
static int evas_object_gradient_was_opaque(Evas_Object *obj);

static Evas_Object_Func object_func =
{
   /* methods (compulsory) */
   evas_object_gradient_free,
     evas_object_gradient_render,
     evas_object_gradient_render_pre,
     evas_object_gradient_render_post,
   /* these are optional. NULL = nothing */
     NULL,
     NULL,
     NULL,
     NULL,
     evas_object_gradient_is_opaque,
     evas_object_gradient_was_opaque,
     NULL,
     NULL,
     NULL
};

/* the actual api call to add a rect */
/* it has no other api calls as all properties are standard */

/**
 * @defgroup Evas_Object_Gradient_Group Evas Gradient Object Functions
 *
 * Functions that work on evas gradient objects.
 *
 * The following example shows how
 */

/**
 * Adds a gradient object to the given evas.
 * @param   e The given evas.
 * @return  A new evas gradient object if successful.  Otherwise, @c NULL.
 * @ingroup Evas_Object_Gradient_Group
 */
Evas_Object *
evas_object_gradient_add(Evas *e)
{
   Evas_Object *obj;

   MAGIC_CHECK(e, Evas, MAGIC_EVAS);
   return NULL;
   MAGIC_CHECK_END();
   obj = evas_object_new();
   evas_object_gradient_init(obj);
   evas_object_inject(obj, e);
   return obj;
}

/**
 * Adds a colour to the given evas gradient object.
 *
 * The @p distance parameter determines the proportion of the gradient
 * object that is to be set to this colour.  For instance, if red is
 * added with @p distance set to 2, and green is added with @p
 * distance set to 1, two-thirds will be red or reddish and one-third
 * will be green or greenish.
 *
 * Colours are added from the top downwards.
 *
 * @param   obj      The given evas gradient object.
 * @param   r        Red component of the given colour.
 * @param   g        Green component of the given colour.
 * @param   b        Blue component of the given colour.
 * @param   a        Alpha component of the given colour.
 * @param   distance Proportion of the gradient object that is this colour.
 * @ingroup Evas_Object_Gradient_Group
 */
void
evas_object_gradient_color_add(Evas_Object *obj, int r, int g, int b, int a, int distance)
{
   Evas_Object_Gradient *o;

   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   return;
   MAGIC_CHECK_END();
   o->engine_data = obj->layer->evas->engine.func->gradient_color_add(obj->layer->evas->engine.data.output,
								      obj->layer->evas->engine.data.context,
								      o->engine_data,
								      r, g, b, a,
								      distance);
   if (a != 255) o->cur.gradient_opaque = 0;
   o->gradient_changed = 1;
   o->changed = 1;
   evas_object_change(obj);
}

/**
 * Deletes all colours set for the given evas gradient object.
 * @param   obj The given evas gradient object.
 * @ingroup Evas_Object_Gradient_Group
 */
void
evas_object_gradient_colors_clear(Evas_Object *obj)
{
   Evas_Object_Gradient *o;

   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   return;
   MAGIC_CHECK_END();
   o->engine_data = obj->layer->evas->engine.func->gradient_colors_clear(obj->layer->evas->engine.data.output,
									 obj->layer->evas->engine.data.context,
									 o->engine_data);
   o->gradient_changed = 1;
   o->changed = 1;
   o->cur.gradient_opaque = 1;
   evas_object_change(obj);
}

/**
 * Sets the angle at which the given evas gradient object sits clockwise
 * from vertical.
 * @param   obj   The given evas gradient object.
 * @param   angle Angle in degrees.  Can be negative.
 * @ingroup Evas_Object_Gradient_Group
 */
void
evas_object_gradient_angle_set(Evas_Object *obj, Evas_Angle angle)
{
   Evas_Object_Gradient *o;

   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   return;
   MAGIC_CHECK_END();
   if (angle == o->cur.angle) return;
   o->cur.angle = angle;
   o->changed = 1;
   evas_object_change(obj);
}

/**
 * Retrieves the angle at which the given evas gradient object sits
 * clockwise from the vertical.
 * @param   obj The given evas gradient object.
 * @return  The current angle if successful. @c 0.0 otherwise.
 * @ingroup Evas_Object_Gradient_Group
 */
Evas_Angle
evas_object_gradient_angle_get(Evas_Object *obj)
{
   Evas_Object_Gradient *o;

   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return 0.0;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   return 0.0;
   MAGIC_CHECK_END();
   return o->cur.angle;
   evas_object_change(obj);
}

/**
 * @defgroup Evas_Object_Gradient_Fill_Group Gradient Object Fill Rectangle Functions
 *
 * Functions that deal with what areas of the gradient object are to be
 * tiled with the gradient.
 */

/**
 * Sets the rectangle on the gradient object that the gradient will be
 * drawn to.
 *
 * Note that the gradient may be tiled around this one rectangle,
 * according to its spread value - restrict, repeat, or reflect.  To have
 * only one 'cycle' of the gradient drawn, the spread value must be set
 * to restrict, or @p x and @p y must be 0 and @p w and @p h need to be
 * the width and height of the gradient object respectively.
 *
 * The default values for the fill parameters is @p x = 0, @p y = 0,
 * @p w = 32 and @p h = 32.
 *
 * @param   obj The given evas gradient object.
 * @param   x   The X coordinate for the top left corner of the rect.
 * @param   y   The Y coordinate for the top left corner of the rect.
 * @param   w   The width of the rect.
 * @param   h   The height of the rect.
 * @ingroup Evas_Object_Gradient_Fill_Group
 */
void
evas_object_gradient_fill_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
{
   Evas_Object_Gradient *o;

   if (w < 0) w = -w;
   if (h < 0) h = -h;
   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   return;
   MAGIC_CHECK_END();
   if ((o->cur.fill.x == x) &&
       (o->cur.fill.y == y) &&
       (o->cur.fill.w == w) &&
       (o->cur.fill.h == h)) return;
   o->cur.fill.x = x;
   o->cur.fill.y = y;
   o->cur.fill.w = w;
   o->cur.fill.h = h;
   o->changed = 1;
   o->gradient_changed = 1;
   evas_object_change(obj);
}

/**
 * Retrieves the dimensions of the rectangle on the gradient object that
 * the gradient will use as its fill rect.
 *
 * See @ref evas_object_gradient_fill_set for more details.
 *
 * @param   obj The given evas gradient object.
 * @param   x   Pointer to an Evas_Coord to store the X coordinate in.
 * @param   y   Pointer to an Evas_Coord to store the Y coordinate in.
 * @param   w   Pointer to an Evas_Coord to store the width in.
 * @param   h   Pointer to an Evas_Coord to store the height in.
 * @ingroup Evas_Object_Gradient_Fill_Group
 */
void
evas_object_gradient_fill_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
{
   Evas_Object_Gradient *o;

   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   if (x) *x = 0;
   if (y) *y = 0;
   if (w) *w = 0;
   if (h) *h = 0;
   return;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   if (x) *x = 0;
   if (y) *y = 0;
   if (w) *w = 0;
   if (h) *h = 0;
   return;
   MAGIC_CHECK_END();
   if (x) *x = o->cur.fill.x;
   if (y) *y = o->cur.fill.y;
   if (w) *w = o->cur.fill.w;
   if (h) *h = o->cur.fill.h;
}

/**
 * Sets the tiling mode for the given evas gradient object.
 * @param   obj   The given evas gradient object.
 * @param   spread One of EVAS_TEXTURE_RESTRICT, EVAS_TEXTURE_REPEAT,
 * or EVAS_TEXTURE_REFLECT.
 * @ingroup Evas_Object_Gradient_Group
 */
void
evas_object_gradient_spread_set(Evas_Object *obj, int spread)
{
   Evas_Object_Gradient *o;

   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   return;
   MAGIC_CHECK_END();
   if (spread == o->cur.spread) return;
   o->cur.spread = spread;
   o->changed = 1;
   o->gradient_changed = 1;
   if (spread == EVAS_TEXTURE_RESTRICT)
      o->cur.gradient_opaque = 0;
   evas_object_change(obj);
}

/**
 * Retrieves the spread (tiling mode) for the given gradient object.
 * @param   obj The given evas gradient object.
 * @return  The current spread mode of the gradient object.
 * @ingroup Evas_Object_Gradient_Group
 */
int
evas_object_gradient_spread_get(Evas_Object *obj)
{
   Evas_Object_Gradient *o;

   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return EVAS_TEXTURE_REFLECT;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   return EVAS_TEXTURE_REFLECT;
   MAGIC_CHECK_END();
   return o->cur.spread;
}

/**
 * @defgroup Evas_Object_Gradient_Type_Group Gradient Object Type Functions
 *
 * Functions that set or get a gradient's geometric type. Examples are "linear",
 * "radial", "rectangular", "sinusoidal", ... Some types may accept added parameters
 * to further specify the look.
 */

/**
 * Sets the geometric type displayed by the given gradient object.
 * @param   obj  The given gradient object.
 * @param   name Name of the geometric type that the gradient is to be drawn as.
 * @param   params List of allowable param_name, param_value pairs. Must be in the
 * format "param_name=param_value; param_name2=param_value2;", eg. "amplitude=0.8;".
 * Can be NULL.
 * @ingroup Evas_Object_Gradient_Type_Group
 */
void
evas_object_gradient_type_set(Evas_Object *obj, const char *name, const char *params)
{
   Evas_Object_Gradient *o;

   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   return;
   MAGIC_CHECK_END();
   if (!name || !*name)
     {
	name = "linear";
	params = NULL;
     }
   if (params && !*params)
	params = NULL;
   if ((o->cur.type.name) && (!strcmp(o->cur.type.name, name)))
     {
	if ((!o->cur.type.params) && (!params))
	  return;
	if ((o->cur.type.params) && (params) && (!strcmp(o->cur.type.params, params)))
	  return;
	if (o->cur.type.params)
	  {
	    if (o->prev.type.params == o->cur.type.params)
		o->prev.type.params = strdup(o->cur.type.params);
	    free(o->cur.type.params);
	    o->cur.type.params = NULL;
	  }
	if (params)
	  o->cur.type.params = strdup(params);
	o->changed = 1;
	o->gradient_changed = 1;
	evas_object_change(obj);
	return;
     }

   if (o->cur.type.name)
     {
	if (o->prev.type.name == o->cur.type.name)
	  o->prev.type.name = strdup(o->cur.type.name);
	free(o->cur.type.name);
	o->cur.type.name = NULL;
     }
   o->cur.type.name = strdup(name);

   if (o->cur.type.params)
     {
	if (o->prev.type.params == o->cur.type.params)
	  o->prev.type.params = strdup(o->cur.type.params);
	free(o->cur.type.params);
	o->cur.type.params = NULL;
     }
   if (params)
	o->cur.type.params = strdup(params);
   o->changed = 1;
   o->gradient_changed = 1;
   evas_object_change(obj);
}

/**
 * Retrieves the type name and params of the given gradient object.
 * @param   obj  The given gradient object.
 * @param   name Pointer to a character pointer to store the pointer to the type
 *               name in.
 * @param   params  Pointer to a character pointer to store the pointer to the type
 *               params string in.
 * @ingroup Evas_Object_Gradient_Type_Group
 */
void
evas_object_gradient_type_get(Evas_Object *obj, char **name, char **params)
{
   Evas_Object_Gradient *o;

   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   if (name) *name = NULL;
   if (params) *params = NULL;
   return;
   MAGIC_CHECK_END();
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   if (name) *name = NULL;
   if (params) *params = NULL;
   return;
   MAGIC_CHECK_END();
   if (name) *name = o->cur.type.name;
   if (params) *params = o->cur.type.params;
}


/*
  these two functions don't really belong here as they can apply to other
  objs as well, but for now..
*/

/**
   FIXME: ...
**/
void
evas_color_hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b)
{
   evas_common_convert_hsv_to_rgb(h, s, v, r, g, b);
}

/**
   FIXME: ...
**/
void
evas_color_rgb_to_hsv(int r, int g, int b, float *h, float *s, float *v)
{
   evas_common_convert_rgb_to_hsv(r, g, b, h, s, v);
}



/* all nice and private */
static void
evas_object_gradient_init(Evas_Object *obj)
{
   /* alloc image ob, setup methods and default values */
   obj->object_data = evas_object_gradient_new();
   /* set up default settings for this kind of object */
   obj->cur.color.r = 255;
   obj->cur.color.g = 255;
   obj->cur.color.b = 255;
   obj->cur.color.a = 255;
   obj->cur.geometry.x = 0.0;
   obj->cur.geometry.y = 0.0;
   obj->cur.geometry.w = 32.0;
   obj->cur.geometry.h = 32.0;
   obj->cur.layer = 0;
   obj->cur.anti_alias = 1;
   obj->cur.interpolation.color_space = EVAS_COLOR_SPACE_ARGB;
   /* set up object-specific settings */
   obj->prev = obj->cur;
   /* set up methods (compulsory) */
   obj->func = &object_func;
   obj->type = o_type;
   obj->changed = 1;
}

static void *
evas_object_gradient_new(void)
{
   Evas_Object_Gradient *o;

   /* alloc obj private data */
   o = calloc(1, sizeof(Evas_Object_Gradient));
   o->magic = MAGIC_OBJ_GRADIENT;
   o->cur.angle = 0.0;
   o->cur.spread = EVAS_TEXTURE_REFLECT;
   o->cur.fill.x = 0;
   o->cur.fill.y = 0;
   o->cur.fill.w = 32;
   o->cur.fill.h = 32;
   o->cur.type.name = strdup("linear");
   o->cur.type.params = NULL;
   o->cur.gradient_opaque = 1;
   o->prev = o->cur;
   o->gradient_changed = 1;
   o->changed = 1;
   return o;
}

static void
evas_object_gradient_free(Evas_Object *obj)
{
   Evas_Object_Gradient *o;

   /* frees private object data. very simple here */
   o = (Evas_Object_Gradient *)(obj->object_data);
   MAGIC_CHECK(o, Evas_Object_Gradient, MAGIC_OBJ_GRADIENT);
   return;
   MAGIC_CHECK_END();
   /* free obj */
   if (o->prev.type.name && (o->prev.type.name != o->cur.type.name))
	free(o->prev.type.name);
   if (o->prev.type.params && (o->prev.type.params != o->cur.type.params))
	free(o->prev.type.params);
   if (o->cur.type.name)
	free(o->cur.type.name);
   if (o->cur.type.params)
	free(o->cur.type.params);
   obj->layer->evas->engine.func->gradient_free(obj->layer->evas->engine.data.output,
						o->engine_data);
   o->magic = 0;
   free(o);
}


static void
evas_object_grad_get_fill_coords(Evas_Object *obj, Evas_Coord fx, Evas_Coord fy, Evas_Coord fw, Evas_Coord fh, Evas_Coord *fx_ret, Evas_Coord *fy_ret, Evas_Coord *fw_ret,
Evas_Coord *fh_ret)
{
   Evas_Coord  x, y, w, h;

   x = ((fx * obj->layer->evas->output.w) /
	    (Evas_Coord)obj->layer->evas->viewport.w);
   w = ((fw * obj->layer->evas->output.w) /
	(Evas_Coord)obj->layer->evas->viewport.w);
   if (fw <= 0) fw = 1;
   y = ((fy * obj->layer->evas->output.h) /
	    (Evas_Coord)obj->layer->evas->viewport.h);
   h = ((fh * obj->layer->evas->output.h) /
	(Evas_Coord)obj->layer->evas->viewport.h);
   if (fh <= 0) fh = 1;
   
   *fx_ret = x;  *fw_ret = w;
   *fy_ret = y;  *fh_ret = h;
}



static void
evas_object_gradient_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y)
{
   Evas_Object_Gradient *o;

   /* render object to surface with context, and offxet by x,y */
   o = (Evas_Object_Gradient *)(obj->object_data);
   obj->layer->evas->engine.func->context_color_set(output,
						    context,
						    255, 255, 255, 255);
   if ((obj->cur.cache.clip.r == 255) &&
       (obj->cur.cache.clip.g == 255) &&
       (obj->cur.cache.clip.b == 255) &&
       (obj->cur.cache.clip.a == 255))
     obj->layer->evas->engine.func->context_multiplier_unset(output, context);
   else
     obj->layer->evas->engine.func->context_multiplier_set(output, context,
							   obj->cur.cache.clip.r,
							   obj->cur.cache.clip.g,
							   obj->cur.cache.clip.b,
							   obj->cur.cache.clip.a);
   obj->layer->evas->engine.func->context_anti_alias_set(output, context,
							 obj->cur.anti_alias);
   obj->layer->evas->engine.func->context_color_interpolation_set(output, context,
						   obj->cur.interpolation.color_space);
   if (o->engine_data)
     {
	if (o->gradient_changed)
	    obj->layer->evas->engine.func->gradient_map(output, context, o->engine_data,
	    						o->cur.spread);   
	obj->layer->evas->engine.func->gradient_draw(output, context, surface,
						     o->engine_data,
						     obj->cur.cache.geometry.x + x,
						     obj->cur.cache.geometry.y + y,
						     obj->cur.cache.geometry.w,
						     obj->cur.cache.geometry.h,
						     o->cur.angle, o->cur.spread);
     }
}

static void
evas_object_gradient_render_pre(Evas_Object *obj)
{
   Evas_List *updates = NULL;
   Evas_Object_Gradient *o;
   int is_v, was_v;

   /* dont pre-render the obj twice! */
   if (obj->pre_render_done) return;
   obj->pre_render_done = 1;
   /* pre-render phase. this does anything an object needs to do just before */
   /* rendering. this could mean loading the image data, retrieving it from */
   /* elsewhere, decoding video etc. */
   /* then when this is done the object needs to figure if it changed and */
   /* if so what and where and add thr appropriate redraw rectangles */
   o = (Evas_Object_Gradient *)(obj->object_data);
   /* if someone is clipping this obj - go calculate the clipper */
   if (obj->cur.clipper)
     {
	if (obj->cur.cache.clip.dirty)
	  evas_object_clip_recalc(obj->cur.clipper);
	obj->cur.clipper->func->render_pre(obj->cur.clipper);
     }
   /* if it changed color */
   if ((obj->cur.color.r != obj->prev.color.r) ||
       (obj->cur.color.g != obj->prev.color.g) ||
       (obj->cur.color.b != obj->prev.color.b) ||
       (obj->cur.color.a != obj->prev.color.a))
	o->gradient_changed = 1;
   if ((obj->cur.cache.clip.r != obj->prev.cache.clip.r) ||
       (obj->cur.cache.clip.g != obj->prev.cache.clip.g) ||
       (obj->cur.cache.clip.b != obj->prev.cache.clip.b) ||   
       (obj->cur.cache.clip.a != obj->prev.cache.clip.a))  
	o->gradient_changed = 1;
   if (obj->cur.anti_alias != obj->prev.anti_alias)
	o->gradient_changed = 1;
   if (obj->cur.interpolation.color_space != obj->prev.interpolation.color_space)
	o->gradient_changed = 1;
   if (obj->cur.cache.clip.a != 255)
	o->cur.gradient_opaque = 0;
   if (o->gradient_changed && o->engine_data)
     {
	Evas_Coord  fx, fy, fw, fh;

	evas_object_grad_get_fill_coords(obj, o->cur.fill.x, o->cur.fill.y,
					 o->cur.fill.w, o->cur.fill.h,
					 &fx, &fy, &fw, &fh);
	obj->layer->evas->engine.func->gradient_fill_set(obj->layer->evas->engine.data.output, o->engine_data,
							 fx, fy, fw, fh);
	obj->layer->evas->engine.func->gradient_type_set(obj->layer->evas->engine.data.output, o->engine_data,
							 o->cur.type.name);
	obj->layer->evas->engine.func->gradient_type_params_set(obj->layer->evas->engine.data.output, o->engine_data,
							        o->cur.type.params);

 	o->engine_data = obj->layer->evas->engine.func->gradient_geometry_init(obj->layer->evas->engine.data.output, o->engine_data, o->cur.spread);
	if (o->engine_data)
	  {
	    o->cur.gradient_opaque &= !(obj->layer->evas->engine.func->gradient_alpha_get(obj->layer->evas->engine.data.output, o->engine_data, o->cur.spread));
	  }
    }
   /* now figure what changed and add draw rects */
   /* if it just became visible or invisible */
   is_v = evas_object_is_visible(obj);
   was_v = evas_object_was_visible(obj);
   if (is_v != was_v)
     {
	updates = evas_object_render_pre_visible_change(updates, obj, is_v, was_v);
	goto done;
     }
   /* its not visible - we accounted for it appearing or not so just abort */
   if (!is_v) goto done;
   /* clipper changed this is in addition to anything else for obj */
   updates = evas_object_render_pre_clipper_change(updates, obj);
   /* gradient changed */
   if (o->gradient_changed)
     {
	updates = evas_object_render_pre_prev_cur_add(updates, obj);
	goto done;
     }
   /* if we restacked (layer or just within a layer) and dont clip anyone */
   if (obj->restack)
     {
	updates = evas_object_render_pre_prev_cur_add(updates, obj);
	goto done;
     }
   /* if it changed geometry */
   if ((obj->cur.geometry.x != obj->prev.geometry.x) ||
       (obj->cur.geometry.y != obj->prev.geometry.y) ||
       (obj->cur.geometry.w != obj->prev.geometry.w) ||
       (obj->cur.geometry.h != obj->prev.geometry.h))
     {
	updates = evas_object_render_pre_prev_cur_add(updates, obj);
	goto done;
     }
   /* angle changed */
   if ((o->changed) && (o->cur.angle != o->prev.angle))
     {
	updates = evas_object_render_pre_prev_cur_add(updates, obj);
	goto done;
     }
   /* it obviously didn't change - add a NO obscure - this "unupdates"  this */
   /* area so if there were updates for it they get wiped. don't do it if we */
   /* arent fully opaque and we are visible */
   
   if (evas_object_is_visible(obj) &&
       evas_object_is_opaque(obj))
     obj->layer->evas->engine.func->output_redraws_rect_del(obj->layer->evas->engine.data.output,
							    obj->cur.cache.clip.x,
							    obj->cur.cache.clip.y,
							    obj->cur.cache.clip.w,
							    obj->cur.cache.clip.h);
   
   done:
   evas_object_render_pre_effect_updates(updates, obj, is_v, was_v);
}

static void
evas_object_gradient_render_post(Evas_Object *obj)
{
   Evas_Object_Gradient *o;

   /* this moves the current data to the previous state parts of the object */
   /* in whatever way is safest for the object. also if we don't need object */
   /* data anymore we can free it if the object deems this is a good idea */
   o = (Evas_Object_Gradient *)(obj->object_data);
   /* remove those pesky changes */
   while (obj->clip.changes)
     {
	Evas_Rectangle *r;

	r = (Evas_Rectangle *)obj->clip.changes->data;
	obj->clip.changes = evas_list_remove(obj->clip.changes, r);
	free(r);
     }
   /* move cur to prev safely for object data */
   obj->prev = obj->cur;
   obj->changed = 0;
   if (o->prev.type.name && (o->prev.type.name != o->cur.type.name))
	free(o->prev.type.name);
   if (o->prev.type.params && (o->prev.type.params != o->cur.type.params))
	free(o->prev.type.params);
   o->prev = o->cur;
   o->changed = 0;
   o->gradient_changed = 0;
}

static int
evas_object_gradient_is_opaque(Evas_Object *obj)
{
   Evas_Object_Gradient *o;

   /* this returns 1 if the internal object data implies that the object is */
   /* currently fulyl opque over the entire gradient it occupies */
   o = (Evas_Object_Gradient *)(obj->object_data);
   if (!o->engine_data) return 1;
   o->cur.gradient_opaque &=
   !(obj->layer->evas->engine.func->gradient_alpha_get(obj->layer->evas->engine.data.output,
   o->engine_data, o->cur.spread));   
   return o->cur.gradient_opaque;
 }

static int
evas_object_gradient_was_opaque(Evas_Object *obj)
{
   Evas_Object_Gradient *o;

   /* this returns 1 if the internal object data implies that the object was */
   /* currently fulyl opque over the entire gradient it occupies */
   o = (Evas_Object_Gradient *)(obj->object_data);
   if (!o->engine_data) return 1;
   return o->prev.gradient_opaque;
}