コード例 #1
0
ファイル: ply-throbber.c プロジェクト: halfline/plymouth
static void
on_timeout (ply_throbber_t *throbber)
{
        double sleep_time;
        bool should_continue;

        throbber->now = ply_get_timestamp ();

        should_continue = animate_at_time (throbber,
                                           throbber->now - throbber->start_time);

        sleep_time = 1.0 / FRAMES_PER_SECOND;
        sleep_time = MAX (sleep_time - (ply_get_timestamp () - throbber->now),
                          0.005);

        if (!should_continue) {
                throbber->is_stopped = true;
                if (throbber->stop_trigger != NULL) {
                        ply_trigger_pull (throbber->stop_trigger, NULL);
                        throbber->stop_trigger = NULL;
                }
        } else {
                ply_event_loop_watch_for_timeout (throbber->loop,
                                                  sleep_time,
                                                  (ply_event_loop_timeout_handler_t)
                                                  on_timeout, throbber);
        }
}
コード例 #2
0
ファイル: ply-animation.c プロジェクト: AlfredArouna/plymouth
bool
ply_animation_start (ply_animation_t    *animation,
                     ply_pixel_display_t *display,
                     ply_trigger_t      *stop_trigger,
                     long                x,
                     long                y)
{
  assert (animation != NULL);

  if (!animation->is_stopped)
    return true;

  animation->loop = ply_event_loop_get_default ();
  animation->display = display;
  animation->stop_trigger = stop_trigger;
  animation->is_stopped = false;
  animation->stop_requested = false;

  animation->x = x;
  animation->y = y;

  animation->start_time = ply_get_timestamp ();

  ply_event_loop_watch_for_timeout (animation->loop,
                                    1.0 / FRAMES_PER_SECOND,
                                    (ply_event_loop_timeout_handler_t)
                                    on_timeout, animation);

  return true;
}
コード例 #3
0
ファイル: ply-progress.c プロジェクト: AtsKiYsPoYl/plymouth
void
ply_progress_unpause (ply_progress_t* progress)
{
  progress->start_time += ply_get_timestamp() - progress->pause_time;
  progress->paused = false;
  return;
}
コード例 #4
0
ファイル: ply-progress.c プロジェクト: AtsKiYsPoYl/plymouth
void
ply_progress_pause (ply_progress_t* progress)
{
  progress->pause_time = ply_get_timestamp ();
  progress->paused = true;
  return;
}
コード例 #5
0
ファイル: ply-throbber.c プロジェクト: halfline/plymouth
bool
ply_throbber_start (ply_throbber_t      *throbber,
                    ply_event_loop_t    *loop,
                    ply_pixel_display_t *display,
                    long                 x,
                    long                 y)
{
        assert (throbber != NULL);
        assert (throbber->loop == NULL);

        throbber->loop = loop;
        throbber->display = display;
        throbber->is_stopped = false;

        throbber->x = x;
        throbber->y = y;

        throbber->start_time = ply_get_timestamp ();

        ply_event_loop_watch_for_timeout (throbber->loop,
                                          1.0 / FRAMES_PER_SECOND,
                                          (ply_event_loop_timeout_handler_t)
                                          on_timeout, throbber);

        return true;
}
コード例 #6
0
ファイル: plugin.c プロジェクト: magcius/plymouth
static void
start_animation (ply_boot_splash_plugin_t *plugin)
{
        ply_list_node_t *node;

        if (plugin->is_animating)
                return;

        node = ply_list_get_first_node (plugin->views);
        while (node != NULL) {
                ply_list_node_t *next_node;
                view_t *view;

                view = ply_list_node_get_data (node);
                next_node = ply_list_get_next_node (plugin->views, node);

                view_start_animation (view);

                node = next_node;
        }

        plugin->is_animating = true;

        plugin->start_time = ply_get_timestamp ();
        animate_at_time (plugin, plugin->start_time);

        if (plugin->mode == PLY_BOOT_SPLASH_MODE_SHUTDOWN)
                return;

        ply_event_loop_watch_for_timeout (plugin->loop,
                                          1.0 / FRAMES_PER_SECOND,
                                          (ply_event_loop_timeout_handler_t)
                                          on_timeout, plugin);
}
コード例 #7
0
ファイル: plugin.c プロジェクト: magcius/plymouth
static ply_boot_splash_plugin_t *
create_plugin (ply_key_file_t *key_file)
{
        ply_boot_splash_plugin_t *plugin;
        char *image_dir, *image_path;

        srand ((int) ply_get_timestamp ());
        plugin = calloc (1, sizeof(ply_boot_splash_plugin_t));
        plugin->start_time = 0.0;

        plugin->logo_image = ply_image_new (PLYMOUTH_LOGO_FILE);
        image_dir = ply_key_file_get_value (key_file, "fade-throbber", "ImageDir");

        asprintf (&image_path, "%s/star.png", image_dir);
        plugin->star_image = ply_image_new (image_path);
        free (image_path);

        asprintf (&image_path, "%s/lock.png", image_dir);
        plugin->lock_image = ply_image_new (image_path);
        free (image_path);

        plugin->image_dir = image_dir;

        plugin->state = PLY_BOOT_SPLASH_DISPLAY_NORMAL;
        plugin->views = ply_list_new ();

        return plugin;
}
コード例 #8
0
ファイル: plugin.c プロジェクト: AlfredArouna/plymouth
static ply_boot_splash_plugin_t *
create_plugin (ply_key_file_t *key_file)
{
  ply_boot_splash_plugin_t *plugin;
  char *image_dir, *image_path;

  srand ((int) ply_get_timestamp ());
  plugin = calloc (1, sizeof (ply_boot_splash_plugin_t));

  plugin->logo_image = ply_image_new (PLYMOUTH_LOGO_FILE);
  image_dir = ply_key_file_get_value (key_file, "throbgress", "ImageDir");

  asprintf (&image_path, "%s/lock.png", image_dir);
  plugin->lock_image = ply_image_new (image_path);
  free (image_path);

  asprintf (&image_path, "%s/box.png", image_dir);
  plugin->box_image = ply_image_new (image_path);
  free (image_path);

  plugin->image_dir = image_dir;
  plugin->views = ply_list_new ();

  return plugin;
}
コード例 #9
0
ファイル: ply-progress.c プロジェクト: AtsKiYsPoYl/plymouth
double
ply_progress_get_time (ply_progress_t* progress)
{
  if (progress->paused)
    {
      return progress->pause_time - progress->start_time;
    }
  return ply_get_timestamp() - progress->start_time;
}
コード例 #10
0
script_lib_math_data_t *script_lib_math_setup (script_state_t *state)
{
  script_lib_math_data_t *data = malloc (sizeof (script_lib_math_data_t));

  srand ((int) ply_get_timestamp ());

  script_obj_t *math_hash = script_obj_hash_get_element (state->global, "Math");
  script_add_native_function (math_hash,
                              "Cos",
                              script_lib_math_double_from_double_function,
                              cos,
                              "value",
                              NULL);
  script_add_native_function (math_hash,
                              "Sin",
                              script_lib_math_double_from_double_function,
                              sin,
                              "value",
                              NULL);
  script_add_native_function (math_hash,
                              "Tan",
                              script_lib_math_double_from_double_function,
                              tan,
                              "value",
                              NULL);
  script_add_native_function (math_hash,
                              "ATan2",
                              script_lib_math_double_from_double_double_function,
                              atan2,
                              "value_a",
                              "value_b",
                              NULL);
  script_add_native_function (math_hash,
                              "Sqrt",
                              script_lib_math_double_from_double_function,
                              sqrt,
                              "value",
                              NULL);
  script_add_native_function (math_hash,
                              "Int",
                              script_lib_math_double_from_double_function,
                              floor,
                              "value",
                              NULL);
  script_add_native_function (math_hash,
                              "Random",
                              script_lib_math_random,
                              NULL,
                              NULL);
  script_obj_unref (math_hash);

  data->script_main_op = script_parse_string (script_lib_math_string, "script-lib-math.script");
  script_return_t ret = script_execute (state, data->script_main_op);
  script_obj_unref (ret.object);

  return data;
}
コード例 #11
0
ファイル: ply-animation.c プロジェクト: AlfredArouna/plymouth
static void
on_timeout (ply_animation_t *animation)
{
  double sleep_time;
  bool should_continue;
  animation->previous_time = animation->now;
  animation->now = ply_get_timestamp ();

#ifdef REAL_TIME_ANIMATION
  should_continue = animate_at_time (animation,
                                     animation->now - animation->start_time);
#else
  static double time = 0.0;
  time += 1.0 / FRAMES_PER_SECOND;
  should_continue = animate_at_time (animation, time);
#endif

  sleep_time = 1.0 / FRAMES_PER_SECOND;
  sleep_time = MAX (sleep_time - (ply_get_timestamp () - animation->now),
                    0.005);

  if (!should_continue)
    {
      if (animation->stop_trigger != NULL)
        {
          ply_trigger_pull (animation->stop_trigger, NULL);
          animation->stop_trigger = NULL;
        }
    }
  else
    {
      ply_event_loop_watch_for_timeout (animation->loop,
                                        sleep_time,
                                        (ply_event_loop_timeout_handler_t)
                                        on_timeout, animation);
    }
}
コード例 #12
0
ファイル: plugin.c プロジェクト: magcius/plymouth
static void
on_timeout (ply_boot_splash_plugin_t *plugin)
{
        double sleep_time;

        plugin->now = ply_get_timestamp ();

        /* The choice below is between
         *
         * 1) keeping a constant animation speed, and dropping
         * frames when necessary
         * 2) showing every frame, but slowing down the animation
         * when a frame would be otherwise dropped.
         *
         * It turns out there are parts of boot up where the animation
         * can get sort of choppy.  By default we choose 2, since the
         * nature of this animation means it looks natural even when it
         * is slowed down
         */
#ifdef REAL_TIME_ANIMATION
        animate_at_time (plugin,
                         plugin->now - plugin->start_time);
#else
        static double time = 0.0;
        time += 1.0 / FRAMES_PER_SECOND;
        animate_at_time (plugin, time);
#endif

        sleep_time = 1.0 / FRAMES_PER_SECOND;
        sleep_time = MAX (sleep_time - (ply_get_timestamp () - plugin->now),
                          0.005);

        ply_event_loop_watch_for_timeout (plugin->loop,
                                          sleep_time,
                                          (ply_event_loop_timeout_handler_t)
                                          on_timeout, plugin);
}
コード例 #13
0
ファイル: plugin.c プロジェクト: magcius/plymouth
static star_t *
star_new (int    x,
          int    y,
          double speed)
{
        star_t *star;

        star = calloc (1, sizeof(star_t));
        star->x = x;
        star->y = y;
        star->speed = speed;
        star->start_time = ply_get_timestamp ();

        return star;
}
コード例 #14
0
ファイル: ply-progress.c プロジェクト: AtsKiYsPoYl/plymouth
ply_progress_t*
ply_progress_new (void)
{
  ply_progress_t *progress = calloc (1, sizeof (ply_progress_t));
  
  progress->start_time = ply_get_timestamp();
  progress->pause_time=0;
  progress->scalar=1.0/DEFAULT_BOOT_DURATION;
  progress->pause_time=0.0;
  progress->last_percentage=0.0;
  progress->last_percentage_time=0.0;
  progress->dead_time=0.0;
  progress->next_message_percentage=0.25;
  progress->current_message_list = ply_list_new ();
  progress->previous_message_list = ply_list_new ();
  progress->paused = false;
  return progress;
}
コード例 #15
0
ファイル: plugin.c プロジェクト: halfline/plymouth
static ply_boot_splash_plugin_t *
create_plugin (ply_key_file_t *key_file)
{
        ply_boot_splash_plugin_t *plugin;
        char *image_dir, *image_path;
        char *color;

        srand ((int) ply_get_timestamp ());
        plugin = calloc (1, sizeof(ply_boot_splash_plugin_t));

        plugin->logo_image = ply_image_new (PLYMOUTH_LOGO_FILE);
        image_dir = ply_key_file_get_value (key_file, "throbgress", "ImageDir");

        asprintf (&image_path, "%s/lock.png", image_dir);
        plugin->lock_image = ply_image_new (image_path);
        free (image_path);

        asprintf (&image_path, "%s/box.png", image_dir);
        plugin->box_image = ply_image_new (image_path);
        free (image_path);

        plugin->image_dir = image_dir;
        plugin->views = ply_list_new ();

        color = ply_key_file_get_value (key_file, "throbgress", "BackgroundStartColor");

        if (color != NULL)
                plugin->background_start_color = strtol (color, NULL, 0);
        else
                plugin->background_start_color = PLYMOUTH_BACKGROUND_START_COLOR;

        free (color);

        color = ply_key_file_get_value (key_file, "throbgress", "BackgroundEndColor");

        if (color != NULL)
                plugin->background_end_color = strtol (color, NULL, 0);
        else
                plugin->background_end_color = PLYMOUTH_BACKGROUND_END_COLOR;

        free (color);

        return plugin;
}
コード例 #16
0
ファイル: ply-progress.c プロジェクト: AtsKiYsPoYl/plymouth
int
main (int    argc,
      char **argv)
{
  double percent;
  int slowness;
  double time;
  int i;
  const char* strings[10]={"foobar", "barfoo", "barbar", "foo", "foo", "bar", "foo", "more", "even more", "even even more"};
  ply_progress_t* progress = ply_progress_new ();
  
  progress->scalar = 1.0/5;  /* Original time estimate is 5 sec*/

  percent = ply_progress_get_percentage (progress);
  time = ply_progress_get_time (progress);
  printf("Time:%f   \t Percentage: %f%%\n", time, percent*100);
  srand ((int) ply_get_timestamp ());
  
  slowness = rand () % 500000 + 50000;

  for (i=0; i<2; i++)
    {
      usleep ((rand () % slowness+slowness));
      percent = ply_progress_get_percentage (progress);
      time = ply_progress_get_time (progress);
      printf("Time:%f   \t Percentage: %f%%\n", time, percent*100);
    }
  printf("Load cache\n");
  ply_progress_load_cache (progress, PLYMOUTH_TIME_DIRECTORY "/boot-duration");

  for (i=0; i<10; i++)
    {
      ply_progress_status_update (progress, strings[i]);
      usleep ((rand () % slowness+slowness));
      percent = ply_progress_get_percentage (progress);
      time = ply_progress_get_time (progress);
      printf("Time:%f   \t Percentage: %f%% \tScalar:%f\n", time, percent*100, progress->scalar);
    }
  printf("Save and free cache\n");
  ply_progress_save_cache (progress, PLYMOUTH_TIME_DIRECTORY "/boot-duration");
  ply_progress_free(progress);

  printf("\nManual set percentage run\n\n");

  progress = ply_progress_new ();
  progress->scalar = 1.0/5;  /* Original time estimate is 5 sec*/

  percent = ply_progress_get_percentage (progress);
  time = ply_progress_get_time (progress);
  printf("Time:%f   \t Percentage: %f%%\n", time, percent*100);
  srand ((int) ply_get_timestamp ());

  for (i=0; i<12; i++)
    {
      ply_progress_set_percentage (progress, (double)i/12);
      usleep ((rand () % slowness+slowness));
      percent = ply_progress_get_percentage (progress);
      time = ply_progress_get_time (progress);
      printf("Time:%f   \t Percentage: %f%% (%f%%)\tScalar:%f\n", time, percent*100, (double)i/12*100, progress->scalar);
    }
  ply_progress_free(progress);

  return 0;
}
コード例 #17
0
void
ply_progress_animation_draw (ply_progress_animation_t *progress_animation)
{
  int number_of_frames;
  int frame_number;
  ply_image_t * const * frames;
  uint32_t *previous_frame_data, *frame_data;

  if (progress_animation->is_hidden)
    return;

  number_of_frames = ply_array_get_size (progress_animation->frames);

  if (number_of_frames == 0)
    return;

  frame_number = progress_animation->percent_done * (number_of_frames - 1);

  if (progress_animation->previous_frame_number != frame_number &&
      progress_animation->transition != PLY_PROGRESS_ANIMATION_TRANSITION_NONE &&
      progress_animation->transition_duration > 0.0)
    {
      progress_animation->is_transitioning = true;
      progress_animation->transition_start_time = ply_get_timestamp ();
    }

  frames = (ply_image_t * const *) ply_array_get_elements (progress_animation->frames);

  progress_animation->frame_area.x = progress_animation->area.x;
  progress_animation->frame_area.y = progress_animation->area.y;
  frame_data = ply_image_get_data (frames[frame_number]);

  if (progress_animation->is_transitioning)
    {
      double now;
      double fade_percentage;
      double fade_out_opacity;
      int width, height;
      uint32_t* faded_data;
      now = ply_get_timestamp ();

      fade_percentage = (now - progress_animation->transition_start_time) / progress_animation->transition_duration;

      if (fade_percentage >= 1.0)
        progress_animation->is_transitioning = false;
      fade_percentage = CLAMP (fade_percentage, 0.0, 1.0);

      if (progress_animation->transition == PLY_PROGRESS_ANIMATION_TRANSITION_MERGE_FADE)
        {
          width = MAX(ply_image_get_width (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
          height = MAX(ply_image_get_height (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
          progress_animation->frame_area.width = width;
          progress_animation->frame_area.height = height;

          ply_pixel_buffer_free (progress_animation->last_rendered_frame);
          progress_animation->last_rendered_frame = ply_pixel_buffer_new (width, height);
          faded_data = ply_pixel_buffer_get_argb32_data (progress_animation->last_rendered_frame);

          image_fade_merge (frames[frame_number - 1], frames[frame_number], fade_percentage, width, height, faded_data);

          ply_pixel_display_draw_area (progress_animation->display,
                                       progress_animation->frame_area.x,
                                       progress_animation->frame_area.y,
                                       progress_animation->frame_area.width,
                                       progress_animation->frame_area.height);
        }
      else
        {
          ply_rectangle_t fill_area;

          previous_frame_data = ply_image_get_data (frames[frame_number - 1]);
          if (progress_animation->transition == PLY_PROGRESS_ANIMATION_TRANSITION_FADE_OVER)
            {
              ply_pixel_buffer_free (progress_animation->last_rendered_frame);
              progress_animation->frame_area.width = ply_image_get_width (frames[frame_number - 1]);
              progress_animation->frame_area.height = ply_image_get_height (frames[frame_number - 1]);

              progress_animation->last_rendered_frame = ply_pixel_buffer_new (progress_animation->frame_area.width,
                                                                              progress_animation->frame_area.height);
              fill_area.x = 0;
              fill_area.y = 0;
              fill_area.width = progress_animation->frame_area.width;
              fill_area.height = progress_animation->frame_area.height;
              ply_pixel_buffer_fill_with_argb32_data (progress_animation->last_rendered_frame,
                                                      &fill_area, 0, 0,
                                                      previous_frame_data);
            }
          else
            {
              fade_out_opacity = 1.0 - fade_percentage;
              progress_animation->frame_area.width = ply_image_get_width (frames[frame_number - 1]);
              progress_animation->frame_area.height = ply_image_get_height (frames[frame_number - 1]);

              fill_area.x = 0;
              fill_area.y = 0;
              fill_area.width = progress_animation->frame_area.width;
              fill_area.height = progress_animation->frame_area.height;
              ply_pixel_buffer_fill_with_argb32_data_at_opacity (progress_animation->last_rendered_frame,
                                                                 &fill_area, 0, 0,
                                                                 previous_frame_data, fade_out_opacity);
            }

          progress_animation->frame_area.width = ply_image_get_width (frames[frame_number]);
          progress_animation->frame_area.height = ply_image_get_height (frames[frame_number]);
          fill_area.x = 0;
          fill_area.y = 0;
          fill_area.width = progress_animation->frame_area.width;
          fill_area.height = progress_animation->frame_area.height;
          ply_pixel_buffer_fill_with_argb32_data_at_opacity (progress_animation->last_rendered_frame,
                                                             &fill_area, 0, 0,
                                                             frame_data, fade_percentage);

          width = MAX(ply_image_get_width (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
          height = MAX(ply_image_get_height (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
          progress_animation->frame_area.width = width;
          progress_animation->frame_area.height = height;
        }
    }
  else
    {
      ply_rectangle_t fill_area;

      ply_pixel_buffer_free (progress_animation->last_rendered_frame);
      progress_animation->frame_area.width = ply_image_get_width (frames[frame_number]);
      progress_animation->frame_area.height = ply_image_get_height (frames[frame_number]);
      progress_animation->last_rendered_frame = ply_pixel_buffer_new (progress_animation->frame_area.width,
                                                                      progress_animation->frame_area.height);

      fill_area.x = 0;
      fill_area.y = 0;
      fill_area.width = progress_animation->frame_area.width;
      fill_area.height = progress_animation->frame_area.height;
      ply_pixel_buffer_fill_with_argb32_data (progress_animation->last_rendered_frame,
                                              &fill_area, 0, 0,
                                              frame_data);
    }

  progress_animation->previous_frame_number = frame_number;

  ply_pixel_display_draw_area (progress_animation->display,
                               progress_animation->frame_area.x,
                               progress_animation->frame_area.y,
                               progress_animation->frame_area.width,
                               progress_animation->frame_area.height);
}
コード例 #18
0
ファイル: plugin.c プロジェクト: AlfredArouna/plymouth
static ply_boot_splash_plugin_t *
create_plugin (ply_key_file_t *key_file)
{
  ply_boot_splash_plugin_t *plugin;
  char *image_dir, *image_path;
  char *alignment;
  char *transition;
  char *transition_duration;
  char *color;

  srand ((int) ply_get_timestamp ());
  plugin = calloc (1, sizeof (ply_boot_splash_plugin_t));

  image_dir = ply_key_file_get_value (key_file, "two-step", "ImageDir");

  asprintf (&image_path, "%s/lock.png", image_dir);
  plugin->lock_image = ply_image_new (image_path);
  free (image_path);

  asprintf (&image_path, "%s/box.png", image_dir);
  plugin->box_image = ply_image_new (image_path);
  free (image_path);

  asprintf (&image_path, "%s/corner-image.png", image_dir);
  plugin->corner_image = ply_image_new (image_path);
  free (image_path);

  plugin->animation_dir = image_dir;

  alignment = ply_key_file_get_value (key_file, "two-step", "HorizontalAlignment");
  if (alignment != NULL)
    plugin->animation_horizontal_alignment = strtod (alignment, NULL);
  else
    plugin->animation_horizontal_alignment = .5;
  free (alignment);

  alignment = ply_key_file_get_value (key_file, "two-step", "VerticalAlignment");
  if (alignment != NULL)
    plugin->animation_vertical_alignment = strtod (alignment, NULL);
  else
    plugin->animation_vertical_alignment = .5;
  free (alignment);

  plugin->transition = PLY_PROGRESS_ANIMATION_TRANSITION_NONE;
  transition = ply_key_file_get_value (key_file, "two-step", "Transition");
  if (transition != NULL)
    {
      if (strcmp (transition, "fade-over") == 0)
        plugin->transition = PLY_PROGRESS_ANIMATION_TRANSITION_FADE_OVER;
      else if (strcmp (transition, "cross-fade") == 0)
        plugin->transition = PLY_PROGRESS_ANIMATION_TRANSITION_CROSS_FADE;
      else if (strcmp (transition, "merge-fade") == 0)
        plugin->transition = PLY_PROGRESS_ANIMATION_TRANSITION_MERGE_FADE;
    }
  free (transition);

  transition_duration = ply_key_file_get_value (key_file, "two-step", "TransitionDuration");
  if (transition_duration != NULL)
    plugin->transition_duration = strtod (transition_duration, NULL);
  else
    plugin->transition_duration = 0.0;
  free (transition_duration);

  color = ply_key_file_get_value (key_file, "two-step", "BackgroundStartColor");

  if (color != NULL)
    plugin->background_start_color = strtol (color, NULL, 0);
  else
    plugin->background_start_color = PLYMOUTH_BACKGROUND_START_COLOR;

  free (color);

  color = ply_key_file_get_value (key_file, "two-step", "BackgroundEndColor");

  if (color != NULL)
    plugin->background_end_color = strtol (color, NULL, 0);
  else
    plugin->background_end_color = PLYMOUTH_BACKGROUND_END_COLOR;

  free (color);

  plugin->views = ply_list_new ();

  return plugin;
}