OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
11 #include "SkFlate.h" | 11 #include "SkFlate.h" |
12 #include "SkImageEncoder.h" | 12 #include "SkImageEncoder.h" |
13 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
14 #include "SkPDFCatalog.h" | 14 #include "SkPDFCatalog.h" |
15 #include "SkPDFDevice.h" | 15 #include "SkPDFDevice.h" |
16 #include "SkPDFStream.h" | 16 #include "SkPDFStream.h" |
17 #include "SkPDFTypes.h" | 17 #include "SkPDFTypes.h" |
| 18 #include "SkReadBuffer.h" |
18 #include "SkScalar.h" | 19 #include "SkScalar.h" |
19 #include "SkStream.h" | 20 #include "SkStream.h" |
20 #include "SkTypes.h" | 21 #include "SkTypes.h" |
21 #include "Test.h" | 22 #include "Test.h" |
22 | 23 |
23 class SkPDFTestDict : public SkPDFDict { | 24 class SkPDFTestDict : public SkPDFDict { |
24 public: | 25 public: |
25 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, | 26 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, |
26 SkTSet<SkPDFObject*>* newResourceObjects) { | 27 SkTSet<SkPDFObject*>* newResourceObjects) { |
27 for (int i = 0; i < fResources.count(); i++) { | 28 for (int i = 0; i < fResources.count(); i++) { |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 TestCatalog(reporter); | 422 TestCatalog(reporter); |
422 | 423 |
423 TestObjectRef(reporter); | 424 TestObjectRef(reporter); |
424 | 425 |
425 TestSubstitute(reporter); | 426 TestSubstitute(reporter); |
426 | 427 |
427 test_issue1083(); | 428 test_issue1083(); |
428 | 429 |
429 TestImages(reporter); | 430 TestImages(reporter); |
430 } | 431 } |
| 432 |
| 433 namespace { |
| 434 |
| 435 class DummyImageFilter : public SkImageFilter { |
| 436 public: |
| 437 DummyImageFilter(bool visited = false) : SkImageFilter(0, NULL), fVisited(vi
sited) {} |
| 438 virtual ~DummyImageFilter() SK_OVERRIDE {} |
| 439 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 440 SkBitmap* result, SkIPoint* offset) const { |
| 441 fVisited = true; |
| 442 offset->fX = offset->fY = 0; |
| 443 *result = src; |
| 444 return true; |
| 445 } |
| 446 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(DummyImageFilter) |
| 447 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 448 explicit DummyImageFilter(SkReadBuffer& buffer) : SkImageFilter(0, NULL) { |
| 449 fVisited = buffer.readBool(); |
| 450 } |
| 451 #endif |
| 452 bool visited() const { return fVisited; } |
| 453 |
| 454 private: |
| 455 mutable bool fVisited; |
| 456 }; |
| 457 |
| 458 SkFlattenable* DummyImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 459 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); |
| 460 bool visited = buffer.readBool(); |
| 461 return SkNEW_ARGS(DummyImageFilter, (visited)); |
| 462 } |
| 463 |
| 464 }; |
| 465 |
| 466 // Check that PDF rendering of image filters successfully falls back to |
| 467 // CPU rasterization. |
| 468 DEF_TEST(PDFImageFilter, reporter) { |
| 469 SkISize pageSize = SkISize::Make(100, 100); |
| 470 SkAutoTUnref<SkPDFDevice> device(new SkPDFDevice(pageSize, pageSize, SkMatri
x::I())); |
| 471 SkCanvas canvas(device.get()); |
| 472 SkAutoTUnref<DummyImageFilter> filter(new DummyImageFilter()); |
| 473 |
| 474 // Filter just created; should be unvisited. |
| 475 REPORTER_ASSERT(reporter, !filter->visited()); |
| 476 SkPaint paint; |
| 477 paint.setImageFilter(filter.get()); |
| 478 canvas.drawRect(SkRect::MakeWH(100, 100), paint); |
| 479 |
| 480 // Filter was used in rendering; should be visited. |
| 481 REPORTER_ASSERT(reporter, filter->visited()); |
| 482 } |
OLD | NEW |