OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDeque.h" | 8 #include "SkDeque.h" |
9 #include "SkLayerRasterizer.h" | 9 #include "SkLayerRasterizer.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 SkPaint fPaint; | 74 SkPaint fPaint; |
75 SkVector fOffset; | 75 SkVector fOffset; |
76 }; | 76 }; |
77 | 77 |
78 static bool equals(const SkLayerRasterizer_Rec& rec1, const SkLayerRasterizer_Re
c& rec2) { | 78 static bool equals(const SkLayerRasterizer_Rec& rec1, const SkLayerRasterizer_Re
c& rec2) { |
79 return rec1.fPaint == rec2.fPaint && rec1.fOffset == rec2.fOffset; | 79 return rec1.fPaint == rec2.fPaint && rec1.fOffset == rec2.fOffset; |
80 } | 80 } |
81 | 81 |
82 DEF_TEST(LayerRasterizer_copy, reporter) { | 82 DEF_TEST(LayerRasterizer_copy, reporter) { |
83 SkLayerRasterizer::Builder builder; | 83 SkLayerRasterizer::Builder builder; |
84 REPORTER_ASSERT(reporter, NULL == builder.snapshotRasterizer()); | 84 REPORTER_ASSERT(reporter, nullptr == builder.snapshotRasterizer()); |
85 SkPaint paint; | 85 SkPaint paint; |
86 // Create a bunch of paints with different flags. | 86 // Create a bunch of paints with different flags. |
87 for (uint32_t flags = 0x01; flags < SkPaint::kAllFlags; flags <<= 1) { | 87 for (uint32_t flags = 0x01; flags < SkPaint::kAllFlags; flags <<= 1) { |
88 paint.setFlags(flags); | 88 paint.setFlags(flags); |
89 builder.addLayer(paint, static_cast<SkScalar>(flags), static_cast<SkScal
ar>(flags)); | 89 builder.addLayer(paint, static_cast<SkScalar>(flags), static_cast<SkScal
ar>(flags)); |
90 } | 90 } |
91 | 91 |
92 // Create a layer rasterizer with all the existing layers. | 92 // Create a layer rasterizer with all the existing layers. |
93 SkAutoTUnref<SkLayerRasterizer> firstCopy(builder.snapshotRasterizer()); | 93 SkAutoTUnref<SkLayerRasterizer> firstCopy(builder.snapshotRasterizer()); |
94 | 94 |
95 // Add one more layer. | 95 // Add one more layer. |
96 paint.setFlags(SkPaint::kAllFlags); | 96 paint.setFlags(SkPaint::kAllFlags); |
97 builder.addLayer(paint); | 97 builder.addLayer(paint); |
98 | 98 |
99 SkAutoTUnref<SkLayerRasterizer> oneLarger(builder.snapshotRasterizer()); | 99 SkAutoTUnref<SkLayerRasterizer> oneLarger(builder.snapshotRasterizer()); |
100 SkAutoTUnref<SkLayerRasterizer> detached(builder.detachRasterizer()); | 100 SkAutoTUnref<SkLayerRasterizer> detached(builder.detachRasterizer()); |
101 | 101 |
102 // Check the counts for consistency. | 102 // Check the counts for consistency. |
103 const int largerCount = LayerRasterizerTester::CountLayers(*oneLarger.get())
; | 103 const int largerCount = LayerRasterizerTester::CountLayers(*oneLarger.get())
; |
104 const int smallerCount = LayerRasterizerTester::CountLayers(*firstCopy.get()
); | 104 const int smallerCount = LayerRasterizerTester::CountLayers(*firstCopy.get()
); |
105 REPORTER_ASSERT(reporter, largerCount == LayerRasterizerTester::CountLayers(
*detached.get())); | 105 REPORTER_ASSERT(reporter, largerCount == LayerRasterizerTester::CountLayers(
*detached.get())); |
106 REPORTER_ASSERT(reporter, smallerCount == largerCount - 1); | 106 REPORTER_ASSERT(reporter, smallerCount == largerCount - 1); |
107 | 107 |
108 const SkLayerRasterizer_Rec* recFirstCopy = NULL; | 108 const SkLayerRasterizer_Rec* recFirstCopy = nullptr; |
109 const SkLayerRasterizer_Rec* recOneLarger = NULL; | 109 const SkLayerRasterizer_Rec* recOneLarger = nullptr; |
110 const SkLayerRasterizer_Rec* recDetached = NULL; | 110 const SkLayerRasterizer_Rec* recDetached = nullptr; |
111 | 111 |
112 const SkDeque& layersFirstCopy = LayerRasterizerTester::GetLayers(*firstCopy
.get()); | 112 const SkDeque& layersFirstCopy = LayerRasterizerTester::GetLayers(*firstCopy
.get()); |
113 const SkDeque& layersOneLarger = LayerRasterizerTester::GetLayers(*oneLarger
.get()); | 113 const SkDeque& layersOneLarger = LayerRasterizerTester::GetLayers(*oneLarger
.get()); |
114 const SkDeque& layersDetached = LayerRasterizerTester::GetLayers(*detached.g
et()); | 114 const SkDeque& layersDetached = LayerRasterizerTester::GetLayers(*detached.g
et()); |
115 | 115 |
116 // Ensure that our version of SkLayerRasterizer_Rec is the same as the one i
n | 116 // Ensure that our version of SkLayerRasterizer_Rec is the same as the one i
n |
117 // SkLayerRasterizer.cpp - or at least the same size. If the order were swit
ched, we | 117 // SkLayerRasterizer.cpp - or at least the same size. If the order were swit
ched, we |
118 // would fail the test elsewhere. | 118 // would fail the test elsewhere. |
119 REPORTER_ASSERT(reporter, layersFirstCopy.elemSize() == sizeof(SkLayerRaster
izer_Rec)); | 119 REPORTER_ASSERT(reporter, layersFirstCopy.elemSize() == sizeof(SkLayerRaster
izer_Rec)); |
120 REPORTER_ASSERT(reporter, layersOneLarger.elemSize() == sizeof(SkLayerRaster
izer_Rec)); | 120 REPORTER_ASSERT(reporter, layersOneLarger.elemSize() == sizeof(SkLayerRaster
izer_Rec)); |
121 REPORTER_ASSERT(reporter, layersDetached.elemSize() == sizeof(SkLayerRasteri
zer_Rec)); | 121 REPORTER_ASSERT(reporter, layersDetached.elemSize() == sizeof(SkLayerRasteri
zer_Rec)); |
122 | 122 |
123 SkDeque::F2BIter iterFirstCopy(layersFirstCopy); | 123 SkDeque::F2BIter iterFirstCopy(layersFirstCopy); |
124 SkDeque::F2BIter iterOneLarger(layersOneLarger); | 124 SkDeque::F2BIter iterOneLarger(layersOneLarger); |
125 SkDeque::F2BIter iterDetached(layersDetached); | 125 SkDeque::F2BIter iterDetached(layersDetached); |
126 | 126 |
127 for (int i = 0; i < largerCount; ++i) { | 127 for (int i = 0; i < largerCount; ++i) { |
128 recFirstCopy = static_cast<const SkLayerRasterizer_Rec*>(iterFirstCopy.n
ext()); | 128 recFirstCopy = static_cast<const SkLayerRasterizer_Rec*>(iterFirstCopy.n
ext()); |
129 recOneLarger = static_cast<const SkLayerRasterizer_Rec*>(iterOneLarger.n
ext()); | 129 recOneLarger = static_cast<const SkLayerRasterizer_Rec*>(iterOneLarger.n
ext()); |
130 recDetached = static_cast<const SkLayerRasterizer_Rec*>(iterDetached.ne
xt()); | 130 recDetached = static_cast<const SkLayerRasterizer_Rec*>(iterDetached.ne
xt()); |
131 | 131 |
132 REPORTER_ASSERT(reporter, equals(*recOneLarger, *recDetached)); | 132 REPORTER_ASSERT(reporter, equals(*recOneLarger, *recDetached)); |
133 if (smallerCount == i) { | 133 if (smallerCount == i) { |
134 REPORTER_ASSERT(reporter, recFirstCopy == NULL); | 134 REPORTER_ASSERT(reporter, recFirstCopy == nullptr); |
135 } else { | 135 } else { |
136 REPORTER_ASSERT(reporter, equals(*recFirstCopy, *recOneLarger)); | 136 REPORTER_ASSERT(reporter, equals(*recFirstCopy, *recOneLarger)); |
137 } | 137 } |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 DEF_TEST(LayerRasterizer_detachEmpty, reporter) { | 141 DEF_TEST(LayerRasterizer_detachEmpty, reporter) { |
142 SkLayerRasterizer::Builder builder; | 142 SkLayerRasterizer::Builder builder; |
143 REPORTER_ASSERT(reporter, NULL == builder.detachRasterizer()); | 143 REPORTER_ASSERT(reporter, nullptr == builder.detachRasterizer()); |
144 } | 144 } |
OLD | NEW |