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

Side by Side Diff: gm/offsetimagefilter.cpp

Issue 1810813003: update callsites for Make image factories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: start to take advantage of sk_sp drawImage Created 4 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 | « gm/ninepatchstretch.cpp ('k') | gm/perspshaders.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 "sk_tool_utils.h" 8 #include "sk_tool_utils.h"
9 #include "SkImage.h" 9 #include "SkImage.h"
10 #include "SkImageSource.h" 10 #include "SkImageSource.h"
(...skipping 14 matching lines...) Expand all
25 protected: 25 protected:
26 SkString onShortName() override { 26 SkString onShortName() override {
27 return SkString("offsetimagefilter"); 27 return SkString("offsetimagefilter");
28 } 28 }
29 29
30 SkISize onISize() override { 30 SkISize onISize() override {
31 return SkISize::Make(WIDTH, HEIGHT); 31 return SkISize::Make(WIDTH, HEIGHT);
32 } 32 }
33 33
34 void onOnceBeforeDraw() override { 34 void onOnceBeforeDraw() override {
35 fBitmap.reset(SkImage::NewFromBitmap( 35 fBitmap = SkImage::MakeFromBitmap(
36 sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96, "e"))); 36 sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96, "e"));
37 37
38 fCheckerboard.reset(SkImage::NewFromBitmap( 38 fCheckerboard = SkImage::MakeFromBitmap(
39 sk_tool_utils::create_checkerboard_bitmap(80, 80, 39 sk_tool_utils::create_checkerboard_bitmap(80, 80,
40 sk_tool_utils::color_to_56 5(0xFFA0A0A0), 40 sk_tool_utils::color_to_56 5(0xFFA0A0A0),
41 sk_tool_utils::color_to_56 5(0xFF404040), 41 sk_tool_utils::color_to_56 5(0xFF404040),
42 8))); 42 8));
43 } 43 }
44 44
45 void onDraw(SkCanvas* canvas) override { 45 void onDraw(SkCanvas* canvas) override {
46 canvas->clear(SK_ColorBLACK); 46 canvas->clear(SK_ColorBLACK);
47 SkPaint paint; 47 SkPaint paint;
48 48
49 for (int i = 0; i < 4; i++) { 49 for (int i = 0; i < 4; i++) {
50 const SkImage* image = (i & 0x01) ? fCheckerboard : fBitmap; 50 const SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.ge t();
51 SkIRect cropRect = SkIRect::MakeXYWH(i * 12, 51 SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
52 i * 8, 52 i * 8,
53 image->width() - i * 8, 53 image->width() - i * 8,
54 image->height() - i * 12); 54 image->height() - i * 12);
55 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); 55 SkImageFilter::CropRect rect(SkRect::Make(cropRect));
56 SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image)); 56 SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image));
57 SkScalar dx = SkIntToScalar(i*5); 57 SkScalar dx = SkIntToScalar(i*5);
58 SkScalar dy = SkIntToScalar(i*10); 58 SkScalar dy = SkIntToScalar(i*10);
59 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(dx, d y, tileInput, 59 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(dx, d y, tileInput,
60 &rect )); 60 &rect ));
61 paint.setImageFilter(filter); 61 paint.setImageFilter(filter);
62 DrawClippedImage(canvas, image, paint, 1, cropRect); 62 DrawClippedImage(canvas, image, paint, 1, cropRect);
63 canvas->translate(SkIntToScalar(image->width() + MARGIN), 0); 63 canvas->translate(SkIntToScalar(image->width() + MARGIN), 0);
64 } 64 }
65 65
66 SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); 66 SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100);
67 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); 67 SkImageFilter::CropRect rect(SkRect::Make(cropRect));
68 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, nullptr, &rect)); 68 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, nullptr, &rect));
69 paint.setImageFilter(filter); 69 paint.setImageFilter(filter);
70 DrawClippedImage(canvas, fBitmap, paint, 2, cropRect); 70 DrawClippedImage(canvas, fBitmap.get(), paint, 2, cropRect);
71 } 71 }
72 private: 72 private:
73 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S kPaint& paint, 73 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S kPaint& paint,
74 SkScalar scale, const SkIRect& cropRect) { 74 SkScalar scale, const SkIRect& cropRect) {
75 SkRect clipRect = SkRect::MakeIWH(image->width(), image->height()); 75 SkRect clipRect = SkRect::MakeIWH(image->width(), image->height());
76 76
77 canvas->save(); 77 canvas->save();
78 canvas->clipRect(clipRect); 78 canvas->clipRect(clipRect);
79 canvas->scale(scale, scale); 79 canvas->scale(scale, scale);
80 canvas->drawImage(image, 0, 0, &paint); 80 canvas->drawImage(image, 0, 0, &paint);
81 canvas->restore(); 81 canvas->restore();
82 82
83 // Draw a boundary rect around the intersection of the clip rect and cro p rect. 83 // Draw a boundary rect around the intersection of the clip rect and cro p rect.
84 SkRect cropRectFloat; 84 SkRect cropRectFloat;
85 SkMatrix::MakeScale(scale, scale).mapRect(&cropRectFloat, SkRect::Make(c ropRect)); 85 SkMatrix::MakeScale(scale, scale).mapRect(&cropRectFloat, SkRect::Make(c ropRect));
86 if (clipRect.intersect(cropRectFloat)) { 86 if (clipRect.intersect(cropRectFloat)) {
87 SkPaint strokePaint; 87 SkPaint strokePaint;
88 strokePaint.setStyle(SkPaint::kStroke_Style); 88 strokePaint.setStyle(SkPaint::kStroke_Style);
89 strokePaint.setStrokeWidth(2); 89 strokePaint.setStrokeWidth(2);
90 strokePaint.setColor(SK_ColorRED); 90 strokePaint.setColor(SK_ColorRED);
91 canvas->drawRect(clipRect, strokePaint); 91 canvas->drawRect(clipRect, strokePaint);
92 } 92 }
93 } 93 }
94 94
95 SkAutoTUnref<SkImage> fBitmap, fCheckerboard; 95 sk_sp<SkImage> fBitmap, fCheckerboard;
96 96
97 typedef skiagm::GM INHERITED; 97 typedef skiagm::GM INHERITED;
98 }; 98 };
99 DEF_GM( return new OffsetImageFilterGM; ) 99 DEF_GM( return new OffsetImageFilterGM; )
100 100
101 ////////////////////////////////////////////////////////////////////////////// 101 //////////////////////////////////////////////////////////////////////////////
102 102
103 class SimpleOffsetImageFilterGM : public skiagm::GM { 103 class SimpleOffsetImageFilterGM : public skiagm::GM {
104 public: 104 public:
105 SimpleOffsetImageFilterGM() {} 105 SimpleOffsetImageFilterGM() {}
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 // crop==clip==dst 199 // crop==clip==dst
200 canvas->translate(100, 0); 200 canvas->translate(100, 0);
201 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2 ), &r2); 201 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2 ), &r2);
202 } 202 }
203 203
204 private: 204 private:
205 typedef skiagm::GM INHERITED; 205 typedef skiagm::GM INHERITED;
206 }; 206 };
207 DEF_GM( return new SimpleOffsetImageFilterGM; ) 207 DEF_GM( return new SimpleOffsetImageFilterGM; )
OLDNEW
« no previous file with comments | « gm/ninepatchstretch.cpp ('k') | gm/perspshaders.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698