OLD | NEW |
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 "gm.h" | 8 #include "gm.h" |
9 #include "SkTileImageFilter.h" | 9 #include "SkTileImageFilter.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 for (size_t i = 0; i < 4; i++) { | 76 for (size_t i = 0; i < 4; i++) { |
77 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; | 77 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; |
78 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4), | 78 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4), |
79 SkIntToScalar(bitmap->height()/4), | 79 SkIntToScalar(bitmap->height()/4), |
80 SkIntToScalar(bitmap->width()/(i+1
)), | 80 SkIntToScalar(bitmap->width()/(i+1
)), |
81 SkIntToScalar(bitmap->height()/(i+
1))); | 81 SkIntToScalar(bitmap->height()/(i+
1))); |
82 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8), | 82 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8), |
83 SkIntToScalar(i * 4), | 83 SkIntToScalar(i * 4), |
84 SkIntToScalar(bitmap->width() - i
* 12), | 84 SkIntToScalar(bitmap->width() - i
* 12), |
85 SkIntToScalar(bitmap->height()) -
i * 12); | 85 SkIntToScalar(bitmap->height()) -
i * 12); |
86 SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*b
itmap))); | 86 SkAutoTUnref<SkImageFilter> tileInput(SkBitmapSource::Create(*bitmap
)); |
87 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( | 87 SkAutoTUnref<SkImageFilter> filter( |
88 SkTileImageFilter, (srcRect, dstRect, tileInput))); | 88 SkTileImageFilter::Create(srcRect, dstRect, tileInput)); |
89 canvas->save(); | 89 canvas->save(); |
90 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 90 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
91 paint.setImageFilter(filter); | 91 paint.setImageFilter(filter); |
92 canvas->drawBitmap(fBitmap, 0, 0, &paint); | 92 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
93 canvas->restore(); | 93 canvas->restore(); |
94 x += bitmap->width() + MARGIN; | 94 x += bitmap->width() + MARGIN; |
95 if (x + bitmap->width() > WIDTH) { | 95 if (x + bitmap->width() > WIDTH) { |
96 x = 0; | 96 x = 0; |
97 y += bitmap->height() + MARGIN; | 97 y += bitmap->height() + MARGIN; |
98 } | 98 } |
99 } | 99 } |
100 } | 100 } |
101 private: | 101 private: |
102 typedef GM INHERITED; | 102 typedef GM INHERITED; |
103 SkBitmap fBitmap, fCheckerboard; | 103 SkBitmap fBitmap, fCheckerboard; |
104 bool fInitialized; | 104 bool fInitialized; |
105 }; | 105 }; |
106 | 106 |
107 ////////////////////////////////////////////////////////////////////////////// | 107 ////////////////////////////////////////////////////////////////////////////// |
108 | 108 |
109 static GM* MyFactory(void*) { return new TileImageFilterGM; } | 109 static GM* MyFactory(void*) { return new TileImageFilterGM; } |
110 static GMRegistry reg(MyFactory); | 110 static GMRegistry reg(MyFactory); |
111 | 111 |
112 } | 112 } |
OLD | NEW |