OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 /* Description: | 8 /* Description: |
9 * This test defines a series of elementatry test steps that perform | 9 * This test defines a series of elementatry test steps that perform |
10 * a single or a small group of canvas API calls. Each test step is | 10 * a single or a small group of canvas API calls. Each test step is |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 canvas.save(); | 772 canvas.save(); |
773 path.moveTo(5, 5); | 773 path.moveTo(5, 5); |
774 canvas.clipPath(path); | 774 canvas.clipPath(path); |
775 canvas.restore(); | 775 canvas.restore(); |
776 canvas.save(); | 776 canvas.save(); |
777 path.moveTo(7, 7); | 777 path.moveTo(7, 7); |
778 canvas.clipPath(path); // should not assert here | 778 canvas.clipPath(path); // should not assert here |
779 canvas.restore(); | 779 canvas.restore(); |
780 } | 780 } |
781 | 781 |
| 782 #define SHADOW_TEST_CANVAS_CONST 10 |
| 783 |
| 784 class SkShadowTestCanvas : public SkPaintFilterCanvas { |
| 785 public: |
| 786 |
| 787 SkShadowTestCanvas(int x, int y, skiatest::Reporter* reporter) |
| 788 : INHERITED(x,y) |
| 789 , fReporter(reporter) {} |
| 790 |
| 791 bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const { |
| 792 REPORTER_ASSERT(this->fReporter, this->getZ() == SHADOW_TEST_CANVAS_CONS
T); |
| 793 |
| 794 return true; |
| 795 } |
| 796 |
| 797 void testUpdateDepth(skiatest::Reporter *reporter) { |
| 798 // set some depths (with picture enabled), then check them as they get s
et |
| 799 |
| 800 REPORTER_ASSERT(reporter, this->getZ() == 0); |
| 801 this->translateZ(-10); |
| 802 REPORTER_ASSERT(reporter, this->getZ() == -10); |
| 803 |
| 804 this->save(); |
| 805 this->translateZ(20); |
| 806 REPORTER_ASSERT(reporter, this->getZ() == 10); |
| 807 |
| 808 this->restore(); |
| 809 REPORTER_ASSERT(reporter, this->getZ() == -10); |
| 810 |
| 811 this->translateZ(13.14f); |
| 812 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(this->getZ(), 3.14f)); |
| 813 } |
| 814 |
| 815 private: |
| 816 skiatest::Reporter* fReporter; |
| 817 |
| 818 typedef SkPaintFilterCanvas INHERITED; |
| 819 }; |
| 820 |
782 namespace { | 821 namespace { |
783 | 822 |
784 class MockFilterCanvas : public SkPaintFilterCanvas { | 823 class MockFilterCanvas : public SkPaintFilterCanvas { |
785 public: | 824 public: |
786 MockFilterCanvas(SkCanvas* canvas) : INHERITED(canvas) { } | 825 MockFilterCanvas(SkCanvas* canvas) : INHERITED(canvas) { } |
787 | 826 |
788 protected: | 827 protected: |
789 bool onFilter(SkTCopyOnFirstWrite<SkPaint>*, Type) const override { return t
rue; } | 828 bool onFilter(SkTCopyOnFirstWrite<SkPaint>*, Type) const override { return t
rue; } |
790 | 829 |
791 private: | 830 private: |
(...skipping 13 matching lines...) Expand all Loading... |
805 MockFilterCanvas filterCanvas(&canvas); | 844 MockFilterCanvas filterCanvas(&canvas); |
806 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 845 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
807 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 846 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
808 REPORTER_ASSERT(reporter, clip1 == clip2); | 847 REPORTER_ASSERT(reporter, clip1 == clip2); |
809 | 848 |
810 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); | 849 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); |
811 filterCanvas.scale(0.75f, 0.5f); | 850 filterCanvas.scale(0.75f, 0.5f); |
812 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 851 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
813 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 852 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
814 REPORTER_ASSERT(reporter, clip1 == clip2); | 853 REPORTER_ASSERT(reporter, clip1 == clip2); |
| 854 |
| 855 SkShadowTestCanvas* tCanvas = new SkShadowTestCanvas(100,100, reporter); |
| 856 tCanvas->testUpdateDepth(reporter); |
| 857 delete(tCanvas); |
| 858 |
| 859 SkPictureRecorder recorder; |
| 860 SkShadowTestCanvas *tSCanvas = new SkShadowTestCanvas(100, 100, reporter); |
| 861 SkCanvas *tPCanvas = recorder.beginRecording(SkRect::MakeIWH(100, 100)); |
| 862 |
| 863 tPCanvas->translateZ(SHADOW_TEST_CANVAS_CONST); |
| 864 sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture(); |
| 865 tSCanvas->drawPicture(pic); |
| 866 |
| 867 delete(tSCanvas); |
815 } | 868 } |
OLD | NEW |