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 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 782 #define SHADOW_TEST_CANVAS_CONST 10 |
783 | 783 #ifdef SK_USE_SHADOWS |
784 class SkShadowTestCanvas : public SkPaintFilterCanvas { | 784 class SkShadowTestCanvas : public SkPaintFilterCanvas { |
785 public: | 785 public: |
786 | 786 |
787 SkShadowTestCanvas(int x, int y, skiatest::Reporter* reporter) | 787 SkShadowTestCanvas(int x, int y, skiatest::Reporter* reporter) |
788 : INHERITED(x,y) | 788 : INHERITED(x,y) |
789 , fReporter(reporter) {} | 789 , fReporter(reporter) {} |
790 | 790 |
791 bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const { | 791 bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const { |
792 REPORTER_ASSERT(this->fReporter, this->getZ() == SHADOW_TEST_CANVAS_CONS
T); | 792 REPORTER_ASSERT(this->fReporter, this->getZ() == SHADOW_TEST_CANVAS_CONS
T); |
793 | 793 |
(...skipping 16 matching lines...) Expand all Loading... |
810 | 810 |
811 this->translateZ(13.14f); | 811 this->translateZ(13.14f); |
812 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(this->getZ(), 3.14f)); | 812 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(this->getZ(), 3.14f)); |
813 } | 813 } |
814 | 814 |
815 private: | 815 private: |
816 skiatest::Reporter* fReporter; | 816 skiatest::Reporter* fReporter; |
817 | 817 |
818 typedef SkPaintFilterCanvas INHERITED; | 818 typedef SkPaintFilterCanvas INHERITED; |
819 }; | 819 }; |
| 820 #endif |
820 | 821 |
821 namespace { | 822 namespace { |
822 | 823 |
823 class MockFilterCanvas : public SkPaintFilterCanvas { | 824 class MockFilterCanvas : public SkPaintFilterCanvas { |
824 public: | 825 public: |
825 MockFilterCanvas(SkCanvas* canvas) : INHERITED(canvas) { } | 826 MockFilterCanvas(SkCanvas* canvas) : INHERITED(canvas) { } |
826 | 827 |
827 protected: | 828 protected: |
828 bool onFilter(SkTCopyOnFirstWrite<SkPaint>*, Type) const override { return t
rue; } | 829 bool onFilter(SkTCopyOnFirstWrite<SkPaint>*, Type) const override { return t
rue; } |
829 | 830 |
(...skipping 15 matching lines...) Expand all Loading... |
845 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 846 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
846 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 847 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
847 REPORTER_ASSERT(reporter, clip1 == clip2); | 848 REPORTER_ASSERT(reporter, clip1 == clip2); |
848 | 849 |
849 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); | 850 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); |
850 filterCanvas.scale(0.75f, 0.5f); | 851 filterCanvas.scale(0.75f, 0.5f); |
851 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 852 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
852 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 853 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
853 REPORTER_ASSERT(reporter, clip1 == clip2); | 854 REPORTER_ASSERT(reporter, clip1 == clip2); |
854 | 855 |
| 856 #ifdef SK_USE_SHADOWS |
855 SkShadowTestCanvas* tCanvas = new SkShadowTestCanvas(100,100, reporter); | 857 SkShadowTestCanvas* tCanvas = new SkShadowTestCanvas(100,100, reporter); |
856 tCanvas->testUpdateDepth(reporter); | 858 tCanvas->testUpdateDepth(reporter); |
857 delete(tCanvas); | 859 delete(tCanvas); |
858 | 860 |
859 SkPictureRecorder recorder; | 861 SkPictureRecorder recorder; |
860 SkShadowTestCanvas *tSCanvas = new SkShadowTestCanvas(100, 100, reporter); | 862 SkShadowTestCanvas *tSCanvas = new SkShadowTestCanvas(100, 100, reporter); |
861 SkCanvas *tPCanvas = recorder.beginRecording(SkRect::MakeIWH(100, 100)); | 863 SkCanvas *tPCanvas = recorder.beginRecording(SkRect::MakeIWH(100, 100)); |
862 | 864 |
863 tPCanvas->translateZ(SHADOW_TEST_CANVAS_CONST); | 865 tPCanvas->translateZ(SHADOW_TEST_CANVAS_CONST); |
864 sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture(); | 866 sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture(); |
865 tSCanvas->drawPicture(pic); | 867 tSCanvas->drawPicture(pic); |
866 | 868 |
867 delete(tSCanvas); | 869 delete(tSCanvas); |
| 870 #endif |
868 } | 871 } |
869 | 872 |
870 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 873 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
871 | 874 |
872 #include "SkDeferredCanvas.h" | 875 #include "SkDeferredCanvas.h" |
873 #include "SkDumpCanvas.h" | 876 #include "SkDumpCanvas.h" |
874 | 877 |
875 DEF_TEST(DeferredCanvas, r) { | 878 DEF_TEST(DeferredCanvas, r) { |
876 SkDebugfDumper dumper; | 879 SkDebugfDumper dumper; |
877 SkDumpCanvas dumpC(&dumper); | 880 SkDumpCanvas dumpC(&dumper); |
878 | 881 |
879 SkDeferredCanvas canvas(&dumpC); | 882 SkDeferredCanvas canvas(&dumpC); |
880 | 883 |
881 SkPaint paint; | 884 SkPaint paint; |
882 // paint.setShader(SkShader::MakeColorShader(SK_ColorRED)); | 885 // paint.setShader(SkShader::MakeColorShader(SK_ColorRED)); |
883 | 886 |
884 canvas.save(); | 887 canvas.save(); |
885 canvas.clipRect(SkRect::MakeWH(55, 55)); | 888 canvas.clipRect(SkRect::MakeWH(55, 55)); |
886 canvas.translate(10, 20); | 889 canvas.translate(10, 20); |
887 canvas.drawRect(SkRect::MakeWH(50, 50), paint); | 890 canvas.drawRect(SkRect::MakeWH(50, 50), paint); |
888 canvas.restore(); | 891 canvas.restore(); |
889 } | 892 } |
890 | 893 |
OLD | NEW |