void
swfdec_test_test_render (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
    SwfdecAsValue *argv, SwfdecAsValue *retval)
{
  SwfdecTestTest *test;
  SwfdecTestImage *image;
  int x = 0, y = 0, w = 0, h = 0;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "|iiii", &x, &y, &w, &h);

  if (!test->plugin_loaded || test->plugin_error || test->plugin_quit)
    return;

  if (argc == 0) {
    w = test->plugin.width;
    h = test->plugin.height;
  }
  image = swfdec_test_image_new (cx, w, h);

  if (test->plugin.screenshot) {
    test->plugin.screenshot (&test->plugin, 
	cairo_image_surface_get_data (SWFDEC_TEST_IMAGE (image)->surface),
	x, y, w, h);
    SWFDEC_AS_VALUE_SET_OBJECT (retval, swfdec_as_relay_get_as_object (SWFDEC_AS_RELAY (image)));
  } else {
    swfdec_test_throw (cx, "plugin doesn't implement render");
  }
}
Esempio n. 2
0
void
swfdec_bitmap_data_setPixel32 (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  SwfdecBitmapData *bitmap;
  guint x, y, color;
  guint8 *addr;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "iii", &x, &y, &color);

  if (bitmap->surface == NULL ||
      x >= (guint) cairo_image_surface_get_width (bitmap->surface) ||
      y >= (guint) cairo_image_surface_get_height (bitmap->surface))
    return;

  addr = cairo_image_surface_get_data (bitmap->surface);
  addr += cairo_image_surface_get_stride (bitmap->surface) * y;
  addr += 4 * x;
  if (swfdec_surface_has_alpha (bitmap->surface)) {
    *(SwfdecColor *) (gpointer) addr = SWFDEC_COLOR_MULTIPLY ((SwfdecColor) color);
  } else {
    *(SwfdecColor *) (gpointer) addr = SWFDEC_COLOR_OPAQUE ((SwfdecColor) color);
  }
  cairo_surface_mark_dirty_rectangle (bitmap->surface, x, y, 1, 1);
  swfdec_bitmap_data_invalidate (bitmap, x, y, 1, 1);
}
Esempio n. 3
0
void
swfdec_bitmap_data_clone (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  SwfdecBitmapData *bitmap, *clone;
  cairo_t *cr;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "");

  if (bitmap->surface == NULL)
    return;

  clone = swfdec_bitmap_data_new (cx,
      swfdec_surface_has_alpha (bitmap->surface),
      cairo_image_surface_get_width (bitmap->surface),
      cairo_image_surface_get_height (bitmap->surface));
  if (clone == NULL)
    return;

  cr = cairo_create (clone->surface);
  cairo_set_source_surface (cr, bitmap->surface, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);
  SWFDEC_AS_VALUE_SET_OBJECT (ret, SWFDEC_AS_OBJECT (clone));
}
void
swfdec_xml_socket_send (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  SwfdecXmlSocket *xml;
  SwfdecBuffer *buf;
  const char *send;
  gsize len;

  SWFDEC_AS_CHECK (0, NULL, "s", &send);
  if (argc < 1)
    return;

  xml = swfdec_xml_socket_get (object);
  if (xml == NULL)
    return;
  if (!swfdec_stream_is_open (SWFDEC_STREAM (xml->socket))) {
    SWFDEC_WARNING ("sending data down a closed stream");
    return;
  }

  len = strlen (send) + 1;
  buf = swfdec_buffer_new_for_data (g_memdup (send, len), len);

  if (swfdec_buffer_queue_get_depth (xml->send_queue) == 0) {
    swfdec_buffer_queue_push (xml->send_queue, buf);
    swfdec_xml_socket_do_write (xml);
  } else {
    swfdec_buffer_queue_push (xml->send_queue, buf);
  }
}
Esempio n. 5
0
void
swfdec_bitmap_data_get_rectangle (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  SwfdecBitmapData *bitmap;
  SwfdecAsObject *o;
  SwfdecAsValue args[4];

  SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "");

  SWFDEC_AS_VALUE_SET_INT (ret, -1);
  if (bitmap->surface == NULL)
    return;
  
  swfdec_as_object_get_variable (cx->global, SWFDEC_AS_STR_flash, args);
  if (!SWFDEC_AS_VALUE_IS_OBJECT (args))
    return;
  o = SWFDEC_AS_VALUE_GET_OBJECT (args);
  swfdec_as_object_get_variable (o, SWFDEC_AS_STR_geom, args);
  if (!SWFDEC_AS_VALUE_IS_OBJECT (args))
    return;
  o = SWFDEC_AS_VALUE_GET_OBJECT (args);
  swfdec_as_object_get_variable (o, SWFDEC_AS_STR_Rectangle, args);
  if (!SWFDEC_AS_VALUE_IS_OBJECT (args))
    return;
  o = SWFDEC_AS_VALUE_GET_OBJECT (args);
  if (!SWFDEC_IS_AS_FUNCTION (o))
    return;

  SWFDEC_AS_VALUE_SET_INT (&args[0], 0);
  SWFDEC_AS_VALUE_SET_INT (&args[1], 0);
  SWFDEC_AS_VALUE_SET_INT (&args[2], cairo_image_surface_get_width (bitmap->surface));
  SWFDEC_AS_VALUE_SET_INT (&args[3], cairo_image_surface_get_height (bitmap->surface));
  swfdec_as_object_create (SWFDEC_AS_FUNCTION (o), 4, args, ret);
}
Esempio n. 6
0
void
swfdec_bitmap_data_construct (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  SwfdecBitmapData *bitmap;
  int w, h;
  gboolean transparent = TRUE;
  guint color = 0;

  if (!swfdec_as_context_is_constructing (cx))
    return;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "ii|bi", 
      &w, &h, &transparent, &color);
  
  if (w > 2880 || w <= 0 || h > 2880 || h <= 0) {
    SWFDEC_FIXME ("the constructor should return undefined here");
    return;
  }

  if (!swfdec_as_context_try_use_mem (cx, w * h * 4))
    return;
  bitmap->surface = cairo_image_surface_create (
      transparent ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, w, h);

  if (color) {
    cairo_t *cr = cairo_create (bitmap->surface);
    swfdec_color_set_source (cr, transparent ? color : SWFDEC_COLOR_OPAQUE (color));
    cairo_paint (cr);
    cairo_destroy (cr);
  }
}
Esempio n. 7
0
void
swfdec_video_clear (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
    SwfdecAsValue *argv, SwfdecAsValue *rval)
{
  SwfdecVideoMovie *video;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_VIDEO_MOVIE, &video, "");

  swfdec_video_movie_clear (video);
}
Esempio n. 8
0
void
swfdec_bitmap_data_do_dispose (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  SwfdecBitmapData *bitmap;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "");

  swfdec_bitmap_data_clear (bitmap);
}
void
swfdec_as_math_random (SwfdecAsContext *cx, SwfdecAsObject *object, 
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double unused, unused2;

  *ret = swfdec_as_value_from_number (cx, NAN);
  SWFDEC_AS_CHECK (0, NULL, "|nn", &unused, &unused2);

  *ret = swfdec_as_value_from_number (cx, g_rand_double (cx->rand));
}
void
swfdec_as_math_abs (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double d, unused;

  *ret = swfdec_as_value_from_number (cx, NAN);
  SWFDEC_AS_CHECK (0, NULL, "n|n", &d, &unused);

  *ret = swfdec_as_value_from_number (cx, fabs (d));
}
void
swfdec_color_transform_as_get_redMultiplier (SwfdecAsContext *cx,
    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
    SwfdecAsValue *ret)
{
  SwfdecColorTransformAs *transform;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS, &transform, "");

  *ret = swfdec_as_value_from_number (cx, transform->ra);
}
void
swfdec_as_math_atan2 (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double x, y;

  *ret = swfdec_as_value_from_number (cx, NAN);
  SWFDEC_AS_CHECK (0, NULL, "nn", &y, &x);

  *ret = swfdec_as_value_from_number (cx, atan2 (y, x));
}
Esempio n. 13
0
void
swfdec_as_math_pow (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double x, y;

  SWFDEC_AS_VALUE_SET_NUMBER (ret, NAN);
  SWFDEC_AS_CHECK (0, NULL, "nn", &x, &y);

  SWFDEC_AS_VALUE_SET_NUMBER (ret, isfinite (x) ? pow (x, y): NAN);
}
void
swfdec_test_test_reset (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
    SwfdecAsValue *argv, SwfdecAsValue *retval)
{
  SwfdecTestTest *test;
  const char *filename = NULL;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "|s", &filename);

  swfdec_test_do_reset (test, filename);
}
Esempio n. 15
0
void
swfdec_as_math_random (SwfdecAsContext *cx, SwfdecAsObject *object, 
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double unused, unused2;

  SWFDEC_AS_VALUE_SET_NUMBER (ret, NAN);
  SWFDEC_AS_CHECK (0, NULL, "|nn", &unused, &unused2);

  SWFDEC_AS_VALUE_SET_NUMBER (ret, g_rand_double (cx->rand));
}
Esempio n. 16
0
void
swfdec_as_math_abs (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double d, unused;

  SWFDEC_AS_VALUE_SET_NUMBER (ret, NAN);
  SWFDEC_AS_CHECK (0, NULL, "n|n", &d, &unused);

  SWFDEC_AS_VALUE_SET_NUMBER (ret, fabs (d));
}
Esempio n. 17
0
void
swfdec_as_math_atan2 (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double x, y;

  SWFDEC_AS_VALUE_SET_NUMBER (ret, NAN);
  SWFDEC_AS_CHECK (0, NULL, "nn", &y, &x);

  SWFDEC_AS_VALUE_SET_NUMBER (ret, atan2 (y, x));
}
Esempio n. 18
0
void
swfdec_bitmap_data_get_height (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  SwfdecBitmapData *bitmap;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "");

  SWFDEC_AS_VALUE_SET_INT (ret, bitmap->surface ? 
      cairo_image_surface_get_height (bitmap->surface) : -1);
}
void
swfdec_as_math_pow (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double x, y;

  *ret = swfdec_as_value_from_number (cx, NAN);
  SWFDEC_AS_CHECK (0, NULL, "nn", &x, &y);

  *ret = swfdec_as_value_from_number (cx, isfinite (x) ? pow (x, y): NAN);
}
void
swfdec_test_test_get_quit (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
    SwfdecAsValue *argv, SwfdecAsValue *retval)
{
  SwfdecTestTest *test;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "");

  /* FIXME: or not quit on error? */
  SWFDEC_AS_VALUE_SET_BOOLEAN (retval, !test->plugin_loaded || test->plugin_error || test->plugin_quit);
}
void
swfdec_color_transform_as_set_redMultiplier (SwfdecAsContext *cx,
    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
    SwfdecAsValue *ret)
{
  SwfdecColorTransformAs *transform;
  double value;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS, &transform, "n", &value);

  transform->ra = value;
}
void
swfdec_test_test_get_rate (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
    SwfdecAsValue *argv, SwfdecAsValue *retval)
{
  SwfdecTestTest *test;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "");

  if (!test->plugin_loaded)
    return;
  
  *retval = swfdec_as_value_from_number (cx, test->plugin.rate / 256.0);
}
void
swfdec_xml_socket_connect (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  const char *host;
  int port;

  SWFDEC_AS_CHECK (0, NULL, "si", &host, &port);

  if (object == NULL || object->movie)
    return;

  swfdec_xml_socket_create (object, swfdec_sandbox_get (SWFDEC_PLAYER (cx)), host, port);
}
Esempio n. 24
0
void
swfdec_as_math_min (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double x, y;

  if (argc == 0) {
    SWFDEC_AS_VALUE_SET_NUMBER (ret, HUGE_VAL);
  } else {
    SWFDEC_AS_VALUE_SET_NUMBER (ret, NAN);
  }
  SWFDEC_AS_CHECK (0, NULL, "nn", &x, &y);

  SWFDEC_AS_VALUE_SET_NUMBER (ret, isnan (x) || isnan (y) ? NAN : MIN (x, y));
}
void
swfdec_as_math_min (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  double x, y;

  if (argc == 0) {
    *ret = swfdec_as_value_from_number (cx, HUGE_VAL);
  } else {
    *ret = swfdec_as_value_from_number (cx, NAN);
  }
  SWFDEC_AS_CHECK (0, NULL, "nn", &x, &y);

  *ret = swfdec_as_value_from_number (cx, isnan (x) || isnan (y) ? NAN : MIN (x, y));
}
Esempio n. 26
0
void
swfdec_as_function_apply (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  SwfdecAsValue *argv_pass = NULL;
  int length = 0;
  SwfdecAsFunction *fun;
  SwfdecAsObject *thisp = NULL;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_AS_FUNCTION, &fun, "|O", &thisp);

  if (thisp == NULL)
    thisp = swfdec_as_object_new_empty (cx);

  if (argc > 1 && SWFDEC_AS_VALUE_IS_OBJECT (&argv[1])) {
    int i;
    SwfdecAsObject *array;
    SwfdecAsValue val;

    array = SWFDEC_AS_VALUE_GET_OBJECT (&argv[1]);

    swfdec_as_object_get_variable (array, SWFDEC_AS_STR_length, &val);
    length = swfdec_as_value_to_integer (cx, &val);

    if (length > 0) {
      /* FIXME: find a smarter way to do this, like providing argv not as an array */
      if (!swfdec_as_context_try_use_mem (cx, sizeof (SwfdecAsValue) * length)) {
	swfdec_as_context_abort (cx, "too many arguments to Function.apply");
	return;
      }
      argv_pass = g_malloc (sizeof (SwfdecAsValue) * length);

      for (i = 0; i < length; i++) {
	swfdec_as_object_get_variable (array,
	    swfdec_as_integer_to_string (cx, i), &argv_pass[i]);
      }
    } else {
      length = 0;
    }
  }

  swfdec_as_function_call (fun, thisp, length, argv_pass, ret);

  if (argv_pass) {
    swfdec_as_context_unuse_mem (cx, sizeof (SwfdecAsValue) * length);
    g_free (argv_pass);
  }
}
void
swfdec_test_test_get_trace (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
    SwfdecAsValue *argv, SwfdecAsValue *retval)
{
  SwfdecTestTest *test;
  SwfdecTestBuffer *buf;
  SwfdecBuffer *buffer;
  gsize len;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "");

  len = swfdec_buffer_queue_get_depth (test->trace);
  buffer = swfdec_buffer_queue_peek (test->trace, len);
  buf = swfdec_test_buffer_new (cx, buffer);
  SWFDEC_AS_VALUE_SET_OBJECT (retval, swfdec_as_relay_get_as_object (SWFDEC_AS_RELAY (buf)));
}
Esempio n. 28
0
void
swfdec_bitmap_data_get_transparent (SwfdecAsContext *cx,
    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
    SwfdecAsValue *ret)
{
  SwfdecBitmapData *bitmap;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "");

  if (bitmap->surface) {
    SWFDEC_AS_VALUE_SET_BOOLEAN (ret, 
	swfdec_surface_has_alpha (bitmap->surface) ? TRUE : FALSE);
  } else {
    SWFDEC_AS_VALUE_SET_INT (ret, -1);
  }
}
void
swfdec_system_security_loadPolicyFile (SwfdecAsContext *cx,
    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
    SwfdecAsValue *ret)
{
  SwfdecPlayer *player;
  const char *url_string;
  SwfdecURL *url;

  SWFDEC_AS_CHECK (0, NULL, "s", &url_string);

  player = SWFDEC_PLAYER (cx);
  url = swfdec_player_create_url (player, url_string);
  swfdec_player_request_resource (player, swfdec_system_security_do_loadPolicyFile, 
      url, (GDestroyNotify) swfdec_url_free);
}
void
swfdec_color_transform_as_set_rgb (SwfdecAsContext *cx,
    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
    SwfdecAsValue *ret)
{
  SwfdecColorTransformAs *transform;
  int value;

  SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS, &transform, "i", &value);

  transform->ra = 0;
  transform->ga = 0;
  transform->ba = 0;
  transform->rb = (value & 0xFF0000) >> 16;
  transform->gb = (value & 0x00FF00) >> 8;
  transform->bb = (value & 0x0000FF);
}