~ubuntu-branches/ubuntu/vivid/clutter-1.0/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/conform/texture.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2012-05-01 23:50:39 UTC
  • mfrom: (4.1.22 experimental)
  • Revision ID: package-import@ubuntu.com-20120501235039-7wehcmtr33nqhv67
Tags: 1.10.4-2
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <glib.h>
 
2
#include <clutter/clutter.h>
 
3
#include <string.h>
 
4
 
 
5
#include "test-conform-common.h"
 
6
 
 
7
static CoglHandle
 
8
make_texture (void)
 
9
{
 
10
  guint32 *data = g_malloc (100 * 100 * 4);
 
11
  int x;
 
12
  int y;
 
13
 
 
14
  for (y = 0; y < 100; y ++)
 
15
    for (x = 0; x < 100; x++)
 
16
      {
 
17
        if (x < 50 && y < 50)
 
18
          data[y * 100 + x] = 0xff00ff00;
 
19
        else
 
20
          data[y * 100 + x] = 0xff00ffff;
 
21
      }
 
22
  return cogl_texture_new_from_data (100,
 
23
                                     100,
 
24
                                     COGL_TEXTURE_NONE,
 
25
                                     COGL_PIXEL_FORMAT_ARGB_8888,
 
26
                                     COGL_PIXEL_FORMAT_ARGB_8888,
 
27
                                     400,
 
28
                                     (guchar *)data);
 
29
}
 
30
 
 
31
void
 
32
texture_pick_with_alpha (TestConformSimpleFixture *fixture,
 
33
                         gconstpointer data)
 
34
{
 
35
  ClutterTexture *tex = CLUTTER_TEXTURE (clutter_texture_new ());
 
36
  ClutterStage *stage = CLUTTER_STAGE (clutter_stage_new ());
 
37
  ClutterActor *actor;
 
38
 
 
39
  clutter_texture_set_cogl_texture (tex, make_texture ());
 
40
 
 
41
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (tex));
 
42
 
 
43
  clutter_actor_show (CLUTTER_ACTOR (stage));
 
44
 
 
45
  if (g_test_verbose ())
 
46
    {
 
47
      g_print ("\nstage = %p\n", stage);
 
48
      g_print ("texture = %p\n\n", tex);
 
49
    }
 
50
 
 
51
  clutter_texture_set_pick_with_alpha (tex, TRUE);
 
52
  if (g_test_verbose ())
 
53
    g_print ("Testing with pick-with-alpha enabled:\n");
 
54
 
 
55
  /* This should fall through and hit the stage: */
 
56
  actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 10, 10);
 
57
  if (g_test_verbose ())
 
58
    g_print ("actor @ (10, 10) = %p\n", actor);
 
59
  g_assert (actor == CLUTTER_ACTOR (stage));
 
60
 
 
61
  /* The rest should hit the texture */
 
62
  actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 90, 10);
 
63
  if (g_test_verbose ())
 
64
    g_print ("actor @ (90, 10) = %p\n", actor);
 
65
  g_assert (actor == CLUTTER_ACTOR (tex));
 
66
  actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 90, 90);
 
67
  if (g_test_verbose ())
 
68
    g_print ("actor @ (90, 90) = %p\n", actor);
 
69
  g_assert (actor == CLUTTER_ACTOR (tex));
 
70
  actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 10, 90);
 
71
  if (g_test_verbose ())
 
72
    g_print ("actor @ (10, 90) = %p\n", actor);
 
73
  g_assert (actor == CLUTTER_ACTOR (tex));
 
74
 
 
75
  clutter_texture_set_pick_with_alpha (tex, FALSE);
 
76
  if (g_test_verbose ())
 
77
    g_print ("Testing with pick-with-alpha disabled:\n");
 
78
 
 
79
  actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 10, 10);
 
80
  if (g_test_verbose ())
 
81
    g_print ("actor @ (10, 10) = %p\n", actor);
 
82
  g_assert (actor == CLUTTER_ACTOR (tex));
 
83
 
 
84
  clutter_actor_destroy (CLUTTER_ACTOR (stage));
 
85
 
 
86
  if (g_test_verbose ())
 
87
    g_print ("OK\n");
 
88
}
 
89