OLD | NEW |
---|---|
(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 | |
10 #include "SkBitmapSource.h" | |
11 | |
robertphillips
2013/12/09 16:23:01
// This GM ...?
Stephen White
2013/12/09 17:04:25
Done.
| |
12 class BitmapSourceGM : public skiagm::GM { | |
13 public: | |
14 BitmapSourceGM() : fInitialized(false) { | |
15 } | |
16 | |
17 protected: | |
robertphillips
2013/12/09 16:23:01
override
Stephen White
2013/12/09 17:04:25
Done.
| |
18 virtual SkString onShortName() { | |
19 return SkString("bitmapsource"); | |
20 } | |
21 | |
robertphillips
2013/12/09 16:23:01
makeBitmap?
Stephen White
2013/12/09 17:04:25
Done.
| |
22 void make_bitmap() { | |
23 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | |
24 fBitmap.allocPixels(); | |
25 SkBitmapDevice device(fBitmap); | |
26 SkCanvas canvas(&device); | |
27 canvas.clear(0x00000000); | |
28 SkPaint paint; | |
29 paint.setAntiAlias(true); | |
30 paint.setColor(0xFFFFFFFF); | |
31 paint.setTextSize(SkIntToScalar(96)); | |
32 const char* str = "e"; | |
33 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint); | |
34 } | |
35 | |
robertphillips
2013/12/09 16:23:01
override
Stephen White
2013/12/09 17:04:25
Done.
| |
36 virtual SkISize onISize() { return SkISize::Make(500, 150); } | |
37 | |
robertphillips
2013/12/09 16:23:01
override
Stephen White
2013/12/09 17:04:25
Done.
| |
38 virtual void onDraw(SkCanvas* canvas) { | |
robertphillips
2013/12/09 16:23:01
maybe just do this in onOnceBeforeDraw?
Stephen White
2013/12/09 17:04:25
Done.
| |
39 if (!fInitialized) { | |
40 this->make_bitmap(); | |
41 fInitialized = true; | |
42 } | |
43 canvas->clear(0x00000000); | |
44 { | |
45 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); | |
46 SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60); | |
47 SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100); | |
48 SkRect bounds; | |
49 fBitmap.getBounds(&bounds); | |
50 SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap) ); | |
51 SkAutoTUnref<SkImageFilter> bitmapSourceSrcRect(new SkBitmapSource(f Bitmap, srcRect, srcRect)); | |
52 SkAutoTUnref<SkImageFilter> bitmapSourceSrcRectDstRect(new SkBitmapS ource(fBitmap, srcRect, dstRect)); | |
53 SkAutoTUnref<SkImageFilter> bitmapSourceDstRectOnly(new SkBitmapSour ce(fBitmap, bounds, dstRect)); | |
54 | |
robertphillips
2013/12/09 16:23:01
subroutine/loop?
Stephen White
2013/12/09 17:04:25
Done.
| |
55 SkPaint paint; | |
56 paint.setImageFilter(bitmapSource); | |
57 canvas->save(); | |
58 canvas->clipRect(clipRect); | |
59 canvas->drawPaint(paint); | |
60 canvas->restore(); | |
61 canvas->translate(SkIntToScalar(100), 0); | |
62 | |
63 paint.setImageFilter(bitmapSourceSrcRect); | |
64 canvas->save(); | |
65 canvas->clipRect(clipRect); | |
66 canvas->drawPaint(paint); | |
67 canvas->restore(); | |
68 canvas->translate(SkIntToScalar(100), 0); | |
69 | |
70 paint.setImageFilter(bitmapSourceSrcRectDstRect); | |
71 canvas->save(); | |
72 canvas->clipRect(clipRect); | |
73 canvas->drawPaint(paint); | |
74 canvas->restore(); | |
75 canvas->translate(SkIntToScalar(100), 0); | |
76 | |
77 paint.setImageFilter(bitmapSourceDstRectOnly); | |
78 canvas->save(); | |
79 canvas->clipRect(clipRect); | |
80 canvas->drawPaint(paint); | |
81 canvas->restore(); | |
82 canvas->translate(SkIntToScalar(100), 0); | |
83 } | |
84 } | |
85 | |
86 private: | |
robertphillips
2013/12/09 16:23:01
micro-nit: this is supposed to go last
Stephen White
2013/12/09 17:04:25
Done.
| |
87 typedef GM INHERITED; | |
88 SkBitmap fBitmap; | |
89 bool fInitialized; | |
90 }; | |
91 | |
92 /////////////////////////////////////////////////////////////////////////////// | |
93 | |
robertphillips
2013/12/09 16:23:01
DEF_GM
Stephen White
2013/12/09 17:04:25
Done.
| |
94 static skiagm::GM* MyFactory(void*) { return new BitmapSourceGM; } | |
95 static skiagm::GMRegistry reg(MyFactory); | |
OLD | NEW |