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