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

Side by Side Diff: gm/tileimagefilter.cpp

Issue 1143083006: Revert of Fix dst bound reported by SkTileImageFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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/bigtileimagefilter.cpp ('k') | include/effects/SkTileImageFilter.h » ('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 "SkColorFilterImageFilter.h" 10 #include "SkColorFilterImageFilter.h"
11 #include "SkColorMatrixFilter.h" 11 #include "SkColorMatrixFilter.h"
12 #include "SkTileImageFilter.h" 12 #include "SkTileImageFilter.h"
13 #include "gm.h" 13 #include "gm.h"
14 14
15 #define WIDTH 400 15 #define WIDTH 400
16 #define HEIGHT 100 16 #define HEIGHT 100
17 #define MARGIN 12 17 #define MARGIN 12
18 18
19 static SkBitmap make_bitmap() {
20 SkBitmap bitmap;
21 bitmap.allocN32Pixels(50, 50);
22 SkCanvas canvas(bitmap);
23 canvas.clear(0xFF000000);
24 SkPaint paint;
25 paint.setAntiAlias(true);
26 sk_tool_utils::set_portable_typeface(&paint);
27 paint.setColor(0xD000D000);
28 paint.setTextSize(SkIntToScalar(50));
29 const char* str = "e";
30 canvas.drawText(str, strlen(str), SkIntToScalar(10), SkIntToScalar(45), pain t);
31 return bitmap;
32 }
33
34
35 namespace skiagm { 19 namespace skiagm {
36 20
37 class TileImageFilterGM : public GM { 21 class TileImageFilterGM : public GM {
38 public: 22 public:
39 TileImageFilterGM() { 23 TileImageFilterGM() : fInitialized(false) {
40 this->setBGColor(0xFF000000); 24 this->setBGColor(0xFF000000);
41 } 25 }
42 26
43 protected: 27 protected:
44 SkString onShortName() override { 28 virtual SkString onShortName() {
45 return SkString("tileimagefilter"); 29 return SkString("tileimagefilter");
46 } 30 }
47 31
48 SkISize onISize() override{ 32 void make_bitmap() {
33 fBitmap.allocN32Pixels(50, 50);
34 SkCanvas canvas(fBitmap);
35 canvas.clear(0xFF000000);
36 SkPaint paint;
37 paint.setAntiAlias(true);
38 sk_tool_utils::set_portable_typeface(&paint);
39 paint.setColor(0xD000D000);
40 paint.setTextSize(SkIntToScalar(50));
41 const char* str = "e";
42 canvas.drawText(str, strlen(str), SkIntToScalar(10), SkIntToScalar(45), paint);
43 }
44
45 virtual SkISize onISize() {
49 return SkISize::Make(WIDTH, HEIGHT); 46 return SkISize::Make(WIDTH, HEIGHT);
50 } 47 }
51 48
52 void onOnceBeforeDraw() override { 49 virtual void onDraw(SkCanvas* canvas) {
53 fBitmap = make_bitmap(); 50 if (!fInitialized) {
51 make_bitmap();
54 52
55 fCheckerboard.allocN32Pixels(80, 80); 53 fCheckerboard.allocN32Pixels(80, 80);
56 SkCanvas checkerboardCanvas(fCheckerboard); 54 SkCanvas checkerboardCanvas(fCheckerboard);
57 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF40 4040, 8); 55 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0x FF404040, 8);
58 }
59 56
60 void onDraw(SkCanvas* canvas) override { 57 fInitialized = true;
58 }
61 canvas->clear(SK_ColorBLACK); 59 canvas->clear(SK_ColorBLACK);
62 60
63 int x = 0, y = 0; 61 int x = 0, y = 0;
64 for (size_t i = 0; i < 4; i++) { 62 for (size_t i = 0; i < 4; i++) {
65 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; 63 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
66 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4), 64 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4),
67 SkIntToScalar(bitmap->height()/4), 65 SkIntToScalar(bitmap->height()/4),
68 SkIntToScalar(bitmap->width()/(i+1 )), 66 SkIntToScalar(bitmap->width()/(i+1 )),
69 SkIntToScalar(bitmap->height()/(i+ 1))); 67 SkIntToScalar(bitmap->height()/(i+ 1)));
70 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8), 68 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 paint.setImageFilter(cfif); 102 paint.setImageFilter(cfif);
105 canvas->save(); 103 canvas->save();
106 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 104 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
107 canvas->clipRect(dstRect); 105 canvas->clipRect(dstRect);
108 canvas->saveLayer(&dstRect, &paint); 106 canvas->saveLayer(&dstRect, &paint);
109 canvas->drawBitmap(fBitmap, 0, 0); 107 canvas->drawBitmap(fBitmap, 0, 0);
110 canvas->restore(); 108 canvas->restore();
111 canvas->restore(); 109 canvas->restore();
112 } 110 }
113 private: 111 private:
114 SkBitmap fBitmap;
115 SkBitmap fCheckerboard;
116
117 typedef GM INHERITED; 112 typedef GM INHERITED;
113 SkBitmap fBitmap, fCheckerboard;
114 bool fInitialized;
118 }; 115 };
119 116
120 ////////////////////////////////////////////////////////////////////////////// 117 //////////////////////////////////////////////////////////////////////////////
121 118
122 DEF_GM( return SkNEW(TileImageFilterGM); ) 119 static GM* MyFactory(void*) { return new TileImageFilterGM; }
120 static GMRegistry reg(MyFactory);
123 121
124 } 122 }
OLDNEW
« no previous file with comments | « gm/bigtileimagefilter.cpp ('k') | include/effects/SkTileImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698