| 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* createContext(SkCanvas*, void* storage) const
SK_OVERRIDE { |
| 20 fOnce = true; | 20 return SkNEW_PLACEMENT(storage, TestDrawLooperContext); |
| 21 } | 21 } |
| 22 | 22 |
| 23 virtual bool next(SkCanvas* canvas, SkPaint*) SK_OVERRIDE { | 23 virtual size_t contextSize() const SK_OVERRIDE { return sizeof(TestDrawLoope
rContext); } |
| 24 if (fOnce) { | |
| 25 fOnce = false; | |
| 26 canvas->translate(SkIntToScalar(10), 0); | |
| 27 return true; | |
| 28 } | |
| 29 return false; | |
| 30 } | |
| 31 | 24 |
| 32 #ifdef SK_DEVELOPER | 25 #ifdef SK_DEVELOPER |
| 33 virtual void toString(SkString* str) const SK_OVERRIDE { | 26 virtual void toString(SkString* str) const SK_OVERRIDE { |
| 34 str->append("TestLooper:"); | 27 str->append("TestLooper:"); |
| 35 } | 28 } |
| 36 #endif | 29 #endif |
| 37 | 30 |
| 31 private: |
| 32 class TestDrawLooperContext : public SkDrawLooper::Context { |
| 33 public: |
| 34 TestDrawLooperContext() : fOnce(true) {} |
| 35 virtual ~TestDrawLooperContext() {} |
| 36 |
| 37 virtual bool next(SkCanvas* canvas, SkPaint*) SK_OVERRIDE { |
| 38 if (fOnce) { |
| 39 fOnce = false; |
| 40 canvas->translate(SkIntToScalar(10), 0); |
| 41 return true; |
| 42 } |
| 43 return false; |
| 44 } |
| 45 private: |
| 46 bool fOnce; |
| 47 }; |
| 48 |
| 38 SK_DECLARE_UNFLATTENABLE_OBJECT() | 49 SK_DECLARE_UNFLATTENABLE_OBJECT() |
| 39 }; | 50 }; |
| 40 | 51 |
| 41 static void test_drawBitmap(skiatest::Reporter* reporter) { | 52 static void test_drawBitmap(skiatest::Reporter* reporter) { |
| 42 SkBitmap src; | 53 SkBitmap src; |
| 43 src.allocN32Pixels(10, 10); | 54 src.allocN32Pixels(10, 10); |
| 44 src.eraseColor(SK_ColorWHITE); | 55 src.eraseColor(SK_ColorWHITE); |
| 45 | 56 |
| 46 SkBitmap dst; | 57 SkBitmap dst; |
| 47 dst.allocN32Pixels(10, 10); | 58 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 | 81 // allows us through, even though sans-looper we would look like we should |
| 71 // be clipped out. | 82 // be clipped out. |
| 72 paint.setLooper(new TestLooper)->unref(); | 83 paint.setLooper(new TestLooper)->unref(); |
| 73 canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint); | 84 canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint); |
| 74 REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5)); | 85 REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5)); |
| 75 } | 86 } |
| 76 | 87 |
| 77 DEF_TEST(QuickReject, reporter) { | 88 DEF_TEST(QuickReject, reporter) { |
| 78 test_drawBitmap(reporter); | 89 test_drawBitmap(reporter); |
| 79 } | 90 } |
| OLD | NEW |