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

Side by Side Diff: gm/imagemakewithfilter.cpp

Issue 1964043002: Image filters: implement SkImage::makeWithFilter(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clip subset to clipBounds; incorporate GM changes Created 4 years, 7 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 | « no previous file | include/core/SkImage.h » ('j') | include/core/SkImage.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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 "gm.h"
9 #include "SkBlurImageFilter.h"
10 #include "SkCanvas.h"
11 #include "SkColorFilter.h"
12 #include "SkColorFilterImageFilter.h"
13 #include "SkDropShadowImageFilter.h"
14 #include "SkSurface.h"
15
16 ///////////////////////////////////////////////////////////////////////////////
17
18 static void show_bounds(SkCanvas* canvas, const SkIRect& subset, const SkIRect& clip) {
19 const SkIRect rects[] { subset, clip };
20 const SkColor colors[] { SK_ColorRED, SK_ColorBLUE };
21
22 SkPaint paint;
23 paint.setStyle(SkPaint::kStroke_Style);
24
25 for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
26 paint.setColor(colors[i]);
27 canvas->drawRect(SkRect::Make(rects[i]), paint);
28 }
29 }
30
robertphillips 2016/05/19 16:35:19 // In this GM we're going to feed the inner portio
Stephen White 2016/05/19 17:44:03 Done.. (but isn't that what the code says? :) )
31 class ImageMakeWithFilterGM : public skiagm::GM {
32 public:
33 ImageMakeWithFilterGM () {}
34
35 protected:
36 SkString onShortName() override {
37 return SkString("imagemakewithfilter");
38 }
39
40 SkISize onISize() override { return SkISize::Make(320, 100); }
41
42 void onDraw(SkCanvas* canvas) override {
43 auto cf = SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_ Mode);
44 sk_sp<SkImageFilter> filters[] = {
45 SkColorFilterImageFilter::Make(std::move(cf), nullptr),
46 SkBlurImageFilter::Make(2.0f, 2.0f, nullptr),
47 SkDropShadowImageFilter::Make(
48 10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE,
49 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
50 nullptr),
51 };
52
53 const SkIRect clipBounds[] {
54 { -20, -20, 100, 100 },
55 { 0, 0, 75, 75 },
56 { 20, 20, 100, 100 },
57 { -20, -20, 50, 50 },
58 { 20, 20, 50, 50 },
59 };
60
61 const SkImageInfo info = SkImageInfo::MakeN32(100, 100, kPremul_SkAlphaT ype);
62 SkScalar MARGIN = SkIntToScalar(40);
robertphillips 2016/05/19 16:35:19 constify DX too ? maybe even MARGIN ?
Stephen White 2016/05/19 17:44:03 const POD local variables are a pet peeve of mine:
63 SkScalar DX = info.width() + MARGIN;
64 const SkScalar DY = info.height() + MARGIN;
65
66 canvas->translate(MARGIN, MARGIN);
67
68 sk_sp<SkSurface> surface = canvas->makeSurface(info);
69 if (!surface) {
70 surface = SkSurface::MakeRaster(info);
71 }
72 sk_tool_utils::draw_checkerboard(surface->getCanvas());
73 sk_sp<SkImage> source = surface->makeImageSnapshot();
74
75 for (auto clipBound : clipBounds) {
76 canvas->save();
77 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
78 SkIRect subset = SkIRect::MakeXYWH(25, 25, 50, 50);
79 SkIRect outSubset;
80 SkIPoint offset;
81 sk_sp<SkImage> result = source->makeWithFilter(filters[i].get(), subset, clipBound,
82 &outSubset, &offs et);
83 SkASSERT(result);
84 SkASSERT(source->isTextureBacked() == result->isTextureBacked()) ;
85 result = result->makeSubset(outSubset);
86 canvas->drawImage(result.get(), SkIntToScalar(offset.fX), SkIntT oScalar(offset.fY));
87 show_bounds(canvas, SkIRect::MakeXYWH(offset.x(), offset.y(), ou tSubset.width(),
88 outSubset.height()), clipB ound);
89 canvas->translate(DX, 0);
90 }
91 canvas->restore();
92 canvas->translate(0, DY);
93 }
94 }
95
96 private:
97 typedef GM INHERITED;
98 };
99 DEF_GM( return new ImageMakeWithFilterGM; )
OLDNEW
« no previous file with comments | « no previous file | include/core/SkImage.h » ('j') | include/core/SkImage.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698