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

Side by Side Diff: gm/tileimagefilter.cpp

Issue 24157005: Moving 4 SkImageFilter derived classes from blink to skia (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Added gm tests Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "SkTileImageFilter.h"
10 #include "SkBitmapSource.h"
11
12 #define WIDTH 400
13 #define HEIGHT 100
14 #define MARGIN 12
15
16 namespace skiagm {
17
18 class TileImageFilterGM : public GM {
19 public:
20 TileImageFilterGM() : fInitialized(false) {
21 this->setBGColor(0xFF000000);
22 }
23
24 protected:
25 virtual SkString onShortName() {
26 return SkString("tileimagefilter");
27 }
28
29 void make_bitmap() {
30 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
31 fBitmap.allocPixels();
32 SkBitmapDevice device(fBitmap);
33 SkCanvas canvas(&device);
34 canvas.clear(0x00000000);
35 SkPaint paint;
36 paint.setAntiAlias(true);
37 paint.setColor(0xD000D000);
38 paint.setTextSize(SkIntToScalar(96));
39 const char* str = "e";
40 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint);
41 }
42
43 void make_checkerboard() {
44 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
45 fCheckerboard.allocPixels();
46 SkBitmapDevice device(fCheckerboard);
47 SkCanvas canvas(&device);
48 canvas.clear(0x00000000);
49 SkPaint darkPaint;
50 darkPaint.setColor(0xFF404040);
51 SkPaint lightPaint;
52 lightPaint.setColor(0xFFA0A0A0);
53 for (int y = 0; y < 80; y += 16) {
54 for (int x = 0; x < 80; x += 16) {
55 canvas.save();
56 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
57 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
58 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
59 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
60 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
61 canvas.restore();
62 }
63 }
64 }
65
66 virtual SkISize onISize() {
67 return make_isize(WIDTH, HEIGHT);
68 }
69
70 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai nt& paint,
71 SkScalar x, SkScalar y) {
72 canvas->save();
73 canvas->clipRect(SkRect::MakeXYWH(x, y,
74 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())));
75 canvas->drawBitmap(bitmap, x, y, &paint);
76 canvas->restore();
77 }
78
79 virtual void onDraw(SkCanvas* canvas) {
80 if (!fInitialized) {
81 make_bitmap();
82 make_checkerboard();
83 fInitialized = true;
84 }
85 canvas->clear(0x00000000);
86 SkPaint paint;
87
88 int x = 0, y = 0;
89 for (size_t i = 0; i < 4; i++) {
90 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
91 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4),
92 SkIntToScalar(bitmap->height()/4),
93 SkIntToScalar(bitmap->width()/(i+1 )),
94 SkIntToScalar(bitmap->height()/(i+ 1)));
95 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8),
96 SkIntToScalar(i * 4),
97 SkIntToScalar(bitmap->width() - i * 4),
98 SkIntToScalar(bitmap->height()) - i * 8);
99 SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*b itmap)));
100 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
101 SkTileImageFilter, (srcRect, dstRect, tileInput)));
102 paint.setImageFilter(filter);
103 drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToS calar(y));
104 x += bitmap->width() + MARGIN;
105 if (x + bitmap->width() > WIDTH) {
106 x = 0;
107 y += bitmap->height() + MARGIN;
108 }
109 }
110 }
111 private:
112 typedef GM INHERITED;
113 SkBitmap fBitmap, fCheckerboard;
114 bool fInitialized;
115 };
116
117 //////////////////////////////////////////////////////////////////////////////
118
119 static GM* MyFactory(void*) { return new TileImageFilterGM; }
120 static GMRegistry reg(MyFactory);
121
122 }
OLDNEW
« no previous file with comments | « gm/offsetimagefilter.cpp ('k') | gm/xfermodeimagefilter.cpp » ('j') | gm/xfermodeimagefilter.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698