Пример #1
0
/*
 * clutter_test_init:
 * @argc: (inout): number of arguments in @argv
 * @argv: (inout) (array length=argc) (nullable): array of arguments
 *
 * Initializes the Clutter test environment.
 *
 * Since: 1.18
 */
void
clutter_test_init (int    *argc,
                   char ***argv)
{
  gboolean no_display = FALSE;

  if (G_UNLIKELY (test_environ != NULL))
    g_error ("Attempting to initialize the test suite more than once, "
             "aborting...\n");

#ifdef CLUTTER_WINDOWING_X11
  /* on X11 backends we need the DISPLAY environment set.
   *
   * check_windowing_backend() will pre-initialize the Clutter
   * backend object.
   */
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11))
    {
      const char *display = g_getenv ("DISPLAY");

      if (display == NULL || *display == '\0')
        {
          g_test_message ("No DISPLAY environment variable found, but we require a "
                          "DISPLAY set in order to run the conformance test suite.\n"
                          "Skipping all tests.\n");
          no_display = TRUE;

          goto out;
        }
    }
#endif

  /* we explicitly disable the synchronisation to the vertical refresh
   * rate, and run the master clock using a 60 fps timer instead.
   */
  _clutter_set_sync_to_vblank (FALSE);

  /* perform the actual initialization */
  g_assert (clutter_init (NULL, NULL) == CLUTTER_INIT_SUCCESS);

out:
  g_test_init (argc, argv, NULL);
  g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=%s");

  /* our global state, accessible from each test unit */
  test_environ = g_new0 (ClutterTestEnvironment, 1);
  test_environ->no_display = no_display;
}
Пример #2
0
G_MODULE_EXPORT int
test_pixmap_main (int argc, char **argv)
{
  GOptionContext      *context;
  Display	      *xdpy;
  int		       screen;
  ClutterActor        *group = NULL, *label, *stage, *tex;
  Pixmap               pixmap;
  const ClutterColor   gry = { 0x99, 0x99, 0x99, 0xFF };
  Window               win_remote;
  guint		       w, h, d;
  GC		       gc;
  ClutterTimeline     *timeline;
  ClutterAlpha	      *alpha;
  ClutterBehaviour    *depth_behavior;
  int		       i;
  int                  row_height;

#ifdef CLUTTER_WINDOWING_X11
  clutter_set_windowing_backend (CLUTTER_WINDOWING_X11);
#endif

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

#ifdef CLUTTER_WINDOWING_X11
  if (!clutter_check_windowing_backend (CLUTTER_WINDOWING_X11))
    g_error ("test-pixmap requires the X11 Clutter backend.");
#endif

  xdpy = clutter_x11_get_default_display ();
  XSynchronize (xdpy, True);

  context = g_option_context_new (" - test-pixmap options");
  g_option_context_add_main_entries (context, g_options, NULL);
  g_option_context_parse (context, &argc, &argv, NULL);

  pixmap = create_pixmap (&w, &h, &d);

  screen = DefaultScreen(xdpy);
  win_remote = XCreateSimpleWindow (xdpy, DefaultRootWindow(xdpy),
				    0, 0, 200, 200,
				    0,
				    WhitePixel(xdpy, screen),
				    WhitePixel(xdpy, screen));

  XMapWindow (xdpy, win_remote);

  stage = clutter_stage_new ();
  clutter_actor_set_position (stage, 0, 150);
  clutter_actor_set_background_color (stage, &gry);
  clutter_stage_set_title (CLUTTER_STAGE (stage), "X11 Texture from Pixmap");
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  timeline = clutter_timeline_new (5000);
  g_signal_connect (timeline,
                    "completed", G_CALLBACK (timeline_completed),
                    NULL);

  alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);
  depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 400);

  if (!disable_x11)
    {
      group = clutter_group_new ();
      clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
      label = clutter_text_new_with_text ("fixed",
                                          "ClutterX11Texture (Window)");
      clutter_container_add_actor (CLUTTER_CONTAINER (group), label);
      tex = clutter_x11_texture_pixmap_new_with_window (win_remote);
      clutter_container_add_actor (CLUTTER_CONTAINER (group), tex);
      clutter_actor_set_position (tex, 0, 20);
      clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex),
                                                TRUE);
      clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex),
                                          CLUTTER_TEXTURE_QUALITY_HIGH);
      clutter_actor_set_position (group, 0, 0);
      if (!disable_animation)
        clutter_behaviour_apply (depth_behavior, group);
    }

  if (group)
    row_height = clutter_actor_get_height (group);
  else
    row_height = 0;

  /* NB: We only draw on the window after being redirected, so we dont
   * have to worry about handling expose events... */
  gc = XCreateGC (xdpy, win_remote, 0, NULL);
  XSetForeground (xdpy, gc, BlackPixel (xdpy, screen));
  XSetLineAttributes(xdpy, gc, 5, LineSolid, CapButt, JoinMiter);

  for (i = 0; i < 10; i++)
    XDrawLine (xdpy, win_remote, gc, 0+i*20, 0, 10+i*20+i, 200);


  group = clutter_group_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
  label = clutter_text_new_with_text ("fixed", "ClutterX11Texture (Pixmap)");
  clutter_container_add_actor (CLUTTER_CONTAINER (group), label);
  tex = clutter_x11_texture_pixmap_new_with_pixmap (pixmap);
  clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex),
                                            TRUE);
  clutter_container_add_actor (CLUTTER_CONTAINER (group), tex);
  clutter_actor_set_position (tex, 0, 20);
  clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex),
				      CLUTTER_TEXTURE_QUALITY_HIGH);
  /* oddly, the actor's size is 0 until it is realized, even though
     pixmap-height is set */
  clutter_actor_set_position (group, 0, row_height);
  if (!disable_animation)
    clutter_behaviour_apply (depth_behavior, group);


  g_signal_connect (stage, "key-release-event",
                    G_CALLBACK (stage_key_release_cb), (gpointer)pixmap);
  g_signal_connect (stage, "button-press-event",
                    G_CALLBACK (stage_button_press_cb), (gpointer)pixmap);

  clutter_actor_show (stage);

  if (!disable_animation)
    clutter_timeline_start (timeline);

  clutter_threads_add_timeout (1000, draw_arc, GUINT_TO_POINTER (pixmap));

  clutter_main ();

  return EXIT_SUCCESS;
}
Пример #3
0
static void
clutter_backend_real_init_events (ClutterBackend *backend)
{
  const char *input_backend = NULL;

  input_backend = g_getenv ("CLUTTER_INPUT_BACKEND");
  if (input_backend != NULL)
    input_backend = g_intern_string (input_backend);

#ifdef CLUTTER_INPUT_OSX
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_OSX) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_OSX)))
    {
      _clutter_backend_osx_events_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_WIN32
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WIN32) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_WIN32)))
    {
      _clutter_backend_win32_events_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_X11
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_X11)))
    {
      _clutter_backend_x11_events_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_GDK
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_GDK) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_GDK)))
    {
      _clutter_backend_gdk_events_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_EVDEV
  /* Evdev can be used regardless of the windowing system */
  if (input_backend != NULL &&
      strcmp (input_backend, CLUTTER_INPUT_EVDEV) == 0)
    {
      _clutter_events_evdev_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_TSLIB
  /* Tslib can be used regardless of the windowing system */
  if (input_backend != NULL &&
      strcmp (input_backend, CLUTTER_INPUT_TSLIB) == 0)
    {
      _clutter_events_tslib_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_WAYLAND
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WAYLAND) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_WAYLAND)))
    {
      _clutter_events_wayland_init (backend);
    }
  else
#endif
  if (input_backend != NULL)
    {
      if (input_backend != I_(CLUTTER_INPUT_NULL))
        g_error ("Unrecognized input backend '%s'", input_backend);
    }
  else
    g_error ("Unknown input backend");
}