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 TransformPaintProperty(TransformPai ntProperty::Type::Transform, TransformationMatrix(), FloatPoint3D())); | |
|
jbroman
2015/10/07 15:22:22
nit: ::Type is unnecessary; enumerators exist in t
| |
| 90 chunker.updateCurrentPaintProperties(simpleTransform); | |
| 91 chunker.incrementDisplayItemIndex(); | |
| 92 | |
| 93 PaintProperties anotherTransform; | |
| 94 anotherTransform.transform = adoptRef(new TransformPaintProperty(TransformPa intProperty::Type::Transform, TransformationMatrix(), FloatPoint3D())); | |
| 95 chunker.updateCurrentPaintProperties(anotherTransform); | |
| 96 chunker.incrementDisplayItemIndex(); | |
| 97 | |
| 98 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); | |
| 99 | |
| 100 EXPECT_THAT(chunks, ElementsAre( | |
| 101 PaintChunk(0, 2, rootPaintProperties()), | |
| 102 PaintChunk(2, 3, simpleTransform), | |
| 103 PaintChunk(3, 4, anotherTransform))); | |
| 104 } | |
| 105 | |
| 106 TEST_F(PaintChunkerTest, BuildLinearChunksFromNestedTransforms) | |
| 107 { | |
| 108 // Test that "nested" transforms linearize using the following | |
| 109 // sequence of transforms and display items: | |
| 110 // <root xform>, <paint>, <a xform>, <paint>, <paint>, </a xform>, <paint>, </root xform> | |
| 111 PaintChunker chunker; | |
| 112 chunker.updateCurrentPaintProperties(rootPaintProperties()); | |
| 113 chunker.incrementDisplayItemIndex(); | |
| 114 | |
| 115 PaintProperties simpleTransform; | |
| 116 simpleTransform.transform = adoptRef(new TransformPaintProperty(TransformPai ntProperty::Type::Transform, TransformationMatrix(), FloatPoint3D())); | |
| 117 chunker.updateCurrentPaintProperties(simpleTransform); | |
| 118 chunker.incrementDisplayItemIndex(); | |
| 119 chunker.incrementDisplayItemIndex(); | |
| 120 | |
| 121 chunker.updateCurrentPaintProperties(rootPaintProperties()); | |
| 122 chunker.incrementDisplayItemIndex(); | |
| 123 | |
| 124 Vector<PaintChunk> chunks = chunker.releasePaintChunks(); | |
| 125 | |
| 126 EXPECT_THAT(chunks, ElementsAre( | |
| 127 PaintChunk(0, 1, rootPaintProperties()), | |
| 128 PaintChunk(1, 3, simpleTransform), | |
| 129 PaintChunk(3, 4, rootPaintProperties()))); | |
| 130 } | |
| 131 | |
| 132 // TODO(pdr): Add more tests once we have more paint properties. | |
|
jbroman
2015/10/07 15:22:22
I'd also like tests for the case that trchen menti
pdr.
2015/10/07 20:19:11
Done
| |
| 83 | 133 |
| 84 } // namespace | 134 } // namespace |
| 85 } // namespace blink | 135 } // namespace blink |
| OLD | NEW |