Skip to content

Commit

Permalink
Revert 224725 "Fix compilation and ui_unittests with float trans..."
Browse files Browse the repository at this point in the history
Reverting as caused perf regression because of new static
initializers.

> Fix compilation and ui_unittests with float transforms
> 
> This change also cleans up the use of gfx::Transform::get/setDouble
> (in favor of get/set) at callsites to prepare for changing SkMScalar
> from double to float.
> 
> BUG=269817
> 
> Review URL: https://chromiumcodereview.appspot.com/23811009

TBR=enne@chromium.org

Review URL: https://codereview.chromium.org/23537065

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224732 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sky@chromium.org committed Sep 23, 2013
1 parent 9c01c37 commit 7852a50
Show file tree
Hide file tree
Showing 26 changed files with 380 additions and 426 deletions.
8 changes: 4 additions & 4 deletions cc/animation/keyframed_animation_curve_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace cc {
namespace {

void ExpectTranslateX(SkMScalar translate_x, const gfx::Transform& transform) {
EXPECT_FLOAT_EQ(translate_x, transform.matrix().get(0, 3));
void ExpectTranslateX(double translate_x, const gfx::Transform& transform) {
EXPECT_FLOAT_EQ(translate_x, transform.matrix().getDouble(0, 3));
}

void ExpectBrightness(double brightness, const FilterOperations& filter) {
Expand Down Expand Up @@ -185,8 +185,8 @@ TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) {

// There is a discontinuity at 1. Any value between 4 and 6 is valid.
gfx::Transform value = curve->GetValue(1.f);
EXPECT_GE(value.matrix().get(0, 3), 4.f);
EXPECT_LE(value.matrix().get(0, 3), 6.f);
EXPECT_GE(value.matrix().getDouble(0.f, 3.f), 4);
EXPECT_LE(value.matrix().getDouble(0.f, 3.f), 6);

ExpectTranslateX(6.f, curve->GetValue(1.5f));
ExpectTranslateX(6.f, curve->GetValue(2.f));
Expand Down
2 changes: 1 addition & 1 deletion cc/animation/transform_operation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "ui/gfx/vector3d_f.h"

namespace {
const SkMScalar kAngleEpsilon = SkDoubleToMScalar(1e-4);
const SkMScalar kAngleEpsilon = 1e-4;
}

namespace cc {
Expand Down
38 changes: 19 additions & 19 deletions cc/base/float_quad_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ namespace {
TEST(FloatQuadTest, IsRectilinearTest) {
const int kNumRectilinear = 8;
gfx::Transform rectilinear_trans[kNumRectilinear];
rectilinear_trans[1].Rotate(90.f);
rectilinear_trans[2].Rotate(180.f);
rectilinear_trans[3].Rotate(270.f);
rectilinear_trans[4].SkewX(0.00000000001f);
rectilinear_trans[5].SkewY(0.00000000001f);
rectilinear_trans[6].Scale(0.00001f, 0.00001f);
rectilinear_trans[6].Rotate(180.f);
rectilinear_trans[7].Scale(100000.f, 100000.f);
rectilinear_trans[7].Rotate(180.f);
rectilinear_trans[1].Rotate(90.0);
rectilinear_trans[2].Rotate(180.0);
rectilinear_trans[3].Rotate(270.0);
rectilinear_trans[4].SkewX(0.00000000001);
rectilinear_trans[5].SkewY(0.00000000001);
rectilinear_trans[6].Scale(0.00001, 0.00001);
rectilinear_trans[6].Rotate(180.0);
rectilinear_trans[7].Scale(100000, 100000);
rectilinear_trans[7].Rotate(180.0);

gfx::QuadF original(
gfx::RectF(0.01010101f, 0.01010101f, 100.01010101f, 100.01010101f));
Expand All @@ -38,16 +38,16 @@ TEST(FloatQuadTest, IsRectilinearTest) {

const int kNumNonRectilinear = 10;
gfx::Transform non_rectilinear_trans[kNumNonRectilinear];
non_rectilinear_trans[0].Rotate(359.9999f);
non_rectilinear_trans[1].Rotate(0.0000001f);
non_rectilinear_trans[2].Rotate(89.9999f);
non_rectilinear_trans[3].Rotate(90.00001f);
non_rectilinear_trans[4].Rotate(179.9999f);
non_rectilinear_trans[5].Rotate(180.00001f);
non_rectilinear_trans[6].Rotate(269.9999f);
non_rectilinear_trans[7].Rotate(270.0001f);
non_rectilinear_trans[8].SkewX(0.00001f);
non_rectilinear_trans[9].SkewY(0.00001f);
non_rectilinear_trans[0].Rotate(359.999);
non_rectilinear_trans[1].Rotate(0.0000001);
non_rectilinear_trans[2].Rotate(89.999999);
non_rectilinear_trans[3].Rotate(90.0000001);
non_rectilinear_trans[4].Rotate(179.999999);
non_rectilinear_trans[5].Rotate(180.0000001);
non_rectilinear_trans[6].Rotate(269.999999);
non_rectilinear_trans[7].Rotate(270.0000001);
non_rectilinear_trans[8].SkewX(0.00001);
non_rectilinear_trans[9].SkewY(0.00001);

for (int i = 0; i < kNumNonRectilinear; ++i) {
bool clipped = false;
Expand Down
12 changes: 6 additions & 6 deletions cc/base/math_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ static HomogeneousCoordinate ComputeClippedPointForEdge(
// w plane when this is called.
DCHECK(h1.ShouldBeClipped() ^ h2.ShouldBeClipped());

// ...or any positive non-zero small epsilon
double w = 0.00001;
double t = (w - h1.w()) / (h2.w() - h1.w());
SkMScalar w = 0.00001; // or any positive non-zero small epsilon

SkMScalar x = SkDoubleToMScalar((1.0 - t) * h1.x() + t * h2.x());
SkMScalar y = SkDoubleToMScalar((1.0 - t) * h1.y() + t * h2.y());
SkMScalar z = SkDoubleToMScalar((1.0 - t) * h1.z() + t * h2.z());
SkMScalar t = (w - h1.w()) / (h2.w() - h1.w());

SkMScalar x = (1 - t) * h1.x() + t * h2.x();
SkMScalar y = (1 - t) * h1.y() + t * h2.y();
SkMScalar z = (1 - t) * h1.z() + t * h2.z();

return HomogeneousCoordinate(x, y, z, w);
}
Expand Down
8 changes: 4 additions & 4 deletions cc/base/math_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ struct HomogeneousCoordinate {
bool ShouldBeClipped() const { return w() <= 0.0; }

gfx::PointF CartesianPoint2d() const {
if (w() == SK_MScalar1)
if (w() == 1.0)
return gfx::PointF(x(), y());

// For now, because this code is used privately only by MathUtil, it should
// never be called when w == 0, and we do not yet need to handle that case.
DCHECK(w());
SkMScalar inv_w = SK_MScalar1 / w();
SkMScalar inv_w = 1.0 / w();
return gfx::PointF(x() * inv_w, y() * inv_w);
}

gfx::Point3F CartesianPoint3d() const {
if (w() == SK_MScalar1)
if (w() == 1)
return gfx::Point3F(x(), y(), z());

// For now, because this code is used privately only by MathUtil, it should
// never be called when w == 0, and we do not yet need to handle that case.
DCHECK(w());
SkMScalar inv_w = SK_MScalar1 / w();
SkMScalar inv_w = 1.0 / w();
return gfx::Point3F(x() * inv_w, y() * inv_w, z() * inv_w);
}

Expand Down
2 changes: 1 addition & 1 deletion cc/base/math_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST(MathUtilTest, ProjectionOfPerpendicularPlane) {

gfx::Transform transform;
transform.MakeIdentity();
transform.matrix().set(2, 2, 0);
transform.matrix().setDouble(2, 2, 0);

gfx::RectF rect = gfx::RectF(0, 0, 1, 1);
gfx::RectF projected_rect = MathUtil::ProjectClippedRect(transform, rect);
Expand Down
10 changes: 5 additions & 5 deletions cc/layers/delegated_renderer_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class DelegatedRendererLayerImplTestTransform
gfx::Size child_pass_content_bounds(7, 7);
gfx::Rect child_pass_rect(20, 20, 7, 7);
gfx::Transform child_pass_transform;
child_pass_transform.Scale(0.8f, 0.8f);
child_pass_transform.Scale(0.8, 0.8);
child_pass_transform.Translate(9.0, 9.0);
gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
bool child_pass_clipped = false;
Expand Down Expand Up @@ -677,7 +677,7 @@ TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) {
contrib_delegated_shared_quad_state->clip_rect.ToString());
EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
expected.MakeIdentity();
expected.Scale(0.8f, 0.8f);
expected.Scale(0.8, 0.8);
expected.Translate(9.0, 9.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected,
Expand Down Expand Up @@ -740,7 +740,7 @@ TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_NoSurface) {
contrib_delegated_shared_quad_state->clip_rect.ToString());
EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
expected.MakeIdentity();
expected.Scale(0.8f, 0.8f);
expected.Scale(0.8, 0.8);
expected.Translate(9.0, 9.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected,
Expand Down Expand Up @@ -796,7 +796,7 @@ TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_Surface) {
contrib_delegated_shared_quad_state->clip_rect.ToString());
EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
expected.MakeIdentity();
expected.Scale(0.8f, 0.8f);
expected.Scale(0.8, 0.8);
expected.Translate(9.0, 9.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected,
Expand Down Expand Up @@ -851,7 +851,7 @@ TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_Surface) {
contrib_delegated_shared_quad_state->clip_rect.ToString());
EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
expected.MakeIdentity();
expected.Scale(0.8f, 0.8f);
expected.Scale(0.8, 0.8);
expected.Translate(9.0, 9.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected,
Expand Down
4 changes: 2 additions & 2 deletions cc/layers/layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) {
gfx::RectF(arbitrary_point_f, gfx::SizeF(1.234f, 5.678f));
SkColor arbitrary_color = SkColorSetRGB(10, 20, 30);
gfx::Transform arbitrary_transform;
arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f);
arbitrary_transform.Scale3d(0.1, 0.2, 0.3);
FilterOperations arbitrary_filters;
arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
skia::RefPtr<SkImageFilter> arbitrary_filter =
Expand Down Expand Up @@ -213,7 +213,7 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) {
gfx::RectF(arbitrary_point_f, gfx::SizeF(1.234f, 5.678f));
SkColor arbitrary_color = SkColorSetRGB(10, 20, 30);
gfx::Transform arbitrary_transform;
arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f);
arbitrary_transform.Scale3d(0.1, 0.2, 0.3);
FilterOperations arbitrary_filters;
arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
skia::RefPtr<SkImageFilter> arbitrary_filter =
Expand Down
10 changes: 5 additions & 5 deletions cc/output/direct_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ static gfx::Transform OrthoProjectionMatrix(float left,
gfx::Transform proj;
if (!delta_x || !delta_y)
return proj;
proj.matrix().set(0, 0, 2.0f / delta_x);
proj.matrix().set(0, 3, -(right + left) / delta_x);
proj.matrix().set(1, 1, 2.0f / delta_y);
proj.matrix().set(1, 3, -(top + bottom) / delta_y);
proj.matrix().setDouble(0, 0, 2.0f / delta_x);
proj.matrix().setDouble(0, 3, -(right + left) / delta_x);
proj.matrix().setDouble(1, 1, 2.0f / delta_y);
proj.matrix().setDouble(1, 3, -(top + bottom) / delta_y);

// Z component of vertices is always set to zero as we don't use the depth
// buffer while drawing.
proj.matrix().set(2, 2, 0);
proj.matrix().setDouble(2, 2, 0);

return proj;
}
Expand Down
8 changes: 4 additions & 4 deletions cc/output/renderer_pixeltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1329,10 +1329,10 @@ TEST_F(GLRendererPixelTest, AntiAliasingPerspective) {

gfx::Rect red_rect(0, 0, 180, 500);
gfx::Transform red_content_to_target_transform(
1.0f, 2.4520f, 10.6206f, 19.0f,
0.0f, 0.3528f, 5.9737f, 9.5f,
0.0f, -0.2250f, -0.9744f, 0.0f,
0.0f, 0.0225f, 0.0974f, 1.0f);
1.0, 2.4520, 10.6206, 19.0,
0.0, 0.3528, 5.9737, 9.5,
0.0, -0.2250, -0.9744, 0.0,
0.0, 0.0225, 0.0974, 1.0);
scoped_ptr<SharedQuadState> red_shared_state =
CreateTestSharedQuadState(red_content_to_target_transform, red_rect);
scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
Expand Down
4 changes: 2 additions & 2 deletions cc/trees/layer_sorter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ TEST(LayerSorterTest, LayersUnderPathologicalPerspectiveTransform) {
// layer_a. When it is not clipped, its bounds will actually incorrectly
// appear much smaller and the correct sorting dependency will not be found.
gfx::Transform transform_b;
transform_b.Translate3d(0.f, 0.f, 0.7f);
transform_b.Translate3d(0.0, 0.0, 0.7);
transform_b.RotateAboutYAxis(45.0);
transform_b.Translate(-5.0, -5.0);
LayerShape layer_b(10.f, 10.f, perspective_matrix * transform_b);
Expand Down Expand Up @@ -287,7 +287,7 @@ TEST(LayerSorterTest, VerifyConcidentLayerPrecisionLossResultsInDocumentOrder) {
// in calculated order.

gfx::Transform BehindMatrix;
BehindMatrix.Translate3d(0.f, 0.f, 0.999999f);
BehindMatrix.Translate3d(0.0, 0.0, 0.999999);
BehindMatrix.RotateAboutXAxis(38.5);
BehindMatrix.RotateAboutYAxis(77.0);
gfx::Transform FrontMatrix;
Expand Down
6 changes: 4 additions & 2 deletions cc/trees/layer_tree_host_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,10 @@ static void PreCalculateMetaInformation(
}

static void RoundTranslationComponents(gfx::Transform* transform) {
transform->matrix().set(0, 3, MathUtil::Round(transform->matrix().get(0, 3)));
transform->matrix().set(1, 3, MathUtil::Round(transform->matrix().get(1, 3)));
transform->matrix().
setDouble(0, 3, MathUtil::Round(transform->matrix().getDouble(0, 3)));
transform->matrix().
setDouble(1, 3, MathUtil::Round(transform->matrix().getDouble(1, 3)));
}

template <typename LayerType>
Expand Down
22 changes: 11 additions & 11 deletions cc/trees/layer_tree_host_common_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
// Case 4: A change in actual position affects both the draw transform and
// screen space transform.
gfx::Transform position_transform;
position_transform.Translate(0.f, 1.2f);
position_transform.Translate(0.0, 1.2);
SetLayerPropertiesForTesting(layer.get(),
identity_matrix,
identity_matrix,
Expand Down Expand Up @@ -551,7 +551,7 @@ TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {

// Case 2: parent's position affects child and grand_child.
gfx::Transform parent_position_transform;
parent_position_transform.Translate(0.f, 1.2f);
parent_position_transform.Translate(0.0, 1.2);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
identity_matrix,
Expand Down Expand Up @@ -629,7 +629,7 @@ TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
// does not preserve3D. When it gives its hierarchy to the grand_child, it
// should be flattened to 2D.
gfx::Transform parent_sublayer_matrix;
parent_sublayer_matrix.Scale3d(10.f, 10.f, 3.3f);
parent_sublayer_matrix.Scale3d(10.0, 10.0, 3.3);
// Sublayer matrix is applied to the anchor point of the parent layer.
parent_composite_transform =
parent_translation_to_anchor * parent_layer_transform *
Expand Down Expand Up @@ -730,11 +730,11 @@ TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
child->SetForceRenderSurface(true);

gfx::Transform parent_layer_transform;
parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
parent_layer_transform.Scale3d(1.0, 0.9, 1.0);
gfx::Transform parent_translation_to_anchor;
parent_translation_to_anchor.Translate(25.0, 30.0);
gfx::Transform parent_sublayer_matrix;
parent_sublayer_matrix.Scale3d(0.9f, 1.f, 3.3f);
parent_sublayer_matrix.Scale3d(0.9, 1.0, 3.3);

gfx::Transform parent_composite_transform =
parent_translation_to_anchor * parent_layer_transform *
Expand Down Expand Up @@ -876,8 +876,8 @@ TEST_F(LayerTreeHostCommonTest, SeparateRenderTargetRequirementWithClipping) {
EXPECT_FALSE(grand_child->render_surface());

// One-time setup of root layer
parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
parent_sublayer_matrix.Scale3d(0.9f, 1.f, 3.3f);
parent_layer_transform.Scale3d(1.0, 0.9, 1.0);
parent_sublayer_matrix.Scale3d(0.9, 1.0, 3.3);
child_layer_matrix.Rotate(20.0);

SetLayerPropertiesForTesting(root.get(),
Expand Down Expand Up @@ -948,8 +948,8 @@ TEST_F(LayerTreeHostCommonTest,
EXPECT_FALSE(grand_child->render_surface());

// One-time setup of root layer
parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
parent_sublayer_matrix.Scale3d(0.9f, 1.f, 3.3f);
parent_layer_transform.Scale3d(1.0, 0.9, 1.0);
parent_sublayer_matrix.Scale3d(0.9, 1.0, 3.3);
child_layer_matrix.Rotate(20.0);

SetLayerPropertiesForTesting(root.get(),
Expand Down Expand Up @@ -1024,7 +1024,7 @@ TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
gfx::Transform parent_translation_to_anchor;
parent_translation_to_anchor.Translate(2.5, 3.0);
gfx::Transform parent_sublayer_matrix;
parent_sublayer_matrix.Scale3d(10.f, 10.f, 3.3f);
parent_sublayer_matrix.Scale3d(10.0, 10.0, 3.3);
gfx::Transform parent_composite_transform =
parent_translation_to_anchor * parent_layer_transform *
Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
Expand Down Expand Up @@ -6245,7 +6245,7 @@ TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
perspective_matrix.ApplyPerspectiveDepth(2.0);

gfx::Transform scale_small_matrix;
scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
scale_small_matrix.Scale(1.0 / 10.0, 1.0 / 12.0);

scoped_refptr<Layer> root = Layer::Create();

Expand Down
4 changes: 2 additions & 2 deletions cc/trees/layer_tree_host_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4748,7 +4748,7 @@ TEST_F(LayerTreeHostImplTest, SurfaceTextureCaching) {

// Change location of the intermediate layer
gfx::Transform transform = intermediate_layer_ptr->transform();
transform.matrix().set(0, 3, 1.0001f);
transform.matrix().setDouble(0, 3, 1.0001);
intermediate_layer_ptr->SetTransform(transform);
{
LayerTreeHostImpl::FrameData frame;
Expand Down Expand Up @@ -4934,7 +4934,7 @@ TEST_F(LayerTreeHostImplTest, SurfaceTextureCachingNoPartialSwap) {

// Change location of the intermediate layer
gfx::Transform transform = intermediate_layer_ptr->transform();
transform.matrix().set(0, 3, 1.0001f);
transform.matrix().setDouble(0, 3, 1.0001);
intermediate_layer_ptr->SetTransform(transform);
{
LayerTreeHostImpl::FrameData frame;
Expand Down
4 changes: 2 additions & 2 deletions cc/trees/layer_tree_host_pixeltest_filters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ TEST_F(LayerTreeHostFiltersPixelTest, BackgroundFilterBlurOffAxis) {
blur->SetBackgroundFilters(filters);

#if defined(OS_WIN)
// Windows has 153 pixels off by at most 2: crbug.com/225027
float percentage_pixels_large_error = 0.3825f; // 153px / (200*200)
// Windows has 151 pixels off by at most 2: crbug.com/225027
float percentage_pixels_large_error = 0.3775f; // 151px / (200*200)
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 2;
Expand Down
Loading

0 comments on commit 7852a50

Please sign in to comment.