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

Side by Side Diff: gm/imagefilters.cpp

Issue 2396953002: Revert[8] "replace SkXfermode obj with SkBlendMode enum in paints" (Closed)
Patch Set: add tmp virtual to unroll legacy arithmodes Created 4 years, 2 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 | « gm/hairmodes.cpp ('k') | gm/imagefiltersgraph.cpp » ('j') | 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 2015 Google Inc. 2 * Copyright 2015 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 "gm.h" 8 #include "gm.h"
9 #include "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkColorMatrixFilter.h" 10 #include "SkColorMatrixFilter.h"
11 #include "SkImage.h" 11 #include "SkImage.h"
12 #include "SkImageFilter.h" 12 #include "SkImageFilter.h"
13 #include "SkSurface.h" 13 #include "SkSurface.h"
14 14
15 /** 15 /**
16 * Test drawing a primitive w/ an imagefilter (in this case, just matrix w/ ide ntity) to see 16 * Test drawing a primitive w/ an imagefilter (in this case, just matrix w/ ide ntity) to see
17 * that we apply the xfermode *after* the image has been created and filtered, and not during 17 * that we apply the xfermode *after* the image has been created and filtered, and not during
18 * the creation step (i.e. before it is filtered). 18 * the creation step (i.e. before it is filtered).
19 * 19 *
20 * see https://bug.skia.org/3741 20 * see https://bug.skia.org/3741
21 */ 21 */
22 static void do_draw(SkCanvas* canvas, SkXfermode::Mode mode, sk_sp<SkImageFilter > imf) { 22 static void do_draw(SkCanvas* canvas, SkBlendMode mode, sk_sp<SkImageFilter> imf ) {
23 SkAutoCanvasRestore acr(canvas, true); 23 SkAutoCanvasRestore acr(canvas, true);
24 canvas->clipRect(SkRect::MakeWH(220, 220)); 24 canvas->clipRect(SkRect::MakeWH(220, 220));
25 25
26 // want to force a layer, so modes like DstIn can combine meaningfully, but the final 26 // want to force a layer, so modes like DstIn can combine meaningfully, but the final
27 // image can still be shown against our default (opaque) background. non -opaque GMs 27 // image can still be shown against our default (opaque) background. non -opaque GMs
28 // are a lot more trouble to compare/triage. 28 // are a lot more trouble to compare/triage.
29 canvas->saveLayer(nullptr, nullptr); 29 canvas->saveLayer(nullptr, nullptr);
30 canvas->drawColor(SK_ColorGREEN); 30 canvas->drawColor(SK_ColorGREEN);
31 31
32 SkPaint paint; 32 SkPaint paint;
33 paint.setAntiAlias(true); 33 paint.setAntiAlias(true);
34 34
35 SkRect r0 = SkRect::MakeXYWH(10, 60, 200, 100); 35 SkRect r0 = SkRect::MakeXYWH(10, 60, 200, 100);
36 SkRect r1 = SkRect::MakeXYWH(60, 10, 100, 200); 36 SkRect r1 = SkRect::MakeXYWH(60, 10, 100, 200);
37 37
38 paint.setColor(SK_ColorRED); 38 paint.setColor(SK_ColorRED);
39 canvas->drawOval(r0, paint); 39 canvas->drawOval(r0, paint);
40 40
41 paint.setColor(0x660000FF); 41 paint.setColor(0x660000FF);
42 paint.setImageFilter(std::move(imf)); 42 paint.setImageFilter(std::move(imf));
43 paint.setXfermodeMode(mode); 43 paint.setBlendMode(mode);
44 canvas->drawOval(r1, paint); 44 canvas->drawOval(r1, paint);
45 } 45 }
46 46
47 DEF_SIMPLE_GM(imagefilters_xfermodes, canvas, 480, 480) { 47 DEF_SIMPLE_GM(imagefilters_xfermodes, canvas, 480, 480) {
48 canvas->translate(10, 10); 48 canvas->translate(10, 10);
49 49
50 // just need an imagefilter to trigger the code-path (which creates a tm p layer) 50 // just need an imagefilter to trigger the code-path (which creates a tm p layer)
51 sk_sp<SkImageFilter> imf(SkImageFilter::MakeMatrixFilter(SkMatrix::I(), 51 sk_sp<SkImageFilter> imf(SkImageFilter::MakeMatrixFilter(SkMatrix::I(),
52 kNone_SkFilterQ uality, 52 kNone_SkFilterQ uality,
53 nullptr)); 53 nullptr));
54 54
55 const SkXfermode::Mode modes[] = { 55 const SkBlendMode modes[] = {
56 SkXfermode::kSrcATop_Mode, SkXfermode::kDstIn_Mode 56 SkBlendMode::kSrcATop, SkBlendMode::kDstIn
57 }; 57 };
58 58
59 for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) { 59 for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) {
60 canvas->save(); 60 canvas->save();
61 do_draw(canvas, modes[i], nullptr); 61 do_draw(canvas, modes[i], nullptr);
62 canvas->translate(240, 0); 62 canvas->translate(240, 0);
63 do_draw(canvas, modes[i], imf); 63 do_draw(canvas, modes[i], imf);
64 canvas->restore(); 64 canvas->restore();
65 65
66 canvas->translate(0, 240); 66 canvas->translate(0, 240);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 canvas->translate(20, 20); 168 canvas->translate(20, 20);
169 for (const auto& xform : xforms) { 169 for (const auto& xform : xforms) {
170 canvas->save(); 170 canvas->save();
171 canvas->translate(xform.fTx, xform.fTy); 171 canvas->translate(xform.fTx, xform.fTy);
172 canvas->scale(xform.fSx, xform.fSy); 172 canvas->scale(xform.fSx, xform.fSy);
173 canvas->drawImage(image, 0, 0, &paint); 173 canvas->drawImage(image, 0, 0, &paint);
174 draw_set(canvas, filters, SK_ARRAY_COUNT(filters)); 174 draw_set(canvas, filters, SK_ARRAY_COUNT(filters));
175 canvas->restore(); 175 canvas->restore();
176 } 176 }
177 } 177 }
OLDNEW
« no previous file with comments | « gm/hairmodes.cpp ('k') | gm/imagefiltersgraph.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698