Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/paint/PaintChunker.h" | 6 #include "platform/graphics/paint/PaintChunker.h" |
| 7 | 7 |
| 8 #include "platform/RuntimeEnabledFeatures.h" | 8 #include "platform/RuntimeEnabledFeatures.h" |
| 9 #include <gmock/gmock.h> | 9 #include <gmock/gmock.h> |
| 10 #include <gtest/gtest.h> | 10 #include <gtest/gtest.h> |
| 11 | 11 |
| 12 using testing::ElementsAre; | 12 using testing::ElementsAre; |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 static PaintProperties samplePaintProperties() { return PaintProperties(); } | 17 static PaintProperties rootPaintProperties() { return PaintProperties(); } |
| 18 | 18 |
| 19 class PaintChunkerTest : public testing::Test { | 19 class PaintChunkerTest : public testing::Test { |
| 20 protected: | 20 protected: |
| 21 void SetUp() override | 21 void SetUp() override |
| 22 { | 22 { |
| 23 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | 23 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void TearDown() override | 26 void TearDown() override |
| 27 { | 27 { |
| 28 m_featuresBackup.restore(); | 28 m_featuresBackup.restore(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 RuntimeEnabledFeatures::Backup m_featuresBackup; | 32 RuntimeEnabledFeatures::Backup m_featuresBackup; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 TEST_F(PaintChunkerTest, Empty) | 35 TEST_F(PaintChunkerTest, Empty) |
| 36 { | 36 { |
| 37 Vector<PaintChunk> chunks = PaintChunker().releasePaintChunks(); | 37 Vector<PaintChunk> chunks = PaintChunker().releasePaintChunks(); |
| 38 ASSERT_TRUE(chunks.isEmpty()); | 38 ASSERT_TRUE(chunks.isEmpty()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 TEST_F(PaintChunkerTest, SingleNonEmptyRange) | 41 TEST_F(PaintChunkerTest, SingleNonEmptyRange) |
| 42 { | 42 { |
| 43 PaintChunker chunker; | 43 PaintChunker chunker; |
| 44 chunker.updateCurrentPaintProperties(samplePaintProperties()); | 44 chunker.updateCurrentPaintProperties(rootPaintProperties()); |
| 45 chunker.incrementDisplayItemIndex(); | 45 chunker.incrementDisplayItemIndex(); |
| 46 chunker.incrementDisplayItemIndex(); | 46 chunker.incrementDisplayItemIndex(); |
| 47 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); | 47 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); |
| 48 | 48 |
| 49 EXPECT_THAT(chunks, ElementsAre( | 49 EXPECT_THAT(chunks, ElementsAre( |
| 50 PaintChunk(0, 2, samplePaintProperties()))); | 50 PaintChunk(0, 2, rootPaintProperties()))); |
| 51 } | 51 } |
| 52 | 52 |
| 53 TEST_F(PaintChunkerTest, SamePropertiesTwiceCombineIntoOneChunk) | 53 TEST_F(PaintChunkerTest, SamePropertiesTwiceCombineIntoOneChunk) |
| 54 { | 54 { |
| 55 PaintChunker chunker; | 55 PaintChunker chunker; |
| 56 chunker.updateCurrentPaintProperties(samplePaintProperties()); | 56 chunker.updateCurrentPaintProperties(rootPaintProperties()); |
| 57 chunker.incrementDisplayItemIndex(); | 57 chunker.incrementDisplayItemIndex(); |
| 58 chunker.incrementDisplayItemIndex(); | 58 chunker.incrementDisplayItemIndex(); |
| 59 chunker.updateCurrentPaintProperties(samplePaintProperties()); | 59 chunker.updateCurrentPaintProperties(rootPaintProperties()); |
| 60 chunker.incrementDisplayItemIndex(); | 60 chunker.incrementDisplayItemIndex(); |
| 61 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); | 61 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); |
| 62 | 62 |
| 63 EXPECT_THAT(chunks, ElementsAre( | 63 EXPECT_THAT(chunks, ElementsAre( |
| 64 PaintChunk(0, 3, samplePaintProperties()))); | 64 PaintChunk(0, 3, rootPaintProperties()))); |
| 65 } | 65 } |
| 66 | 66 |
| 67 TEST_F(PaintChunkerTest, CanRewindDisplayItemIndex) | 67 TEST_F(PaintChunkerTest, CanRewindDisplayItemIndex) |
| 68 { | 68 { |
| 69 PaintChunker chunker; | 69 PaintChunker chunker; |
| 70 chunker.updateCurrentPaintProperties(samplePaintProperties()); | 70 chunker.updateCurrentPaintProperties(rootPaintProperties()); |
| 71 chunker.incrementDisplayItemIndex(); | 71 chunker.incrementDisplayItemIndex(); |
| 72 chunker.incrementDisplayItemIndex(); | 72 chunker.incrementDisplayItemIndex(); |
| 73 chunker.decrementDisplayItemIndex(); | 73 chunker.decrementDisplayItemIndex(); |
| 74 chunker.incrementDisplayItemIndex(); | 74 chunker.incrementDisplayItemIndex(); |
| 75 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); | 75 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); |
| 76 | 76 |
| 77 EXPECT_THAT(chunks, ElementsAre( | 77 EXPECT_THAT(chunks, ElementsAre( |
| 78 PaintChunk(0, 2, samplePaintProperties()))); | 78 PaintChunk(0, 2, rootPaintProperties()))); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // TODO(jbroman): Add more tests one it is possible for there to be two distinct | 81 TEST_F(PaintChunkerTest, BuildMultipleChunksWithSinglePropertyChanging) |
| 82 // PaintProperties. | 82 { |
| 83 PaintChunker chunker; | |
| 84 chunker.updateCurrentPaintProperties(rootPaintProperties()); | |
| 85 chunker.incrementDisplayItemIndex(); | |
| 86 chunker.incrementDisplayItemIndex(); | |
| 87 | |
| 88 PaintProperties simpleTransform; | |
| 89 simpleTransform.transform = adoptRef(new TransformPaintPropertyNode(Transfor mationMatrix(), FloatPoint3D())); | |
| 90 | |
| 91 chunker.updateCurrentPaintProperties(simpleTransform); | |
| 92 chunker.incrementDisplayItemIndex(); | |
| 93 | |
| 94 PaintProperties anotherTransform; | |
| 95 anotherTransform.transform = adoptRef(new TransformPaintPropertyNode(Transfo rmationMatrix(), FloatPoint3D())); | |
| 96 chunker.updateCurrentPaintProperties(anotherTransform); | |
| 97 chunker.incrementDisplayItemIndex(); | |
| 98 | |
| 99 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); | |
| 100 | |
| 101 EXPECT_THAT(chunks, ElementsAre( | |
| 102 PaintChunk(0, 2, rootPaintProperties()), | |
|
chrishtr
2015/10/07 21:14:28
Make the different transforms have different param
pdr.
2015/10/07 22:15:59
Done
| |
| 103 PaintChunk(2, 3, simpleTransform), | |
| 104 PaintChunk(3, 4, anotherTransform))); | |
| 105 } | |
| 106 | |
| 107 TEST_F(PaintChunkerTest, BuildLinearChunksFromNestedTransforms) | |
| 108 { | |
| 109 // Test that "nested" transforms linearize using the following | |
| 110 // sequence of transforms and display items: | |
| 111 // <root xform>, <paint>, <a xform>, <paint>, <paint>, </a xform>, <paint>, </root xform> | |
| 112 PaintChunker chunker; | |
| 113 chunker.updateCurrentPaintProperties(rootPaintProperties()); | |
| 114 chunker.incrementDisplayItemIndex(); | |
| 115 | |
| 116 PaintProperties simpleTransform; | |
| 117 simpleTransform.transform = adoptRef(new TransformPaintPropertyNode(Transfor mationMatrix(), FloatPoint3D())); | |
| 118 chunker.updateCurrentPaintProperties(simpleTransform); | |
| 119 chunker.incrementDisplayItemIndex(); | |
| 120 chunker.incrementDisplayItemIndex(); | |
| 121 | |
| 122 chunker.updateCurrentPaintProperties(rootPaintProperties()); | |
| 123 chunker.incrementDisplayItemIndex(); | |
| 124 | |
| 125 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); | |
| 126 | |
| 127 EXPECT_THAT(chunks, ElementsAre( | |
| 128 PaintChunk(0, 1, rootPaintProperties()), | |
| 129 PaintChunk(1, 3, simpleTransform), | |
| 130 PaintChunk(3, 4, rootPaintProperties()))); | |
| 131 } | |
| 132 | |
| 133 TEST_F(PaintChunkerTest, ChangingPropertiesWithoutItems) | |
| 134 { | |
| 135 // Test that properties can change without display items being generated. | |
| 136 PaintChunker chunker; | |
| 137 chunker.updateCurrentPaintProperties(rootPaintProperties()); | |
| 138 chunker.incrementDisplayItemIndex(); | |
| 139 | |
| 140 PaintProperties firstTransform; | |
| 141 firstTransform.transform = adoptRef(new TransformPaintPropertyNode(Transform ationMatrix(), FloatPoint3D())); | |
| 142 chunker.updateCurrentPaintProperties(firstTransform); | |
| 143 | |
| 144 PaintProperties secondTransform; | |
| 145 secondTransform.transform = adoptRef(new TransformPaintPropertyNode(Transfor mationMatrix(), FloatPoint3D())); | |
| 146 chunker.updateCurrentPaintProperties(secondTransform); | |
| 147 | |
| 148 chunker.incrementDisplayItemIndex(); | |
| 149 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); | |
| 150 | |
| 151 EXPECT_THAT(chunks, ElementsAre( | |
| 152 PaintChunk(0, 1, rootPaintProperties()), | |
| 153 PaintChunk(1, 2, secondTransform))); | |
| 154 } | |
| 155 | |
| 156 // TODO(pdr): Add more tests once we have more paint properties. | |
| 83 | 157 |
| 84 } // namespace | 158 } // namespace |
| 85 } // namespace blink | 159 } // namespace blink |
| OLD | NEW |