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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/PaintControllerTest.cpp

Issue 2894093002: Don't access DisplayItemClient::VisualRect() for cached display items. (Closed)
Patch Set: - Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/graphics/paint/PaintController.h" 5 #include "platform/graphics/paint/PaintController.h"
6 6
7 #include "platform/RuntimeEnabledFeatures.h" 7 #include "platform/RuntimeEnabledFeatures.h"
8 #include "platform/graphics/GraphicsContext.h" 8 #include "platform/graphics/GraphicsContext.h"
9 #include "platform/graphics/paint/ClipPathDisplayItem.h" 9 #include "platform/graphics/paint/ClipPathDisplayItem.h"
10 #include "platform/graphics/paint/ClipPathRecorder.h" 10 #include "platform/graphics/paint/ClipPathRecorder.h"
(...skipping 12 matching lines...) Expand all
23 using blink::testing::CreateOpacityOnlyEffect; 23 using blink::testing::CreateOpacityOnlyEffect;
24 using blink::testing::DefaultPaintChunkProperties; 24 using blink::testing::DefaultPaintChunkProperties;
25 using testing::UnorderedElementsAre; 25 using testing::UnorderedElementsAre;
26 26
27 namespace blink { 27 namespace blink {
28 28
29 class PaintControllerTestBase : public ::testing::Test { 29 class PaintControllerTestBase : public ::testing::Test {
30 public: 30 public:
31 PaintControllerTestBase() : paint_controller_(PaintController::Create()) {} 31 PaintControllerTestBase() : paint_controller_(PaintController::Create()) {}
32 32
33 IntRect VisualRect(const PaintArtifact& paint_artifact, size_t index) {
34 return paint_artifact.GetDisplayItemList().VisualRect(index);
35 }
36
37 protected: 33 protected:
38 PaintController& GetPaintController() { return *paint_controller_; } 34 PaintController& GetPaintController() { return *paint_controller_; }
39 35
40 int NumCachedNewItems() const { 36 int NumCachedNewItems() const {
41 return paint_controller_->num_cached_new_items_; 37 return paint_controller_->num_cached_new_items_;
42 } 38 }
43 39
44 #ifndef NDEBUG 40 #ifndef NDEBUG
45 int NumSequentialMatches() const { 41 int NumSequentialMatches() const {
46 return paint_controller_->num_sequential_matches_; 42 return paint_controller_->num_sequential_matches_;
(...skipping 13 matching lines...) Expand all
60 const DisplayItem::Type kBackgroundDrawingType = 56 const DisplayItem::Type kBackgroundDrawingType =
61 DisplayItem::kDrawingPaintPhaseFirst; 57 DisplayItem::kDrawingPaintPhaseFirst;
62 const DisplayItem::Type kClipType = DisplayItem::kClipFirst; 58 const DisplayItem::Type kClipType = DisplayItem::kClipFirst;
63 59
64 class TestDisplayItem final : public DisplayItem { 60 class TestDisplayItem final : public DisplayItem {
65 public: 61 public:
66 TestDisplayItem(const FakeDisplayItemClient& client, Type type) 62 TestDisplayItem(const FakeDisplayItemClient& client, Type type)
67 : DisplayItem(client, type, sizeof(*this)) {} 63 : DisplayItem(client, type, sizeof(*this)) {}
68 64
69 void Replay(GraphicsContext&) const final { NOTREACHED(); } 65 void Replay(GraphicsContext&) const final { NOTREACHED(); }
70 void AppendToWebDisplayItemList(const IntRect&, 66 void AppendToWebDisplayItemList(const LayoutSize&,
71 WebDisplayItemList*) const final { 67 WebDisplayItemList*) const final {
72 NOTREACHED(); 68 NOTREACHED();
73 } 69 }
74 }; 70 };
75 71
76 #ifndef NDEBUG 72 #ifndef NDEBUG
77 #define TRACE_DISPLAY_ITEMS(i, expected, actual) \ 73 #define TRACE_DISPLAY_ITEMS(i, expected, actual) \
78 String trace = String::Format("%d: ", (int)i) + \ 74 String trace = String::Format("%d: ", (int)i) + \
79 "Expected: " + (expected).AsDebugString() + \ 75 "Expected: " + (expected).AsDebugString() + \
80 " Actual: " + (actual).AsDebugString(); \ 76 " Actual: " + (actual).AsDebugString(); \
(...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 GraphicsContext context(GetPaintController()); 1874 GraphicsContext context(GetPaintController());
1879 DrawRect(context, client, kBackgroundDrawingType, FloatRect(0, 0, 100, 100)); 1875 DrawRect(context, client, kBackgroundDrawingType, FloatRect(0, 0, 100, 100));
1880 1876
1881 GetPaintController().CommitNewDisplayItems(); 1877 GetPaintController().CommitNewDisplayItems();
1882 const auto& paint_chunks = GetPaintController().PaintChunks(); 1878 const auto& paint_chunks = GetPaintController().PaintChunks();
1883 ASSERT_EQ(1u, paint_chunks.size()); 1879 ASSERT_EQ(1u, paint_chunks.size());
1884 EXPECT_EQ(0u, paint_chunks[0].begin_index); 1880 EXPECT_EQ(0u, paint_chunks[0].begin_index);
1885 EXPECT_EQ(1u, paint_chunks[0].end_index); 1881 EXPECT_EQ(1u, paint_chunks[0].end_index);
1886 } 1882 }
1887 1883
1888 TEST_F(PaintControllerTestBase, PaintArtifactWithVisualRects) {
1889 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100));
1890
1891 GraphicsContext context(GetPaintController());
1892 DrawRect(context, client, kBackgroundDrawingType, FloatRect(0, 0, 100, 100));
1893
1894 GetPaintController().CommitNewDisplayItems(LayoutSize(20, 30));
1895 const auto& paint_artifact = GetPaintController().GetPaintArtifact();
1896 ASSERT_EQ(1u, paint_artifact.GetDisplayItemList().size());
1897 EXPECT_EQ(IntRect(-20, -30, 200, 100), VisualRect(paint_artifact, 0));
1898 }
1899
1900 void DrawPath(GraphicsContext& context, 1884 void DrawPath(GraphicsContext& context,
1901 DisplayItemClient& client, 1885 DisplayItemClient& client,
1902 DisplayItem::Type type, 1886 DisplayItem::Type type,
1903 unsigned count) { 1887 unsigned count) {
1904 if (DrawingRecorder::UseCachedDrawingIfPossible(context, client, type)) 1888 if (DrawingRecorder::UseCachedDrawingIfPossible(context, client, type))
1905 return; 1889 return;
1906 1890
1907 DrawingRecorder drawing_recorder(context, client, type, 1891 DrawingRecorder drawing_recorder(context, client, type,
1908 FloatRect(0, 0, 100, 100)); 1892 FloatRect(0, 0, 100, 100));
1909 SkPath path; 1893 SkPath path;
1910 path.moveTo(0, 0); 1894 path.moveTo(0, 0);
1911 path.lineTo(0, 100); 1895 path.lineTo(0, 100);
1912 path.lineTo(50, 50); 1896 path.lineTo(50, 50);
1913 path.lineTo(100, 100); 1897 path.lineTo(100, 100);
1914 path.lineTo(100, 0); 1898 path.lineTo(100, 0);
1915 path.close(); 1899 path.close();
1916 PaintFlags flags; 1900 PaintFlags flags;
1917 flags.setAntiAlias(true); 1901 flags.setAntiAlias(true);
1918 for (unsigned i = 0; i < count; i++) 1902 for (unsigned i = 0; i < count; i++)
1919 context.DrawPath(path, flags); 1903 context.DrawPath(path, flags);
1920 } 1904 }
1921 1905
1922 TEST_F(PaintControllerTestBase, IsSuitableForGpuRasterizationSinglePath) { 1906 TEST_F(PaintControllerTestBase, IsSuitableForGpuRasterizationSinglePath) {
1923 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100)); 1907 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100));
1924 GraphicsContext context(GetPaintController()); 1908 GraphicsContext context(GetPaintController());
1925 DrawPath(context, client, kBackgroundDrawingType, 1); 1909 DrawPath(context, client, kBackgroundDrawingType, 1);
1926 GetPaintController().CommitNewDisplayItems(LayoutSize()); 1910 GetPaintController().CommitNewDisplayItems();
1927 EXPECT_TRUE( 1911 EXPECT_TRUE(
1928 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization()); 1912 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization());
1929 } 1913 }
1930 1914
1931 TEST_F(PaintControllerTestBase, 1915 TEST_F(PaintControllerTestBase,
1932 IsNotSuitableForGpuRasterizationSinglePaintRecordManyPaths) { 1916 IsNotSuitableForGpuRasterizationSinglePaintRecordManyPaths) {
1933 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100)); 1917 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100));
1934 GraphicsContext context(GetPaintController()); 1918 GraphicsContext context(GetPaintController());
1935 1919
1936 DrawPath(context, client, kBackgroundDrawingType, 50); 1920 DrawPath(context, client, kBackgroundDrawingType, 50);
1937 GetPaintController().CommitNewDisplayItems(LayoutSize()); 1921 GetPaintController().CommitNewDisplayItems();
1938 EXPECT_FALSE( 1922 EXPECT_FALSE(
1939 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization()); 1923 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization());
1940 } 1924 }
1941 1925
1942 TEST_F(PaintControllerTestBase, 1926 TEST_F(PaintControllerTestBase,
1943 IsNotSuitableForGpuRasterizationMultiplePaintRecordsSinglePathEach) { 1927 IsNotSuitableForGpuRasterizationMultiplePaintRecordsSinglePathEach) {
1944 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100)); 1928 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100));
1945 GraphicsContext context(GetPaintController()); 1929 GraphicsContext context(GetPaintController());
1946 GetPaintController().BeginSkippingCache(); 1930 GetPaintController().BeginSkippingCache();
1947 1931
1948 for (int i = 0; i < 50; ++i) 1932 for (int i = 0; i < 50; ++i)
1949 DrawPath(context, client, kBackgroundDrawingType, 50); 1933 DrawPath(context, client, kBackgroundDrawingType, 50);
1950 1934
1951 GetPaintController().EndSkippingCache(); 1935 GetPaintController().EndSkippingCache();
1952 GetPaintController().CommitNewDisplayItems(LayoutSize()); 1936 GetPaintController().CommitNewDisplayItems();
1953 EXPECT_FALSE( 1937 EXPECT_FALSE(
1954 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization()); 1938 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization());
1955 } 1939 }
1956 1940
1957 TEST_F(PaintControllerTestBase, 1941 TEST_F(PaintControllerTestBase,
1958 IsNotSuitableForGpuRasterizationSinglePaintRecordManyPathsTwoPaints) { 1942 IsNotSuitableForGpuRasterizationSinglePaintRecordManyPathsTwoPaints) {
1959 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100)); 1943 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100));
1960 1944
1961 { 1945 {
1962 GraphicsContext context(GetPaintController()); 1946 GraphicsContext context(GetPaintController());
1963 DrawPath(context, client, kBackgroundDrawingType, 50); 1947 DrawPath(context, client, kBackgroundDrawingType, 50);
1964 GetPaintController().CommitNewDisplayItems(LayoutSize()); 1948 GetPaintController().CommitNewDisplayItems();
1965 EXPECT_FALSE(GetPaintController() 1949 EXPECT_FALSE(GetPaintController()
1966 .GetPaintArtifact() 1950 .GetPaintArtifact()
1967 .IsSuitableForGpuRasterization()); 1951 .IsSuitableForGpuRasterization());
1968 } 1952 }
1969 1953
1970 client.SetDisplayItemsUncached(); 1954 client.SetDisplayItemsUncached();
1971 1955
1972 { 1956 {
1973 GraphicsContext context(GetPaintController()); 1957 GraphicsContext context(GetPaintController());
1974 DrawPath(context, client, kBackgroundDrawingType, 50); 1958 DrawPath(context, client, kBackgroundDrawingType, 50);
1975 GetPaintController().CommitNewDisplayItems(LayoutSize()); 1959 GetPaintController().CommitNewDisplayItems();
1976 EXPECT_FALSE(GetPaintController() 1960 EXPECT_FALSE(GetPaintController()
1977 .GetPaintArtifact() 1961 .GetPaintArtifact()
1978 .IsSuitableForGpuRasterization()); 1962 .IsSuitableForGpuRasterization());
1979 } 1963 }
1980 } 1964 }
1981 1965
1982 TEST_F(PaintControllerTestBase, 1966 TEST_F(PaintControllerTestBase,
1983 IsNotSuitableForGpuRasterizationSinglePaintRecordManyPathsCached) { 1967 IsNotSuitableForGpuRasterizationSinglePaintRecordManyPathsCached) {
1984 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100)); 1968 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100));
1985 1969
1986 { 1970 {
1987 GraphicsContext context(GetPaintController()); 1971 GraphicsContext context(GetPaintController());
1988 DrawPath(context, client, kBackgroundDrawingType, 50); 1972 DrawPath(context, client, kBackgroundDrawingType, 50);
1989 GetPaintController().CommitNewDisplayItems(LayoutSize()); 1973 GetPaintController().CommitNewDisplayItems();
1990 EXPECT_FALSE(GetPaintController() 1974 EXPECT_FALSE(GetPaintController()
1991 .GetPaintArtifact() 1975 .GetPaintArtifact()
1992 .IsSuitableForGpuRasterization()); 1976 .IsSuitableForGpuRasterization());
1993 } 1977 }
1994 1978
1995 { 1979 {
1996 GraphicsContext context(GetPaintController()); 1980 GraphicsContext context(GetPaintController());
1997 DrawPath(context, client, kBackgroundDrawingType, 50); 1981 DrawPath(context, client, kBackgroundDrawingType, 50);
1998 GetPaintController().CommitNewDisplayItems(LayoutSize()); 1982 GetPaintController().CommitNewDisplayItems();
1999 EXPECT_FALSE(GetPaintController() 1983 EXPECT_FALSE(GetPaintController()
2000 .GetPaintArtifact() 1984 .GetPaintArtifact()
2001 .IsSuitableForGpuRasterization()); 1985 .IsSuitableForGpuRasterization());
2002 } 1986 }
2003 } 1987 }
2004 1988
2005 TEST_F( 1989 TEST_F(
2006 PaintControllerTestBase, 1990 PaintControllerTestBase,
2007 IsNotSuitableForGpuRasterizationSinglePaintRecordManyPathsCachedSubsequence) { 1991 IsNotSuitableForGpuRasterizationSinglePaintRecordManyPathsCachedSubsequence) {
2008 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100)); 1992 FakeDisplayItemClient client("test client", LayoutRect(0, 0, 200, 100));
2009 FakeDisplayItemClient container("container", LayoutRect(0, 0, 200, 100)); 1993 FakeDisplayItemClient container("container", LayoutRect(0, 0, 200, 100));
2010 1994
2011 GraphicsContext context(GetPaintController()); 1995 GraphicsContext context(GetPaintController());
2012 { 1996 {
2013 SubsequenceRecorder subsequence_recorder(context, container); 1997 SubsequenceRecorder subsequence_recorder(context, container);
2014 DrawPath(context, client, kBackgroundDrawingType, 50); 1998 DrawPath(context, client, kBackgroundDrawingType, 50);
2015 } 1999 }
2016 GetPaintController().CommitNewDisplayItems(LayoutSize()); 2000 GetPaintController().CommitNewDisplayItems();
2017 EXPECT_FALSE( 2001 EXPECT_FALSE(
2018 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization()); 2002 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization());
2019 2003
2020 EXPECT_TRUE( 2004 EXPECT_TRUE(
2021 SubsequenceRecorder::UseCachedSubsequenceIfPossible(context, container)); 2005 SubsequenceRecorder::UseCachedSubsequenceIfPossible(context, container));
2022 GetPaintController().CommitNewDisplayItems(LayoutSize()); 2006 GetPaintController().CommitNewDisplayItems();
2023 EXPECT_FALSE( 2007 EXPECT_FALSE(
2024 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization()); 2008 GetPaintController().GetPaintArtifact().IsSuitableForGpuRasterization());
2025 2009
2026 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS 2010 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS
2027 DisplayItemClient::EndShouldKeepAliveAllClients(); 2011 DisplayItemClient::EndShouldKeepAliveAllClients();
2028 #endif 2012 #endif
2029 } 2013 }
2030 2014
2031 // Temporarily disabled (pref regressions due to GPU veto stickiness: 2015 // Temporarily disabled (pref regressions due to GPU veto stickiness:
2032 // http://crbug.com/603969). 2016 // http://crbug.com/603969).
(...skipping 10 matching lines...) Expand all
2043 2027
2044 // Run twice for empty/non-empty m_currentPaintArtifact coverage. 2028 // Run twice for empty/non-empty m_currentPaintArtifact coverage.
2045 for (int i = 0; i < 2; ++i) { 2029 for (int i = 0; i < 2; ++i) {
2046 for (int j = 0; j < 50; ++j) 2030 for (int j = 0; j < 50; ++j)
2047 GetPaintController().CreateAndAppend<BeginClipPathDisplayItem>(client, 2031 GetPaintController().CreateAndAppend<BeginClipPathDisplayItem>(client,
2048 path); 2032 path);
2049 DrawRect(context, client, kBackgroundDrawingType, 2033 DrawRect(context, client, kBackgroundDrawingType,
2050 FloatRect(0, 0, 100, 100)); 2034 FloatRect(0, 0, 100, 100));
2051 for (int j = 0; j < 50; ++j) 2035 for (int j = 0; j < 50; ++j)
2052 GetPaintController().CreateAndAppend<EndClipPathDisplayItem>(client); 2036 GetPaintController().CreateAndAppend<EndClipPathDisplayItem>(client);
2053 GetPaintController().CommitNewDisplayItems(LayoutSize()); 2037 GetPaintController().CommitNewDisplayItems();
2054 EXPECT_FALSE(GetPaintController() 2038 EXPECT_FALSE(GetPaintController()
2055 .GetPaintArtifact() 2039 .GetPaintArtifact()
2056 .IsSuitableForGpuRasterization()); 2040 .IsSuitableForGpuRasterization());
2057 } 2041 }
2058 } 2042 }
2059 2043
2060 TEST_F(PaintControllerTestBase, BeginAndEndFrame) { 2044 TEST_F(PaintControllerTestBase, BeginAndEndFrame) {
2061 class FakeFrame {}; 2045 class FakeFrame {};
2062 2046
2063 // PaintController should have one null frame in the stack since beginning. 2047 // PaintController should have one null frame in the stack since beginning.
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 TEST_F(PaintControllerUnderInvalidationTest, InvalidationInSubsequence) { 2346 TEST_F(PaintControllerUnderInvalidationTest, InvalidationInSubsequence) {
2363 // We allow invalidated display item clients as long as they would produce the 2347 // We allow invalidated display item clients as long as they would produce the
2364 // same display items. The cases of changed display items are tested by other 2348 // same display items. The cases of changed display items are tested by other
2365 // test cases. 2349 // test cases.
2366 TestInvalidationInSubsequence(); 2350 TestInvalidationInSubsequence();
2367 } 2351 }
2368 2352
2369 #endif // defined(GTEST_HAS_DEATH_TEST) && !OS(ANDROID) 2353 #endif // defined(GTEST_HAS_DEATH_TEST) && !OS(ANDROID)
2370 2354
2371 } // namespace blink 2355 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698