OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "skia/ext/analysis_canvas.h" | 6 #include "skia/ext/analysis_canvas.h" |
7 #include "skia/ext/refptr.h" | 7 #include "skia/ext/refptr.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/skia/include/core/SkPicture.h" | 9 #include "third_party/skia/include/core/SkPicture.h" |
10 #include "third_party/skia/include/core/SkPictureRecorder.h" | 10 #include "third_party/skia/include/core/SkPictureRecorder.h" |
(...skipping 204 matching lines...) Loading... |
215 canvas.clipPath(path); | 215 canvas.clipPath(path); |
216 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); | 216 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); |
217 | 217 |
218 canvas.restore(); | 218 canvas.restore(); |
219 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); | 219 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); |
220 | 220 |
221 SolidColorFill(canvas); | 221 SolidColorFill(canvas); |
222 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); | 222 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); |
223 } | 223 } |
224 | 224 |
| 225 TEST(AnalysisCanvasTest, SaveLayerWithXfermode) { |
| 226 skia::AnalysisCanvas canvas(255, 255); |
| 227 SkRect bounds = SkRect::MakeWH(255, 255); |
| 228 SkColor outputColor; |
| 229 |
| 230 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); |
| 231 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); |
| 232 SkPaint paint; |
| 233 |
| 234 // Note: nothing is draw to the the save layer, but solid color |
| 235 // and transparency are handled conservatively in case the layer's |
| 236 // SkPaint draws something. For example, there could be an |
| 237 // SkPictureImageFilter. If someday analysis_canvas starts doing |
| 238 // a deeper analysis of the SkPaint, this test may need to be |
| 239 // redesigned. |
| 240 TransparentFill(canvas); |
| 241 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); |
| 242 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); |
| 243 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 244 canvas.saveLayer(&bounds, &paint); |
| 245 canvas.restore(); |
| 246 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); |
| 247 |
| 248 TransparentFill(canvas); |
| 249 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); |
| 250 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); |
| 251 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 252 canvas.saveLayer(&bounds, &paint); |
| 253 canvas.restore(); |
| 254 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); |
| 255 |
| 256 // Layer with dst xfermode is a no-op, so this is the only case |
| 257 // where solid color is unaffected by the layer. |
| 258 TransparentFill(canvas); |
| 259 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); |
| 260 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); |
| 261 paint.setXfermodeMode(SkXfermode::kDst_Mode); |
| 262 canvas.saveLayer(&bounds, &paint); |
| 263 canvas.restore(); |
| 264 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); |
| 265 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); |
| 266 } |
| 267 |
225 TEST(AnalysisCanvasTest, SaveLayerRestore) { | 268 TEST(AnalysisCanvasTest, SaveLayerRestore) { |
226 skia::AnalysisCanvas canvas(255, 255); | 269 skia::AnalysisCanvas canvas(255, 255); |
227 | 270 |
228 SkColor outputColor; | 271 SkColor outputColor; |
229 SolidColorFill(canvas); | 272 SolidColorFill(canvas); |
230 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); | 273 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); |
231 | 274 |
232 SkRect bounds = SkRect::MakeWH(255, 255); | 275 SkRect bounds = SkRect::MakeWH(255, 255); |
233 SkPaint paint; | 276 SkPaint paint; |
234 paint.setColor(SkColorSetARGB(255, 255, 255, 255)); | 277 paint.setColor(SkColorSetARGB(255, 255, 255, 255)); |
(...skipping 107 matching lines...) Loading... |
342 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); | 385 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); |
343 | 386 |
344 canvas.restore(); | 387 canvas.restore(); |
345 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); | 388 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); |
346 | 389 |
347 SolidColorFill(canvas); | 390 SolidColorFill(canvas); |
348 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); | 391 EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); |
349 } | 392 } |
350 | 393 |
351 } // namespace skia | 394 } // namespace skia |
OLD | NEW |