[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r9594: Cache matrix parameters in ch
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r9594: Cache matrix parameters in character instances. |
Date: |
Fri, 15 Aug 2008 09:31:29 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9594
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Fri 2008-08-15 09:31:29 +0200
message:
Cache matrix parameters in character instances.
modified:
libcore/DisplayList.cpp
libcore/character.cpp
libcore/character.h
libcore/edit_text_character.cpp
libcore/movie_root.cpp
libcore/sprite_instance.cpp
testsuite/actionscript.all/TextField.as
testsuite/libcore.all/MatrixTest.cpp
testsuite/swfdec/PASSING
------------------------------------------------------------
revno: 9593.1.1
committer: Sandro Santilli <address@hidden>
branch nick: mybranch
timestamp: Thu 2008-08-14 16:10:02 +0200
message:
Add tests for setting negative scaling. It seems they break rotation...
modified:
testsuite/libcore.all/MatrixTest.cpp
------------------------------------------------------------
revno: 9593.1.2
committer: Sandro Santilli <address@hidden>
branch nick: mybranch
timestamp: Thu 2008-08-14 23:51:05 +0200
message:
Have characters maintain a cache of scale and rotation values
modified:
libcore/DisplayList.cpp
libcore/character.cpp
libcore/character.h
libcore/edit_text_character.cpp
libcore/movie_root.cpp
libcore/sprite_instance.cpp
------------------------------------------------------------
revno: 9593.1.3
committer: Sandro Santilli <address@hidden>
branch nick: mybranch
timestamp: Thu 2008-08-14 23:52:09 +0200
message:
Tests passed due to matrix components caching
modified:
testsuite/swfdec/PASSING
------------------------------------------------------------
revno: 9593.1.4
committer: Sandro Santilli <address@hidden>
branch nick: mybranch
timestamp: Thu 2008-08-14 23:53:25 +0200
message:
_xscale accuracy test success
modified:
testsuite/actionscript.all/TextField.as
=== modified file 'libcore/DisplayList.cpp'
--- a/libcore/DisplayList.cpp 2008-06-29 15:00:40 +0000
+++ b/libcore/DisplayList.cpp 2008-08-14 21:51:05 +0000
@@ -305,7 +305,7 @@
if (use_old_matrix)
{
// Use the matrix from the old character.
- ch->set_matrix(oldch->get_matrix());
+ ch->copyMatrix(*oldch); // copy matrix and caches
}
// remember bounds of old char
@@ -390,7 +390,7 @@
}
if (mat)
{
- ch->set_matrix(*mat);
+ ch->set_matrix(*mat, true); // update matrix caches
}
if(ratio)
{
@@ -981,7 +981,7 @@
// static transformation.
if( chOld->get_accept_anim_moves() )
{
- chOld->set_matrix(chNew->get_matrix());
+ chOld->copyMatrix(*chNew); // copy matrix and caches
chOld->set_cxform(chNew->get_cxform());
}
chNew->unload();
=== modified file 'libcore/character.cpp'
--- a/libcore/character.cpp 2008-07-18 11:45:21 +0000
+++ b/libcore/character.cpp 2008-08-14 21:51:05 +0000
@@ -256,8 +256,8 @@
{
const double newx = fn.arg(0).to_number();
matrix m = ptr->get_matrix();
- m.set_x_translation(PIXELS_TO_TWIPS(utility::infinite_to_zero(newx)));
- ptr->set_matrix(m);
+
m.set_x_translation(PIXELS_TO_TWIPS(utility::infinite_to_zero(newx)));
+ ptr->set_matrix(m); // no need to update caches when only
changing translation
ptr->transformedByScript(); // m_accept_anim_moves = false;
}
return rv;
@@ -280,7 +280,7 @@
const double newy = fn.arg(0).to_number();
matrix m = ptr->get_matrix();
m.set_y_translation(PIXELS_TO_TWIPS(utility::infinite_to_zero(newy)));
- ptr->set_matrix(m);
+ ptr->set_matrix(m); // no need to update caches when only
changing translation
ptr->transformedByScript(); // m_accept_anim_moves = false;
}
return rv;
@@ -295,14 +295,10 @@
as_value rv;
if ( fn.nargs == 0 ) // getter
{
- matrix m = ptr->get_matrix();
- const double xscale = m.get_x_scale();
- rv = as_value(xscale * 100); // result in percent
+ return as_value(ptr->_xscale);
}
else // setter
{
- matrix m = ptr->get_matrix();
-
const double scale_percent = fn.arg(0).to_number();
// Handle bogus values
@@ -312,12 +308,11 @@
log_aserror(_("Attempt to set _xscale to %g, refused"),
scale_percent);
);
- return as_value();
+ return as_value();
}
// input is in percent
- double scale = scale_percent / 100.0;
- ptr->set_x_scale(scale);
+ ptr->set_x_scale(scale_percent);
}
return rv;
@@ -331,14 +326,10 @@
as_value rv;
if ( fn.nargs == 0 ) // getter
{
- matrix m = ptr->get_matrix();
- const float yscale = m.get_y_scale();
- rv = as_value(yscale * 100); // result in percent
+ return ptr->_yscale;
}
else // setter
{
- matrix m = ptr->get_matrix();
-
const double scale_percent = fn.arg(0).to_number();
// Handle bogus values
@@ -352,8 +343,7 @@
}
// input is in percent
- double scale = scale_percent / 100.0;
- ptr->set_y_scale(scale);
+ ptr->set_y_scale(scale_percent);
}
return rv;
@@ -530,7 +520,7 @@
);
}
- ptr->set_y_scale( newheight / oldheight );
+ ptr->set_y_scale( 100 * (newheight / oldheight) );
}
return rv;
@@ -544,20 +534,24 @@
as_value rv;
if ( fn.nargs == 0 ) // getter
{
- double angle = ptr->get_matrix().get_rotation();
- // convert radian to degree
- angle *= 180.0 / PI;
- rv = as_value(angle);
+ return ptr->_rotation;
}
else // setter
{
- matrix m = ptr->get_matrix();
// input is in degrees
- double rotation = fn.arg(0).to_number() * PI / 180.0;
- m.set_rotation(rotation);
-
- ptr->set_matrix(m);
- ptr->transformedByScript();
+ double rotation_val = fn.arg(0).to_number();
+
+ // Handle bogus values
+ if (isnan(rotation_val))
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(_("Attempt to set _rotation to %g,
refused"),
+ rotation_val);
+ );
+ return as_value();
+ }
+
+ ptr->set_rotation(rotation_val);
}
return rv;
}
@@ -611,6 +605,34 @@
}
void
+character::copyMatrix(const character& c)
+{
+ m_matrix = c.m_matrix;
+ _xscale = c._xscale;
+ _yscale = c._yscale;
+ _rotation = c._rotation;
+}
+
+void
+character::set_matrix(const matrix& m, bool updateCache)
+{
+ assert(m.is_valid());
+ if (!(m == m_matrix))
+ {
+ set_invalidated(__FILE__, __LINE__);
+ m_matrix = m;
+
+ if ( updateCache ) // don't update caches if matrix wasn't
updated too
+ {
+ _xscale = m_matrix.get_x_scale() * 100.0;
+ _yscale = m_matrix.get_y_scale() * 100.0;
+ _rotation = m_matrix.get_rotation() * 180.0 / PI;
+ }
+ }
+
+}
+
+void
character::set_event_handlers(const Events& copyfrom)
{
for (Events::const_iterator it=copyfrom.begin(), itE=copyfrom.end();
@@ -735,25 +757,49 @@
}
void
-character::set_x_scale(float x_scale)
-{
- matrix m = get_matrix();
-
- m.set_x_scale(x_scale);
-
- set_matrix(m);
- transformedByScript(); // m_accept_anim_moves = false;
-}
-
-void
-character::set_y_scale(float y_scale)
-{
- matrix m = get_matrix();
-
- m.set_y_scale(y_scale);
-
- set_matrix(m);
- transformedByScript(); // m_accept_anim_moves = false;
+character::set_x_scale(double scale_percent)
+{
+ _xscale = scale_percent;
+
+ double scale = scale_percent / 100.0;
+ matrix m = get_matrix();
+ m.set_x_scale(scale);
+ set_matrix(m); // we updated the cache ourselves
+
+ transformedByScript();
+}
+
+void
+character::set_rotation(double rot)
+{
+ // Translate to the -180 .. 180 range
+ rot = fmod (rot, 360.0);
+ if (rot > 180.0)
+ rot -= 360.0;
+ else if (rot < -180.0)
+ rot += 360.0;
+
+ //log_debug("_rotation: %d", rot);
+ _rotation = rot;
+
+ double rotation = rot * PI / 180.0;
+ matrix m = get_matrix();
+ m.set_rotation(rotation);
+ set_matrix(m); // we updated the cache ourselves
+ transformedByScript();
+}
+
+void
+character::set_y_scale(double scale_percent)
+{
+ _yscale = scale_percent;
+
+ double scale = scale_percent / 100.0;
+ matrix m = get_matrix();
+ m.set_y_scale(scale);
+ set_matrix(m); // we updated the cache ourselves
+
+ transformedByScript();
}
=== modified file 'libcore/character.h'
--- a/libcore/character.h 2008-07-18 11:45:21 +0000
+++ b/libcore/character.h 2008-08-14 21:51:05 +0000
@@ -82,6 +82,11 @@
cxform m_color_transform;
matrix m_matrix;
+ /// Cache values for ActionScript access.
+ /// NOTE: not all characters need this, just the
+ /// ones which are ActionScript-referenceable
+ double _xscale, _yscale, _rotation;
+
/// Volume control associated to this character
//
/// This is used by Sound objects
@@ -391,6 +396,9 @@
m_depth(0),
m_color_transform(),
m_matrix(),
+ _xscale(100),
+ _yscale(100),
+ _rotation(0),
_volume(100),
m_ratio(0),
m_clip_depth(noClipDepthValue),
@@ -465,30 +473,45 @@
const matrix& get_matrix() const { return m_matrix; }
/// Set local transform matrix for this character
- void set_matrix(const matrix& m)
- {
- assert(m.is_valid());
- if (!(m == m_matrix))
- {
- set_invalidated(__FILE__, __LINE__);
- m_matrix = m;
- }
- }
+ //
+ /// @param m the new matrix to assign to this character
+ ///
+ /// @param updateCache if true, updates the cache values
+ /// from the matrix (only if matrix != current matrix)
+ ///
+ void set_matrix(const matrix& m, bool updateCache=false);
/// Set the xscale value of current matrix
//
/// This is used when setting either _xscale or _width.
/// See xscale_getset and width_getset
///
- void set_x_scale(float factor);
+ /// @param factor scale factor, in percent
+ ///
+ void set_x_scale(double factor);
+
+ /// Copy matrix and caches from given character
+ void copyMatrix(const character& ch);
/// Set the yscale value of current matrix
//
- ///
/// This is used when setting either _yscale or _height
/// See xscale_getset and width_getset
///
- void set_y_scale(float factor);
+ /// @param factor scale factor, in percent
+ ///
+ void set_y_scale(double factor);
+
+ /// Set the rotation value of current matrix
+ //
+ ///
+ /// This is used when setting _rotation
+ /// See rotation_getset
+ ///
+ /// @param rot rotation in degrees. will be trimmed to
+ /// the -180 .. 180 range, can be passed outside it.
+ ///
+ void set_rotation(double rot);
const cxform& get_cxform() const { return m_color_transform; }
=== modified file 'libcore/edit_text_character.cpp'
--- a/libcore/edit_text_character.cpp 2008-08-03 10:42:46 +0000
+++ b/libcore/edit_text_character.cpp 2008-08-14 21:51:05 +0000
@@ -925,7 +925,7 @@
matrix m = get_matrix();
double x = utility::infinite_to_fzero( val.to_number() );
m.tx = PIXELS_TO_TWIPS(x);
- set_matrix(m);
+ set_matrix(m); // no need to update caches when only changing
translation
// m_accept_anim_moves = false;
return true;
@@ -935,7 +935,7 @@
matrix m = get_matrix();
double y = utility::infinite_to_fzero( val.to_number() );
m.ty = PIXELS_TO_TWIPS(y);
- set_matrix(m);
+ set_matrix(m); // no need to update caches when only changing
translation
// m_accept_anim_moves = false;
return true;
=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp 2008-08-10 14:54:12 +0000
+++ b/libcore/movie_root.cpp 2008-08-14 21:51:05 +0000
@@ -1015,9 +1015,10 @@
parent_world_mat.invert().transform(world_mouse);
// Place our origin so that it coincides with the mouse coords
// in our parent frame.
+ // TODO: add a character::set_translation ?
matrix local = dragChar->get_matrix();
- local.set_translation(world_mouse.x, world_mouse.y);
- dragChar->set_matrix(local);
+ local.set_translation(world_mouse.x, world_mouse.y);
+ dragChar->set_matrix(local); //no need to update caches when only
changing translation
}
=== modified file 'libcore/sprite_instance.cpp'
--- a/libcore/sprite_instance.cpp 2008-08-10 15:49:15 +0000
+++ b/libcore/sprite_instance.cpp 2008-08-14 21:51:05 +0000
@@ -2746,8 +2746,6 @@
boost::intrusive_ptr<character>
sprite_instance::add_textfield(const std::string& name, int depth, float x,
float y, float width, float height)
{
- matrix txt_matrix;
-
// Create a definition (TODO: cleanup this thing, definitions should be
immutable!)
boost::intrusive_ptr<edit_text_character_def> txt = new
edit_text_character_def();
@@ -2769,9 +2767,10 @@
// Set _x and _y
x = utility::infinite_to_fzero(x);
y = utility::infinite_to_fzero(y);
+ matrix txt_matrix;
txt_matrix.set_translation(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
+ txt_char->set_matrix(txt_matrix, true); // update caches (altought shouldn't
be needed as we only set translation)
- txt_char->set_matrix(txt_matrix);
// Here we add the character to the displayList.
m_display_list.place_character(txt_char.get(), depth);
@@ -2812,7 +2811,7 @@
newsprite->_drawable = new DynamicShape(*_drawable);
newsprite->set_cxform(get_cxform());
- newsprite->set_matrix(get_matrix());
+ newsprite->copyMatrix(*this); // copy matrix and caches
newsprite->set_ratio(get_ratio());
newsprite->set_clip_depth(get_clip_depth());
@@ -3497,7 +3496,7 @@
// TODO: check if we should check those has_xxx flags first.
ch->set_cxform(tag->getCxform());
- ch->set_matrix(tag->getMatrix());
+ ch->set_matrix(tag->getMatrix(), true); // update caches
ch->set_ratio(tag->getRatio());
ch->set_clip_depth(tag->getClipDepth());
@@ -3568,7 +3567,7 @@
}
if(tag->hasMatrix())
{
- ch->set_matrix(tag->getMatrix());
+ ch->set_matrix(tag->getMatrix(), true); // update caches
}
dlist.replace_character(ch.get(), tag->getDepth(),
!tag->hasCxform(), // use matrix from the old
character if tag doesn't provide one.
=== modified file 'testsuite/actionscript.all/TextField.as'
--- a/testsuite/actionscript.all/TextField.as 2008-06-05 02:26:30 +0000
+++ b/testsuite/actionscript.all/TextField.as 2008-08-14 21:53:25 +0000
@@ -881,7 +881,7 @@
check_equals(tf._y, 11);
check_equals(tf._visible, false);
check_equals(tf._xscale, 200);
-xcheck_equals(tf._yscale, 201);
+check_equals(tf._yscale, 201);
check_equals(tf._target, '/fake_name');
check_equals(tf._parent, _level0);
check_equals(tf._name, 'fake_name');
=== modified file 'testsuite/libcore.all/MatrixTest.cpp'
--- a/testsuite/libcore.all/MatrixTest.cpp 2008-07-04 07:41:05 +0000
+++ b/testsuite/libcore.all/MatrixTest.cpp 2008-08-14 14:10:02 +0000
@@ -153,6 +153,31 @@
check_equals(m1.get_x_translation(), 5);
check_equals(m1.get_y_translation(), 6);
+ matrix m2;
+ check_equals(D(m2.get_rotation()), 0);
+ m2.set_x_scale(16);
+ check_equals(D(m2.get_x_scale()), 16);
+ check_equals(D(m2.get_y_scale()), 1);
+ check_equals(D(m2.get_rotation()), 0);
+ m2.set_x_scale(-16);
+ check_equals(D(m2.get_x_scale()), -16);
+ check_equals(D(m2.get_y_scale()), 1);
+ check_equals(D(m2.get_rotation()), 0);
+ m2.set_x_scale(16);
+ check_equals(D(m2.get_x_scale()), 16);
+ check_equals(D(m2.get_y_scale()), 1);
+ check_equals(D(m2.get_rotation()), 0);
+ m2.set_x_scale(16);
+ m2.set_y_scale(-64);
+ check_equals(D(m2.get_x_scale()), 16);
+ check_equals(D(m2.get_y_scale()), -64);
+ check_equals(D(m2.get_rotation()), 0);
+ m2.set_x_scale(16);
+ m2.set_x_scale(-128);
+ check_equals(D(m2.get_x_scale()), -128);
+ check_equals(D(m2.get_y_scale()), -64);
+ check_equals(D(m2.get_rotation()), 0);
+
//
// Test matrix concatenation
//
=== modified file 'testsuite/swfdec/PASSING'
--- a/testsuite/swfdec/PASSING 2008-07-31 08:15:13 +0000
+++ b/testsuite/swfdec/PASSING 2008-08-14 21:52:09 +0000
@@ -783,6 +783,10 @@
root-onload-7.swf:baed64fdde7c5f27344daa4268ce6202
root-onload-8.swf:25d71869e59a04c1576efb74f5b5763f
rotation2-5.swf:4edcd35e1076a14037d3531ec780d292
+rotation2-6.swf:4d97baf5830bb84b17ac9cd0847c126e
+rotation2-7.swf:832fdea08108c8329af50416d8905abb
+rotation2-8.swf:41b3692750ea8ee67989e6d764b93473
+rotation-5.swf:b06eb9fc7a109d796d5d4ade7d30cbeb
round-direction-5.swf:3a69581d4483d995a04ab3a2aa005278
round-direction-6.swf:2f7d7580490e0c4a3ddfb107849dc6d8
round-direction-7.swf:66f77f46b6695bbb4d2a2e556ed737fa
@@ -1050,6 +1054,7 @@
too-many-blocks-7.swf:001ea87d7f7a99cae8a50170892ab4ed
too-many-blocks-8.swf:882a04f9f7aa70a2994c88532d1dcc12
totalframes.swf:cdc0d5e2017d293438ef80fa136c44e8
+transform2.swf:95d19c9ed6592c459d7f6836a0365df2
transform-color-transform-5.swf:1b03afaa179024037f5d167556b3f7a9
transform-color-transform-6.swf:8cfd79068cc9d51db8796bb27186bbda
transform-color-transform-7.swf:bd48f8529157f81c30caca47ce6bb871
@@ -1105,3 +1110,4 @@
xml-socket-properties-6.swf:c2a153377e55fd70aed74a5711dc8bfd
xml-socket-properties-7.swf:ad8a3f3b1ed9a4b6f068f74f003f2260
xml-socket-properties-8.swf:a97dbf0b46416298ea32e285ea04f74f
+xscale.swf:812327246d1fea5a69001191aa45a2ef
- [Gnash-commit] /srv/bzr/gnash/trunk r9594: Cache matrix parameters in character instances.,
Sandro Santilli <=