Beispiel #1
0
static gdouble
clutter_alpha_easing_func (ClutterAlpha *alpha,
                           gpointer      data G_GNUC_UNUSED)
{
  ClutterAlphaPrivate *priv = alpha->priv;
  ClutterTimeline *timeline = priv->timeline;
  gdouble t, d;

  if (G_UNLIKELY (priv->timeline == NULL))
    return 0.0;

  t = clutter_timeline_get_elapsed_time (timeline);
  d = clutter_timeline_get_duration (timeline);

  return clutter_easing_for_mode (priv->mode, t, d);
}
void
st_theme_node_transition_update (StThemeNodeTransition *transition,
                                 StThemeNode           *new_node)
{
  StThemeNodeTransitionPrivate *priv = transition->priv;
  StThemeNode *old_node;
  ClutterTimelineDirection direction;

  g_return_if_fail (ST_IS_THEME_NODE_TRANSITION (transition));
  g_return_if_fail (ST_IS_THEME_NODE (new_node));

  direction = clutter_timeline_get_direction (priv->timeline);
  old_node = (direction == CLUTTER_TIMELINE_FORWARD) ? priv->old_theme_node
                                                     : priv->new_theme_node;

  /* If the update is the reversal of the current transition,
   * we reverse the timeline.
   * Otherwise, we should initiate a new transition from the
   * current state to the new one; this is hard to do if the
   * transition is in an intermediate state, so we just cancel
   * the ongoing transition in that case.
   * Note that reversing a timeline before any time elapsed
   * results in the timeline's time position being set to the
   * full duration - this is not what we want, so we cancel the
   * transition as well in that case.
   */
  if (st_theme_node_equal (new_node, old_node))
    {
      if (clutter_timeline_get_elapsed_time (priv->timeline) > 0)
        {
          if (direction == CLUTTER_TIMELINE_FORWARD)
            clutter_timeline_set_direction (priv->timeline,
                                            CLUTTER_TIMELINE_BACKWARD);
          else
            clutter_timeline_set_direction (priv->timeline,
                                            CLUTTER_TIMELINE_FORWARD);
        }
      else
        {
          clutter_timeline_stop (priv->timeline);
          g_signal_emit (transition, signals[COMPLETED], 0);
        }
    }
  else
    {
      if (clutter_timeline_get_elapsed_time (priv->timeline) > 0)
        {
          clutter_timeline_stop (priv->timeline);
          g_signal_emit (transition, signals[COMPLETED], 0);
        }
      else
        {
          guint new_duration = st_theme_node_get_transition_duration (new_node);

          clutter_timeline_set_duration (priv->timeline, new_duration);

          /* If the change doesn't affect painting, we don't need to redraw,
           * but we still need to replace the node so that we properly share
           * caching with the painting that happens after the transition finishes.
           */
          if (!st_theme_node_paint_equal (priv->new_theme_node, new_node))
              priv->needs_setup = TRUE;

          g_object_unref (priv->new_theme_node);
          priv->new_theme_node = g_object_ref (new_node);
        }
    }
}
static void
new_frame_cb (ClutterTimeline *timeline,
	      gint frame_num,
	      TestState *state)
{
  GTimeVal current_time;
  gint current_frame;
  glong msec_diff;
  gint loop_overflow = 0;
  static gint step = 1;

  g_get_current_time (&current_time);

  current_frame = clutter_timeline_get_elapsed_time (state->timeline);

  msec_diff = (current_time.tv_sec - state->start_time.tv_sec) * 1000;
  msec_diff += (current_time.tv_usec - state->start_time.tv_usec)/1000;

  /* If we expect to have interpolated past the end of the timeline
   * we keep track of the overflow so we can determine when
   * the next timeout will happen. We then clip expected_frames
   * to TEST_TIMELINE_DURATION since clutter-timeline
   * semantics guaranty this frame is always signaled before
   * looping */
  if (state->expected_frame > TEST_TIMELINE_DURATION)
    {
      loop_overflow = state->expected_frame - TEST_TIMELINE_DURATION;
      state->expected_frame = TEST_TIMELINE_DURATION;
    }

  if (current_frame >= (state->expected_frame-TEST_ERROR_TOLERANCE)
      && current_frame <= (state->expected_frame+TEST_ERROR_TOLERANCE))
    {
      g_test_message ("elapsed milliseconds=%-5li "
		      "expected frame=%-4i actual frame=%-4i (OK)",
		      msec_diff,
		      state->expected_frame,
		      current_frame);
    }
  else
    {
      g_test_message ("elapsed milliseconds=%-5li "
		      "expected frame=%-4i actual frame=%-4i (FAILED)",
		      msec_diff,
		      state->expected_frame,
		      current_frame);
      state->passed = FALSE;
    }

  if (step>0)
    {
      state->expected_frame = current_frame + (TEST_TIMELINE_FPS / 4);
      g_test_message ("Sleeping for 250ms "
		      "so next frame should be (%i + %i) = %i",
		      current_frame,
		      (TEST_TIMELINE_FPS / 4),
		      state->expected_frame);
      g_usleep (250000);
    }
  else
    {
      state->expected_frame = current_frame + TEST_TIMELINE_FPS;
      g_test_message ("Sleeping for 1sec "
		      "so next frame should be (%i + %i) = %i",
		      current_frame,
		      TEST_TIMELINE_FPS,
		      state->expected_frame);
      g_usleep (1000000);
    }

  if (current_frame >= TEST_TIMELINE_DURATION)
    {
      state->expected_frame += loop_overflow;
      state->expected_frame -= TEST_TIMELINE_DURATION;
      g_test_message ("End of timeline reached: "
		      "Wrapping expected frame too %i",
		      state->expected_frame);
    }

  state->new_frame_counter++;
  step = -step;
}