diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-19 05:24:57 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-19 05:24:57 +0000 |
commit | 552e600db9f51ac1efb0438bd749227226dffa64 (patch) | |
tree | 121e6a11a6f637e9b5cfd2d04244c94b1961420f /chrome/renderer/paint_aggregator_unittest.cc | |
parent | 0dea18f231b425216aae0c956129bc80b7086770 (diff) | |
download | chromium_src-552e600db9f51ac1efb0438bd749227226dffa64.zip chromium_src-552e600db9f51ac1efb0438bd749227226dffa64.tar.gz chromium_src-552e600db9f51ac1efb0438bd749227226dffa64.tar.bz2 |
Refactors RenderWidget to extract a PaintAggregator class.
After this change, I plan on changing the PaintAggregator algorithm.
Some things to note:
1- Previously, it was possible to send overlapping ViewHostMsg_PaintRect and
ViewHostMsg_ScrollRect messages. This happened when scrolling a page since the
scrollbar would need to be repainted while the contents of the page are being
scrolled. With this CL, this overlapping behavior is a bit more explicit.
2- There was a TODO about view_size clipping that I've eliminated. I was able
to eliminate it because I realized that it is correct to clip the rects passed
by didInvalidateRect and didScrollRect to the size of the RenderWidget.
Apparently WebKit can sometimes invalidate regions outside the view.
R=brettw
BUG=25905
TEST=none
Review URL: http://codereview.chromium.org/403005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32496 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/paint_aggregator_unittest.cc')
-rw-r--r-- | chrome/renderer/paint_aggregator_unittest.cc | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/chrome/renderer/paint_aggregator_unittest.cc b/chrome/renderer/paint_aggregator_unittest.cc new file mode 100644 index 0000000..f490a2d --- /dev/null +++ b/chrome/renderer/paint_aggregator_unittest.cc @@ -0,0 +1,128 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/renderer/paint_aggregator.h" +#include "testing/gtest/include/gtest/gtest.h" + +TEST(PaintAggregator, InitialState) { + PaintAggregator greg; + EXPECT_FALSE(greg.HasPendingUpdate()); +} + +TEST(PaintAggregator, SingleInvalidation) { + PaintAggregator greg; + + gfx::Rect rect(2, 4, 10, 16); + greg.InvalidateRect(rect); + + EXPECT_TRUE(greg.HasPendingUpdate()); + EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); + EXPECT_FALSE(greg.GetPendingUpdate().paint_rect.IsEmpty()); + + EXPECT_EQ(rect.x(), greg.GetPendingUpdate().paint_rect.x()); + EXPECT_EQ(rect.y(), greg.GetPendingUpdate().paint_rect.y()); + EXPECT_EQ(rect.width(), greg.GetPendingUpdate().paint_rect.width()); + EXPECT_EQ(rect.height(), greg.GetPendingUpdate().paint_rect.height()); +} + +TEST(PaintAggregator, DoubleDisjointInvalidation) { + PaintAggregator greg; + + gfx::Rect r1(2, 4, 2, 4); + gfx::Rect r2(4, 2, 4, 2); + + greg.InvalidateRect(r1); + greg.InvalidateRect(r2); + + gfx::Rect expected = r1.Union(r2); + + EXPECT_TRUE(greg.HasPendingUpdate()); + EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); + EXPECT_FALSE(greg.GetPendingUpdate().paint_rect.IsEmpty()); + + EXPECT_EQ(expected.x(), greg.GetPendingUpdate().paint_rect.x()); + EXPECT_EQ(expected.y(), greg.GetPendingUpdate().paint_rect.y()); + EXPECT_EQ(expected.width(), greg.GetPendingUpdate().paint_rect.width()); + EXPECT_EQ(expected.height(), greg.GetPendingUpdate().paint_rect.height()); +} + +TEST(PaintAggregator, SingleScroll) { + PaintAggregator greg; + + gfx::Rect rect(1, 2, 3, 4); + gfx::Point delta(1, 0); + greg.ScrollRect(delta.x(), delta.y(), rect); + + EXPECT_TRUE(greg.HasPendingUpdate()); + EXPECT_TRUE(greg.GetPendingUpdate().paint_rect.IsEmpty()); + EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); + + EXPECT_EQ(rect.x(), greg.GetPendingUpdate().scroll_rect.x()); + EXPECT_EQ(rect.y(), greg.GetPendingUpdate().scroll_rect.y()); + EXPECT_EQ(rect.width(), greg.GetPendingUpdate().scroll_rect.width()); + EXPECT_EQ(rect.height(), greg.GetPendingUpdate().scroll_rect.height()); + + EXPECT_EQ(delta.x(), greg.GetPendingUpdate().scroll_delta.x()); + EXPECT_EQ(delta.y(), greg.GetPendingUpdate().scroll_delta.y()); + + gfx::Rect resulting_damage = greg.GetPendingUpdate().GetScrollDamage(); + gfx::Rect expected_damage(1, 2, 1, 4); + EXPECT_EQ(expected_damage.x(), resulting_damage.x()); + EXPECT_EQ(expected_damage.y(), resulting_damage.y()); + EXPECT_EQ(expected_damage.width(), resulting_damage.width()); + EXPECT_EQ(expected_damage.height(), resulting_damage.height()); +} + +TEST(PaintAggregator, DoubleOverlappingScroll) { + PaintAggregator greg; + + gfx::Rect rect(1, 2, 3, 4); + gfx::Point delta1(1, 0); + gfx::Point delta2(1, 0); + greg.ScrollRect(delta1.x(), delta1.y(), rect); + greg.ScrollRect(delta2.x(), delta2.y(), rect); + + EXPECT_TRUE(greg.HasPendingUpdate()); + EXPECT_TRUE(greg.GetPendingUpdate().paint_rect.IsEmpty()); + EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); + + EXPECT_EQ(rect.x(), greg.GetPendingUpdate().scroll_rect.x()); + EXPECT_EQ(rect.y(), greg.GetPendingUpdate().scroll_rect.y()); + EXPECT_EQ(rect.width(), greg.GetPendingUpdate().scroll_rect.width()); + EXPECT_EQ(rect.height(), greg.GetPendingUpdate().scroll_rect.height()); + + gfx::Point expected_delta(delta1.x() + delta2.x(), + delta1.y() + delta2.y()); + EXPECT_EQ(expected_delta.x(), greg.GetPendingUpdate().scroll_delta.x()); + EXPECT_EQ(expected_delta.y(), greg.GetPendingUpdate().scroll_delta.y()); + + gfx::Rect resulting_damage = greg.GetPendingUpdate().GetScrollDamage(); + gfx::Rect expected_damage(1, 2, 2, 4); + EXPECT_EQ(expected_damage.x(), resulting_damage.x()); + EXPECT_EQ(expected_damage.y(), resulting_damage.y()); + EXPECT_EQ(expected_damage.width(), resulting_damage.width()); + EXPECT_EQ(expected_damage.height(), resulting_damage.height()); +} + +TEST(PaintAggregator, DiagonalScroll) { + PaintAggregator greg; + + // We don't support optimized diagonal scrolling, so this should result in + // repainting. + + gfx::Rect rect(1, 2, 3, 4); + gfx::Point delta(1, 1); + greg.ScrollRect(delta.x(), delta.y(), rect); + + EXPECT_TRUE(greg.HasPendingUpdate()); + EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); + EXPECT_FALSE(greg.GetPendingUpdate().paint_rect.IsEmpty()); + + EXPECT_EQ(rect.x(), greg.GetPendingUpdate().paint_rect.x()); + EXPECT_EQ(rect.y(), greg.GetPendingUpdate().paint_rect.y()); + EXPECT_EQ(rect.width(), greg.GetPendingUpdate().paint_rect.width()); + EXPECT_EQ(rect.height(), greg.GetPendingUpdate().paint_rect.height()); +} + +// TODO(darin): Add tests for mixed scrolling and invalidation |