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

Side by Side Diff: gm/offsetimagefilter.cpp

Issue 1320673011: Minor code cleanup (left over from prior CL) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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/matrixconvolution.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 "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
10 #include "SkOffsetImageFilter.h" 10 #include "SkOffsetImageFilter.h"
11 #include "gm.h" 11 #include "gm.h"
12 12
13 #define WIDTH 600 13 #define WIDTH 600
14 #define HEIGHT 100 14 #define HEIGHT 100
15 #define MARGIN 12 15 #define MARGIN 12
16 16
17 class OffsetImageFilterGM : public skiagm::GM { 17 class OffsetImageFilterGM : public skiagm::GM {
18 public: 18 public:
19 OffsetImageFilterGM() { 19 OffsetImageFilterGM() {
20 this->setBGColor(0xFF000000); 20 this->setBGColor(0xFF000000);
21 } 21 }
22 22
23 protected: 23 protected:
24 SkString onShortName() override { 24 SkString onShortName() override {
25 return SkString("offsetimagefilter"); 25 return SkString("offsetimagefilter");
26 } 26 }
27 27
28 void make_bitmap() {
29 fBitmap.allocN32Pixels(80, 80);
30 SkCanvas canvas(fBitmap);
31 canvas.clear(0);
32 SkPaint paint;
33 paint.setAntiAlias(true);
34 sk_tool_utils::set_portable_typeface(&paint);
35 paint.setColor(sk_tool_utils::color_to_565(0xD000D000));
36 paint.setTextSize(96);
37 canvas.drawText("e", 1, 15, 65, paint);
38 }
39
40 SkISize onISize() override { 28 SkISize onISize() override {
41 return SkISize::Make(WIDTH, HEIGHT); 29 return SkISize::Make(WIDTH, HEIGHT);
42 } 30 }
43 31
44 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai nt& paint, 32 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai nt& paint,
45 SkScalar scale, const SkIRect& cropRect) { 33 SkScalar scale, const SkIRect& cropRect) {
46 SkRect clipRect = SkRect::MakeIWH(bitmap.width(), bitmap.height()); 34 SkRect clipRect = SkRect::MakeIWH(bitmap.width(), bitmap.height());
47 35
48 canvas->save(); 36 canvas->save();
49 canvas->clipRect(clipRect); 37 canvas->clipRect(clipRect);
50 canvas->scale(scale, scale); 38 canvas->scale(scale, scale);
51 canvas->drawBitmap(bitmap, 0, 0, &paint); 39 canvas->drawBitmap(bitmap, 0, 0, &paint);
52 canvas->restore(); 40 canvas->restore();
53 41
54 // Draw a boundary rect around the intersection of the clip rect and cro p rect. 42 // Draw a boundary rect around the intersection of the clip rect and cro p rect.
55 SkRect cropRectFloat; 43 SkRect cropRectFloat;
56 SkMatrix::MakeScale(scale, scale).mapRect(&cropRectFloat, SkRect::Make(c ropRect)); 44 SkMatrix::MakeScale(scale, scale).mapRect(&cropRectFloat, SkRect::Make(c ropRect));
57 if (clipRect.intersect(cropRectFloat)) { 45 if (clipRect.intersect(cropRectFloat)) {
58 SkPaint strokePaint; 46 SkPaint strokePaint;
59 strokePaint.setStyle(SkPaint::kStroke_Style); 47 strokePaint.setStyle(SkPaint::kStroke_Style);
60 strokePaint.setStrokeWidth(2); 48 strokePaint.setStrokeWidth(2);
61 strokePaint.setColor(SK_ColorRED); 49 strokePaint.setColor(SK_ColorRED);
62 canvas->drawRect(clipRect, strokePaint); 50 canvas->drawRect(clipRect, strokePaint);
63 } 51 }
64 } 52 }
65 53
66 void onOnceBeforeDraw() override { 54 void onOnceBeforeDraw() override {
67 make_bitmap(); 55 fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65 , 96, "e");
68 56
69 fCheckerboard.allocN32Pixels(80, 80); 57 fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(
70 SkCanvas checkerboardCanvas(fCheckerboard); 58 80, 80,
71 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 59 sk_tool_utils::color_to_ 565(0xFFA0A0A0),
72 sk_tool_utils::color_to_565(0xFFA0A0A0), 60 sk_tool_utils::color_to_ 565(0xFF404040),
73 sk_tool_utils::color_to_565(0xFF404040), 8); 61 8);
74 } 62 }
75 63
76 void onDraw(SkCanvas* canvas) override { 64 void onDraw(SkCanvas* canvas) override {
77 canvas->clear(SK_ColorBLACK); 65 canvas->clear(SK_ColorBLACK);
78 SkPaint paint; 66 SkPaint paint;
79 67
80 for (int i = 0; i < 4; i++) { 68 for (int i = 0; i < 4; i++) {
81 const SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; 69 const SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
82 SkIRect cropRect = SkIRect::MakeXYWH(i * 12, 70 SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
83 i * 8, 71 i * 8,
(...skipping 10 matching lines...) Expand all
94 canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0); 82 canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0);
95 } 83 }
96 84
97 SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); 85 SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100);
98 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); 86 SkImageFilter::CropRect rect(SkRect::Make(cropRect));
99 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, nullptr, &rect)); 87 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, nullptr, &rect));
100 paint.setImageFilter(filter); 88 paint.setImageFilter(filter);
101 drawClippedBitmap(canvas, fBitmap, paint, 2, cropRect); 89 drawClippedBitmap(canvas, fBitmap, paint, 2, cropRect);
102 } 90 }
103 private: 91 private:
92 SkBitmap fBitmap, fCheckerboard;
93
104 typedef skiagm::GM INHERITED; 94 typedef skiagm::GM INHERITED;
105 SkBitmap fBitmap, fCheckerboard;
106 }; 95 };
107 DEF_GM( return new OffsetImageFilterGM; ) 96 DEF_GM( return new OffsetImageFilterGM; )
108 97
109 ////////////////////////////////////////////////////////////////////////////// 98 //////////////////////////////////////////////////////////////////////////////
110 99
111 class SimpleOffsetImageFilterGM : public skiagm::GM { 100 class SimpleOffsetImageFilterGM : public skiagm::GM {
112 public: 101 public:
113 SimpleOffsetImageFilterGM() {} 102 SimpleOffsetImageFilterGM() {}
114 103
115 protected: 104 protected:
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 195
207 // crop==clip==dst 196 // crop==clip==dst
208 canvas->translate(100, 0); 197 canvas->translate(100, 0);
209 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2 ), &r2); 198 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2 ), &r2);
210 } 199 }
211 200
212 private: 201 private:
213 typedef skiagm::GM INHERITED; 202 typedef skiagm::GM INHERITED;
214 }; 203 };
215 DEF_GM( return new SimpleOffsetImageFilterGM; ) 204 DEF_GM( return new SimpleOffsetImageFilterGM; )
OLDNEW
« no previous file with comments | « gm/matrixconvolution.cpp ('k') | gm/perspshaders.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698