Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(658)

Side by Side Diff: tests/QuickRejectTest.cpp

Issue 155513012: [WIP] Add Context to SkDrawLooper. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/LayerDrawLooperTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « tests/LayerDrawLooperTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698