Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp

Issue 1393083003: Implement interest rects for synchronized paint. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp
diff --git a/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f7b15eccd4e1ff7ed31cbff34b33b5af6a0313c8
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp
@@ -0,0 +1,174 @@
+// Copyright 2014 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 "config.h"
+#include "core/layout/compositing/CompositedLayerMapping.h"
+
+#include "core/frame/FrameView.h"
+#include "core/layout/LayoutBoxModelObject.h"
+#include "core/layout/LayoutTestHelper.h"
+#include "core/paint/PaintLayer.h"
+#include <gtest/gtest.h>
+
+namespace blink {
+
+class CompositedLayerMappingTest : public RenderingTest {
+public:
+ CompositedLayerMappingTest()
+ : m_originalSlimmingPaintSynchronizedPaintingEnabled(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled()) { }
+
+protected:
+ IntRect computeInterestRect(const GraphicsLayer* graphicsLayer, LayoutObject* owningLayoutObject)
+ {
+ return CompositedLayerMapping::computeInterestRect(graphicsLayer, owningLayoutObject);
+ }
+
+private:
+ void SetUp() override
+ {
+ RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(true);
+
+ RenderingTest::SetUp();
+ enableCompositing();
+ GraphicsLayer::setDrawDebugRedFillForTesting(false);
+ }
+
+ void TearDown() override
+ {
+ GraphicsLayer::setDrawDebugRedFillForTesting(true);
+ RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_originalSlimmingPaintSynchronizedPaintingEnabled);
+ }
+
+ bool m_originalSlimmingPaintSynchronizedPaintingEnabled;
+};
+
+static void printRect(IntRect rect)
+{
+ fprintf(stderr, "[x=%d y=%d maxX=%d maxY=%d]\n", rect.x(), rect.y(), rect.maxX(), rect.maxY());
+}
+
+static bool checkRectsEqual(const IntRect& expected, const IntRect& actual)
+{
+ if (expected != actual) {
+ fprintf(stderr, "Expected: ");
+ printRect(expected);
+ fprintf(stderr, "Actual: ");
+ printRect(actual);
+ return false;
+ }
+ return true;
+}
+
+TEST_F(CompositedLayerMappingTest, SimpleInterestRect)
+{
+ setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will-change: transform'></div>");
+
+ document().view()->updateAllLifecyclePhases();
+ Element* element = document().getElementById("target");
+ PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->layer();
+ ASSERT_TRUE(!!paintLayer->graphicsLayerBacking());
+ EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 200), computeInterestRect(paintLayer->graphicsLayerBacking(), paintLayer->layoutObject())));
+}
+
+TEST_F(CompositedLayerMappingTest, TallLayerInterestRect)
+{
+ setBodyInnerHTML("<div id='target' style='width: 200px; height: 10000px; will-change: transform'></div>");
+
+ document().view()->updateAllLifecyclePhases();
+ Element* element = document().getElementById("target");
+ PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->layer();
+ ASSERT_TRUE(paintLayer->graphicsLayerBacking());
+ // Screen-space visible content rect is [8, 8, 200, 600]. Mapping back to local, adding 4000px in all directions, then
+ // clipping, yields this rect.
+ EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 4592), computeInterestRect(paintLayer->graphicsLayerBacking(), paintLayer->layoutObject())));
+}
+
+TEST_F(CompositedLayerMappingTest, RotatedInterestRect)
+{
+ setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will-change: transform; transform: rotateZ(45deg)'></div>");
+
+ document().view()->updateAllLifecyclePhases();
+ Element* element = document().getElementById("target");
+ PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->layer();
+ ASSERT_TRUE(!!paintLayer->graphicsLayerBacking());
+ EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 200), computeInterestRect(paintLayer->graphicsLayerBacking(), paintLayer->layoutObject())));
+}
+
+TEST_F(CompositedLayerMappingTest, RotatedTallInterestRect)
+{
+ setBodyInnerHTML("<div id='target' style='width: 200px; height: 10000px; will-change: transform; transform: rotateZ(45deg)'></div>");
+
+ document().view()->updateAllLifecyclePhases();
+ Element* element = document().getElementById("target");
+ PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->layer();
+ ASSERT_TRUE(!!paintLayer->graphicsLayerBacking());
+ EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 5536), computeInterestRect(paintLayer->graphicsLayerBacking(), paintLayer->layoutObject())));
+}
+
+TEST_F(CompositedLayerMappingTest, WideLayerInterestRect)
+{
+ setBodyInnerHTML("<div id='target' style='width: 10000px; height: 200px; will-change: transform'></div>");
+
+ document().view()->updateAllLifecyclePhases();
+ Element* element = document().getElementById("target");
+ PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->layer();
+ ASSERT_TRUE(!!paintLayer->graphicsLayerBacking());
+ // Screen-space visible content rect is [8, 8, 800, 200] (the screen is 800x600).
+ // Mapping back to local, adding 4000px in all directions, then clipping, yields this rect.
+ EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 4792, 200), computeInterestRect(paintLayer->graphicsLayerBacking(), paintLayer->layoutObject())));
+}
+
+TEST_F(CompositedLayerMappingTest, FixedPositionInterestRect)
+{
+ setBodyInnerHTML("<div id='target' style='width: 300px; height: 400px; will-change: transform; position: fixed; top: 100px; left: 200px;'></div>");
+
+ document().view()->updateAllLifecyclePhases();
+ Element* element = document().getElementById("target");
+ PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->layer();
+ ASSERT_TRUE(!!paintLayer->graphicsLayerBacking());
+ EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 300, 400), computeInterestRect(paintLayer->graphicsLayerBacking(), paintLayer->layoutObject())));
+}
+
+TEST_F(CompositedLayerMappingTest, LayerOffscreenInterestRect)
+{
+ setBodyInnerHTML(
+ "<div id='target' style='width: 200px; height: 200px; will-change: transform; position: absolute; top: 9000px; left: 0px;'>"
+ "</div>");
+
+ document().view()->updateAllLifecyclePhases();
+ Element* element = document().getElementById("target");
+ PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->layer();
+ ASSERT_TRUE(!!paintLayer->graphicsLayerBacking());
+ // Offscreen layers are painted as usual.
+ fprintf(stderr, "\nTest:\n");
wkorman 2015/10/09 19:46:32 Need this and others still?
chrishtr 2015/10/09 20:54:52 Fixed. I think that's the only one.
+ EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 200), computeInterestRect(paintLayer->graphicsLayerBacking(), paintLayer->layoutObject())));
+}
+
+TEST_F(CompositedLayerMappingTest, ScrollingLayerInterestRect)
+{
+ setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will-change: transform; overflow: scroll'>"
+ "<div style='width: 100px; height: 10000px'></div></div>");
+
+ document().view()->updateAllLifecyclePhases();
+ Element* element = document().getElementById("target");
+ PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->layer();
+ ASSERT_TRUE(paintLayer->graphicsLayerBacking());
+ // Offscreen layers are painted as usual.
+ EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 4592), computeInterestRect(paintLayer->graphicsLayerBackingForScrolling(), paintLayer->layoutObject())));
+}
+
+TEST_F(CompositedLayerMappingTest, ClippedBigLayer)
+{
+ setBodyInnerHTML("<div style='width: 1px; height: 1px; overflow: hidden'>"
+ "<div id='target' style='width: 10000px; height: 10000px; will-change: transform'></div></div>");
+
+ document().view()->updateAllLifecyclePhases();
+ Element* element = document().getElementById("target");
+ PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->layer();
+ ASSERT_TRUE(paintLayer->graphicsLayerBacking());
+ // Offscreen layers are painted as usual.
+ EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 4001, 4001), computeInterestRect(paintLayer->graphicsLayerBacking(), paintLayer->layoutObject())));
+}
ajuma 2015/10/09 20:55:27 Please also add a test where the transform to/from
chrishtr 2015/10/09 21:35:46 Done.
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698