OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkDrawLooper.h" | 9 #include "SkDrawLooper.h" |
10 #include "SkTypes.h" | |
10 #include "Test.h" | 11 #include "Test.h" |
11 | 12 |
12 /* | 13 /* |
13 * Subclass of looper that just draws once, with an offset in X. | 14 * Subclass of looper that just draws once, with an offset in X. |
14 */ | 15 */ |
15 class TestLooper : public SkDrawLooper { | 16 class TestLooper : public SkDrawLooper { |
16 public: | 17 public: |
17 bool fOnce; | |
18 | 18 |
19 virtual void init(SkCanvas*) SK_OVERRIDE { | 19 virtual SkDrawLooper::Context* init(SkCanvas*, SkDrawLooper::ContextAllocato r* allocator) const |
20 fOnce = true; | 20 SK_OVERRIDE { |
21 } | 21 int tp=sizeof(TestDrawLooperContext); |
scroggo
2014/03/10 19:41:32
Shouldn't the return value of sizeof be a size_t?
| |
22 | 22 if (tp < 0) return NULL; |
scroggo
2014/03/10 19:41:32
I don't think this should ever happen.
Dominik Grewe
2014/03/10 21:54:07
Sorry, please ignore those two lines. I just added
| |
23 virtual bool next(SkCanvas* canvas, SkPaint*) SK_OVERRIDE { | 23 return allocator->createT<TestDrawLooperContext>(); |
24 if (fOnce) { | |
25 fOnce = false; | |
26 canvas->translate(SkIntToScalar(10), 0); | |
27 return true; | |
28 } | |
29 return false; | |
30 } | 24 } |
31 | 25 |
32 #ifdef SK_DEVELOPER | 26 #ifdef SK_DEVELOPER |
33 virtual void toString(SkString* str) const SK_OVERRIDE { | 27 virtual void toString(SkString* str) const SK_OVERRIDE { |
34 str->append("TestLooper:"); | 28 str->append("TestLooper:"); |
35 } | 29 } |
36 #endif | 30 #endif |
37 | 31 |
32 private: | |
33 class TestDrawLooperContext : public SkDrawLooper::Context { | |
34 public: | |
35 TestDrawLooperContext() : fOnce(true) {} | |
36 virtual ~TestDrawLooperContext() {} | |
37 | |
38 virtual bool next(SkCanvas* canvas, SkPaint*) SK_OVERRIDE { | |
39 if (fOnce) { | |
40 fOnce = false; | |
41 canvas->translate(SkIntToScalar(10), 0); | |
42 return true; | |
43 } | |
44 return false; | |
45 } | |
46 private: | |
47 bool fOnce; | |
48 }; | |
49 | |
38 SK_DECLARE_UNFLATTENABLE_OBJECT() | 50 SK_DECLARE_UNFLATTENABLE_OBJECT() |
39 }; | 51 }; |
40 | 52 |
41 static void test_drawBitmap(skiatest::Reporter* reporter) { | 53 static void test_drawBitmap(skiatest::Reporter* reporter) { |
42 SkBitmap src; | 54 SkBitmap src; |
43 src.allocN32Pixels(10, 10); | 55 src.allocN32Pixels(10, 10); |
44 src.eraseColor(SK_ColorWHITE); | 56 src.eraseColor(SK_ColorWHITE); |
45 | 57 |
46 SkBitmap dst; | 58 SkBitmap dst; |
47 dst.allocN32Pixels(10, 10); | 59 dst.allocN32Pixels(10, 10); |
(...skipping 22 matching lines...) Expand all Loading... | |
70 // allows us through, even though sans-looper we would look like we should | 82 // allows us through, even though sans-looper we would look like we should |
71 // be clipped out. | 83 // be clipped out. |
72 paint.setLooper(new TestLooper)->unref(); | 84 paint.setLooper(new TestLooper)->unref(); |
73 canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint); | 85 canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint); |
74 REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5)); | 86 REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5)); |
75 } | 87 } |
76 | 88 |
77 DEF_TEST(QuickReject, reporter) { | 89 DEF_TEST(QuickReject, reporter) { |
78 test_drawBitmap(reporter); | 90 test_drawBitmap(reporter); |
79 } | 91 } |
OLD | NEW |