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

Side by Side Diff: gm/imagesource.cpp

Issue 1842243002: Update SkImageSource to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 4 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 | « gm/imagefilterstransformed.cpp ('k') | gm/imagesource2.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 2013 Google Inc. 2 * Copyright 2013 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 9
10 #include "SkImage.h" 10 #include "SkImage.h"
11 #include "SkImageSource.h" 11 #include "SkImageSource.h"
12 12
13 // This GM exercises the SkImageSource ImageFilter class. 13 // This GM exercises the SkImageSource ImageFilter class.
14 14
15 static void fill_rect_filtered(SkCanvas* canvas,
16 const SkRect& clipRect,
17 sk_sp<SkImageFilter> filter) {
18 SkPaint paint;
19 paint.setImageFilter(std::move(filter));
20 canvas->save();
21 canvas->clipRect(clipRect);
22 canvas->drawPaint(paint);
23 canvas->restore();
24 }
25
15 class ImageSourceGM : public skiagm::GM { 26 class ImageSourceGM : public skiagm::GM {
16 public: 27 public:
17 ImageSourceGM() { } 28 ImageSourceGM() { }
18 29
19 protected: 30 protected:
20 SkString onShortName() override { 31 SkString onShortName() override {
21 return SkString("imagesource"); 32 return SkString("imagesource");
22 } 33 }
23 34
24 SkISize onISize() override { return SkISize::Make(500, 150); } 35 SkISize onISize() override { return SkISize::Make(500, 150); }
25 36
26 void onOnceBeforeDraw() override { 37 void onOnceBeforeDraw() override {
27 SkBitmap bm = sk_tool_utils::create_string_bitmap(100, 100, 0xFFFFFFFF, 20, 70, 96, "e"); 38 SkBitmap bm = sk_tool_utils::create_string_bitmap(100, 100, 0xFFFFFFFF, 20, 70, 96, "e");
28 fImage = SkImage::MakeFromBitmap(bm); 39 fImage = SkImage::MakeFromBitmap(bm);
29 } 40 }
30 41
31 static void FillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma geFilter* filter) {
32 SkPaint paint;
33 paint.setImageFilter(filter);
34 canvas->save();
35 canvas->clipRect(clipRect);
36 canvas->drawPaint(paint);
37 canvas->restore();
38 }
39
40 void onDraw(SkCanvas* canvas) override { 42 void onDraw(SkCanvas* canvas) override {
41 canvas->clear(SK_ColorBLACK); 43 canvas->clear(SK_ColorBLACK);
44
45 const SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
46 const SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60);
47 const SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100);
48 const SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height()) ;
49
42 { 50 {
43 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
44 SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60);
45 SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100);
46 SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
47 SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(fImage .get()));
48 SkAutoTUnref<SkImageFilter> imageSourceSrcRect(
49 SkImageSource::Create(fImage.get(), srcRect, srcRect, kHigh_SkFi lterQuality));
50 SkAutoTUnref<SkImageFilter> imageSourceSrcRectDstRect(
51 SkImageSource::Create(fImage.get(), srcRect, dstRect, kHigh_SkFi lterQuality));
52 SkAutoTUnref<SkImageFilter> imageSourceDstRectOnly(
53 SkImageSource::Create(fImage.get(), bounds, dstRect, kHigh_SkFil terQuality));
54
55 // Draw an unscaled bitmap. 51 // Draw an unscaled bitmap.
56 FillRectFiltered(canvas, clipRect, imageSource); 52 sk_sp<SkImageFilter> imageSource(SkImageSource::Make(fImage));
53 fill_rect_filtered(canvas, clipRect, std::move(imageSource));
57 canvas->translate(SkIntToScalar(100), 0); 54 canvas->translate(SkIntToScalar(100), 0);
58 55 }
56 {
59 // Draw an unscaled subset of the source bitmap (srcRect -> srcRect) . 57 // Draw an unscaled subset of the source bitmap (srcRect -> srcRect) .
60 FillRectFiltered(canvas, clipRect, imageSourceSrcRect); 58 sk_sp<SkImageFilter> imageSourceSrcRect(
59 SkImageSource::Make(fImage, srcRect, srcRect, kHigh_SkFilterQual ity));
60 fill_rect_filtered(canvas, clipRect, std::move(imageSourceSrcRect));
61 canvas->translate(SkIntToScalar(100), 0); 61 canvas->translate(SkIntToScalar(100), 0);
62 62 }
63 {
63 // Draw a subset of the bitmap scaled to a destination rect (srcRect -> dstRect). 64 // Draw a subset of the bitmap scaled to a destination rect (srcRect -> dstRect).
64 FillRectFiltered(canvas, clipRect, imageSourceSrcRectDstRect); 65 sk_sp<SkImageFilter> imageSourceSrcRectDstRect(
66 SkImageSource::Make(fImage, srcRect, dstRect, kHigh_SkFilterQual ity));
67 fill_rect_filtered(canvas, clipRect, std::move(imageSourceSrcRectDst Rect));
65 canvas->translate(SkIntToScalar(100), 0); 68 canvas->translate(SkIntToScalar(100), 0);
66 69 }
70 {
67 // Draw the entire bitmap scaled to a destination rect (bounds -> ds tRect). 71 // Draw the entire bitmap scaled to a destination rect (bounds -> ds tRect).
68 FillRectFiltered(canvas, clipRect, imageSourceDstRectOnly); 72 sk_sp<SkImageFilter> imageSourceDstRectOnly(
73 SkImageSource::Make(fImage, bounds, dstRect, kHigh_SkFilterQuali ty));
74 fill_rect_filtered(canvas, clipRect, std::move(imageSourceDstRectOnl y));
69 canvas->translate(SkIntToScalar(100), 0); 75 canvas->translate(SkIntToScalar(100), 0);
70 } 76 }
71 } 77 }
72 78
73 private: 79 private:
74 sk_sp<SkImage> fImage; 80 sk_sp<SkImage> fImage;
75 typedef GM INHERITED; 81 typedef GM INHERITED;
76 }; 82 };
77 83
78 /////////////////////////////////////////////////////////////////////////////// 84 ///////////////////////////////////////////////////////////////////////////////
79 85
80 DEF_GM( return new ImageSourceGM; ) 86 DEF_GM( return new ImageSourceGM; )
OLDNEW
« no previous file with comments | « gm/imagefilterstransformed.cpp ('k') | gm/imagesource2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698