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

Side by Side Diff: gm/bigtileimagefilter.cpp

Issue 1152553006: Fix dst bound reported by SkTileImageFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix line wraps 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 | « no previous file | 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 2015 Google Inc. 2 * Copyright 2015 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 "SkBitmapSource.h" 8 #include "SkBitmapSource.h"
9 #include "SkTileImageFilter.h" 9 #include "SkTileImageFilter.h"
10 #include "gm.h" 10 #include "gm.h"
11 11
12 static void create_circle_texture(SkBitmap* bm, SkColor color) {
13 SkCanvas canvas(*bm);
14 canvas.clear(0xFF000000);
15
16 SkPaint paint;
17 paint.setColor(color);
18 paint.setStrokeWidth(3);
19 paint.setStyle(SkPaint::kStroke_Style);
20
21 canvas.drawCircle(SkScalarHalf(bm->width()), SkScalarHalf(bm->height()),
22 SkScalarHalf(bm->width()), paint);
23 }
24
12 namespace skiagm { 25 namespace skiagm {
13 26
14 class BigTileImageFilterGM : public GM { 27 class BigTileImageFilterGM : public GM {
15 public: 28 public:
16 BigTileImageFilterGM() { 29 BigTileImageFilterGM() {
17 this->setBGColor(0xFF000000); 30 this->setBGColor(0xFF000000);
18 } 31 }
19 32
20 protected: 33 protected:
21 34
22 SkString onShortName() override { 35 SkString onShortName() override {
23 return SkString("bigtileimagefilter"); 36 return SkString("bigtileimagefilter");
24 } 37 }
25 38
26 SkISize onISize() override{ 39 SkISize onISize() override{
27 return SkISize::Make(kWidth, kHeight); 40 return SkISize::Make(kWidth, kHeight);
28 } 41 }
29 42
30 void onOnceBeforeDraw() override { 43 void onOnceBeforeDraw() override {
31 fBitmap.allocN32Pixels(kBitmapSize, kBitmapSize); 44 fRedBitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
45 create_circle_texture(&fRedBitmap, SK_ColorRED);
32 46
33 SkCanvas canvas(fBitmap); 47 fGreenBitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
34 canvas.clear(0xFF000000); 48 create_circle_texture(&fGreenBitmap, SK_ColorGREEN);
35
36 SkPaint paint;
37 paint.setColor(SK_ColorRED);
38 paint.setStrokeWidth(3);
39 paint.setStyle(SkPaint::kStroke_Style);
40
41 canvas.drawCircle(SkScalarHalf(kBitmapSize), SkScalarHalf(kBitmapSize),
42 SkScalarHalf(kBitmapSize), paint);
43 } 49 }
44 50
45 void onDraw(SkCanvas* canvas) override { 51 void onDraw(SkCanvas* canvas) override {
46 canvas->clear(SK_ColorBLACK); 52 canvas->clear(SK_ColorBLACK);
47 53
48 SkPaint p; 54 {
55 SkPaint p;
49 56
50 SkAutoTUnref<SkBitmapSource> bms(SkBitmapSource::Create(fBitmap)); 57 SkRect bound = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(k Height));
51 SkAutoTUnref<SkTileImageFilter> tif(SkTileImageFilter::Create( 58 SkAutoTUnref<SkBitmapSource> bms(SkBitmapSource::Create(fRedBitmap)) ;
59 SkAutoTUnref<SkTileImageFilter> tif(SkTileImageFilter::Create(
52 SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc alar(kBitmapSize)), 60 SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc alar(kBitmapSize)),
53 SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar( kHeight)), 61 SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar( kHeight)),
54 bms)); 62 bms));
55 p.setImageFilter(tif); 63 p.setImageFilter(tif);
56 64
57 SkRect bound = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeig ht)); 65 canvas->saveLayer(&bound, &p);
58 canvas->saveLayer(&bound, &p); 66 canvas->restore();
59 canvas->restore(); 67 }
68
69 {
70 SkPaint p2;
71
72 SkRect bound2 = SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc alar(kBitmapSize));
73
74 SkAutoTUnref<SkTileImageFilter> tif2(SkTileImageFilter::Create(
75 SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc alar(kBitmapSize)),
76 SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc alar(kBitmapSize)),
77 NULL));
78 p2.setImageFilter(tif2);
79
80 canvas->translate(320, 320);
81 canvas->saveLayer(&bound2, &p2);
82 canvas->setMatrix(SkMatrix::I());
83
84 SkRect bound3 = SkRect::MakeXYWH(320, 320,
85 SkIntToScalar(kBitmapSize),
86 SkIntToScalar(kBitmapSize));
87 canvas->drawBitmapRectToRect(fGreenBitmap, &bound2, bound3);
88 canvas->restore();
89 }
60 } 90 }
61 91
62 private: 92 private:
63 static const int kWidth = 512; 93 static const int kWidth = 512;
64 static const int kHeight = 512; 94 static const int kHeight = 512;
65 static const int kBitmapSize = 64; 95 static const int kBitmapSize = 64;
66 96
67 SkBitmap fBitmap; 97 SkBitmap fRedBitmap;
98 SkBitmap fGreenBitmap;
68 99
69 typedef GM INHERITED; 100 typedef GM INHERITED;
70 }; 101 };
71 102
72 ////////////////////////////////////////////////////////////////////////////// 103 //////////////////////////////////////////////////////////////////////////////
73 104
74 DEF_GM( return SkNEW(BigTileImageFilterGM); ) 105 DEF_GM( return SkNEW(BigTileImageFilterGM); )
75 106
76 } 107 }
OLDNEW
« no previous file with comments | « no previous file | include/effects/SkTileImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698