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

Side by Side Diff: gm/tileimagefilter.cpp

Issue 1169713003: Add bigtileimagefilter GM & improvements to toString (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
19 namespace skiagm { 35 namespace skiagm {
20 36
21 class TileImageFilterGM : public GM { 37 class TileImageFilterGM : public GM {
22 public: 38 public:
23 TileImageFilterGM() : fInitialized(false) { 39 TileImageFilterGM() {
24 this->setBGColor(0xFF000000); 40 this->setBGColor(0xFF000000);
25 } 41 }
26 42
27 protected: 43 protected:
28 virtual SkString onShortName() { 44 SkString onShortName() override {
29 return SkString("tileimagefilter"); 45 return SkString("tileimagefilter");
30 } 46 }
31 47
32 void make_bitmap() { 48 SkISize onISize() override{
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() {
46 return SkISize::Make(WIDTH, HEIGHT); 49 return SkISize::Make(WIDTH, HEIGHT);
47 } 50 }
48 51
49 virtual void onDraw(SkCanvas* canvas) { 52 void onOnceBeforeDraw() override {
50 if (!fInitialized) { 53 fBitmap = make_bitmap();
51 make_bitmap();
52 54
53 fCheckerboard.allocN32Pixels(80, 80); 55 fCheckerboard.allocN32Pixels(80, 80);
54 SkCanvas checkerboardCanvas(fCheckerboard); 56 SkCanvas checkerboardCanvas(fCheckerboard);
55 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0x FF404040, 8); 57 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF40 4040, 8);
58 }
56 59
57 fInitialized = true; 60 void onDraw(SkCanvas* canvas) override {
58 }
59 canvas->clear(SK_ColorBLACK); 61 canvas->clear(SK_ColorBLACK);
60 62
61 int x = 0, y = 0; 63 int x = 0, y = 0;
62 for (size_t i = 0; i < 4; i++) { 64 for (size_t i = 0; i < 4; i++) {
63 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; 65 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
64 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4), 66 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4),
65 SkIntToScalar(bitmap->height()/4), 67 SkIntToScalar(bitmap->height()/4),
66 SkIntToScalar(bitmap->width()/(i+1 )), 68 SkIntToScalar(bitmap->width()/(i+1 )),
67 SkIntToScalar(bitmap->height()/(i+ 1))); 69 SkIntToScalar(bitmap->height()/(i+ 1)));
68 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8), 70 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 paint.setImageFilter(cfif); 104 paint.setImageFilter(cfif);
103 canvas->save(); 105 canvas->save();
104 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 106 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
105 canvas->clipRect(dstRect); 107 canvas->clipRect(dstRect);
106 canvas->saveLayer(&dstRect, &paint); 108 canvas->saveLayer(&dstRect, &paint);
107 canvas->drawBitmap(fBitmap, 0, 0); 109 canvas->drawBitmap(fBitmap, 0, 0);
108 canvas->restore(); 110 canvas->restore();
109 canvas->restore(); 111 canvas->restore();
110 } 112 }
111 private: 113 private:
114 SkBitmap fBitmap;
115 SkBitmap fCheckerboard;
116
112 typedef GM INHERITED; 117 typedef GM INHERITED;
113 SkBitmap fBitmap, fCheckerboard;
114 bool fInitialized;
115 }; 118 };
116 119
117 ////////////////////////////////////////////////////////////////////////////// 120 //////////////////////////////////////////////////////////////////////////////
118 121
119 static GM* MyFactory(void*) { return new TileImageFilterGM; } 122 DEF_GM( return SkNEW(TileImageFilterGM); )
120 static GMRegistry reg(MyFactory);
121 123
122 } 124 }
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