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::DrawContext* init(SkCanvas*, void*, size_t) const |
20 fOnce = true; | 20 SK_OVERRIDE { |
21 } | 21 return SkNEW(TestDrawLooperContext); |
22 | |
23 virtual bool next(SkCanvas* canvas, SkPaint*) SK_OVERRIDE { | |
24 if (fOnce) { | |
25 fOnce = false; | |
26 canvas->translate(SkIntToScalar(10), 0); | |
27 return true; | |
28 } | |
29 return false; | |
30 } | 22 } |
31 | 23 |
32 #ifdef SK_DEVELOPER | 24 #ifdef SK_DEVELOPER |
33 virtual void toString(SkString* str) const SK_OVERRIDE { | 25 virtual void toString(SkString* str) const SK_OVERRIDE { |
34 str->append("TestLooper:"); | 26 str->append("TestLooper:"); |
35 } | 27 } |
36 #endif | 28 #endif |
37 | 29 |
| 30 private: |
| 31 class TestDrawLooperContext : public SkDrawLooper::DrawContext { |
| 32 public: |
| 33 TestDrawLooperContext() : fOnce(true) {} |
| 34 virtual ~TestDrawLooperContext() {} |
| 35 |
| 36 virtual bool next(SkCanvas* canvas, SkPaint*) SK_OVERRIDE { |
| 37 if (fOnce) { |
| 38 fOnce = false; |
| 39 canvas->translate(SkIntToScalar(10), 0); |
| 40 return true; |
| 41 } |
| 42 return false; |
| 43 } |
| 44 private: |
| 45 bool fOnce; |
| 46 }; |
| 47 |
38 SK_DECLARE_UNFLATTENABLE_OBJECT() | 48 SK_DECLARE_UNFLATTENABLE_OBJECT() |
39 }; | 49 }; |
40 | 50 |
41 static void test_drawBitmap(skiatest::Reporter* reporter) { | 51 static void test_drawBitmap(skiatest::Reporter* reporter) { |
42 SkBitmap src; | 52 SkBitmap src; |
43 src.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); | 53 src.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); |
44 src.allocPixels(); | 54 src.allocPixels(); |
45 src.eraseColor(SK_ColorWHITE); | 55 src.eraseColor(SK_ColorWHITE); |
46 | 56 |
47 SkBitmap dst; | 57 SkBitmap dst; |
(...skipping 24 matching lines...) Expand all Loading... |
72 // 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 |
73 // be clipped out. | 83 // be clipped out. |
74 paint.setLooper(new TestLooper)->unref(); | 84 paint.setLooper(new TestLooper)->unref(); |
75 canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint); | 85 canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint); |
76 REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5)); | 86 REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5)); |
77 } | 87 } |
78 | 88 |
79 DEF_TEST(QuickReject, reporter) { | 89 DEF_TEST(QuickReject, reporter) { |
80 test_drawBitmap(reporter); | 90 test_drawBitmap(reporter); |
81 } | 91 } |
OLD | NEW |