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

Side by Side Diff: tests/DrawLooperTest.cpp

Issue 993863002: Make the canvas draw looper internal layer not part of SkCanvas save count Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: another approach Created 5 years, 8 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 | « src/core/SkCanvas.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
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkCanvas.h"
9 #include "SkColorFilter.h"
10 #include "SkColorFilterImageFilter.h"
11 #include "SkDrawLooper.h"
12 #include "Test.h"
13
14 /* Tests for SkDrawLooper -related APIs and implementations. */
15
16 namespace {
17 /*
18 * Subclass that caused an assert at the time of writing.
19 */
20 class GetSaveCountAssertLooper : public SkDrawLooper {
21 public:
22 GetSaveCountAssertLooper(skiatest::Reporter* reporter)
23 : fReporter(reporter) {
24 }
25
26 SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const overrid e {
27 return SkNEW_PLACEMENT_ARGS(storage, GetSaveCountAssertLooperContext, (f Reporter));
28 }
29
30 size_t contextSize() const override { return sizeof(GetSaveCountAssertLooper Context); }
31
32 #ifndef SK_IGNORE_TO_STRING
33 void toString(SkString* str) const override {
34 str->append("GetSaveCountAssertLooper:");
35 }
36 #endif
37
38 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(GetSaveCountAssertLooper );
39
40 private:
41 class GetSaveCountAssertLooperContext : public SkDrawLooper::Context {
42 public:
43 GetSaveCountAssertLooperContext(skiatest::Reporter* reporter)
44 : fReporter(reporter)
45 , fOnce(0) {
46 }
47
48 bool next(SkCanvas* canvas, SkPaint* p) override {
49 // 1st test: Getting the save count would assert in SkCanvas at the time of writing.
50 // 2nd test: test the sentence from SkCanvas.h:
51 // This will equal # save() calls - # restore() calls + 1.
52 REPORTER_ASSERT(fReporter, 1 == canvas->getSaveCount());
53
54 SkASSERT(p->getColor() == SK_ColorRED);
55 // Set the color green so the test knows payload was run. We use thi s color in order to
56 // try to express the expectation that Skia can not away the color f ilter. Due to
57 // non-pm-to-pm-to-non-pm conversions, this probably is not exactly correct.
58 p->setColor(SkColorSetARGB(255, 0, 254, 0));
59 return fOnce++ < 1;
60 }
61 private:
62 skiatest::Reporter* fReporter;
63 int fOnce;
64 };
65 mutable skiatest::Reporter* fReporter;
66 };
67
68 SkFlattenable* GetSaveCountAssertLooper::CreateProc(SkReadBuffer&) {
69 SkASSERT(false);
70 return SkNEW_ARGS(GetSaveCountAssertLooper, (NULL));
71 }
72
73 }
74
75 DEF_TEST(SkCanvas_GetSaveCountInDrawLooperAssert, reporter) {
76 SkBitmap dst;
77 dst.allocN32Pixels(10, 10);
78 dst.eraseColor(SK_ColorTRANSPARENT);
79
80 SkCanvas canvas(dst);
81 SkPaint paint;
82 {
83 SkAutoTUnref<SkColorFilter> addGreenCF(
84 SkColorFilter::CreateModeFilter(SkColorSetARGB(64, 0, 4, 0), SkXferm ode::kPlus_Mode));
85 SkAutoTUnref<SkImageFilter> addGreenIF(
86 SkColorFilterImageFilter::Create(addGreenCF));
87
88 // This would trigger the assert upon a draw. It is a color filter that adds (roughly) 1 to
89 // the green component.
90 paint.setImageFilter(addGreenIF);
91
92 SkAutoTUnref<SkDrawLooper> looper(SkNEW_ARGS(GetSaveCountAssertLooper, ( reporter)));
93 paint.setLooper(looper);
94 }
95 paint.setColor(SK_ColorRED);
96 paint.setStrokeWidth(1);
97 paint.setStyle(SkPaint::kStroke_Style);
98 canvas.drawPoint(0, 0, paint);
99
100 uint32_t pixel = 0;
101 SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul _SkAlphaType);
102 canvas.readPixels(info, &pixel, 4, 0, 0);
103 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
104 }
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698