OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 114 static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
115 SkPaint paint; | 115 SkPaint paint; |
116 paint.setImageFilter(imf); | 116 paint.setImageFilter(imf); |
117 | 117 |
118 SkIRect bounds; | 118 SkIRect bounds; |
119 r.roundOut(&bounds); | 119 r.roundOut(&bounds); |
120 | 120 |
121 SkBitmap bm; | 121 SkBitmap bm; |
122 bm.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), bounds.height()); | 122 bm.allocN32Pixels(bounds.width(), bounds.height()); |
123 bm.allocPixels(); | |
124 bm.eraseColor(SK_ColorTRANSPARENT); | 123 bm.eraseColor(SK_ColorTRANSPARENT); |
125 SkCanvas c(bm); | 124 SkCanvas c(bm); |
126 draw_path(&c, r, NULL); | 125 draw_path(&c, r, NULL); |
127 | 126 |
128 canvas->drawBitmap(bm, 0, 0, &paint); | 127 canvas->drawBitmap(bm, 0, 0, &paint); |
129 } | 128 } |
130 | 129 |
131 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 130 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
132 SkPaint paint; | 131 SkPaint paint; |
133 paint.setImageFilter(imf); | 132 paint.setImageFilter(imf); |
134 | 133 |
135 SkIRect bounds; | 134 SkIRect bounds; |
136 r.roundOut(&bounds); | 135 r.roundOut(&bounds); |
137 | 136 |
138 SkBitmap bm; | 137 SkBitmap bm; |
139 bm.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), bounds.height()); | 138 bm.allocN32Pixels(bounds.width(), bounds.height()); |
140 bm.allocPixels(); | |
141 bm.eraseColor(SK_ColorTRANSPARENT); | 139 bm.eraseColor(SK_ColorTRANSPARENT); |
142 SkCanvas c(bm); | 140 SkCanvas c(bm); |
143 draw_path(&c, r, NULL); | 141 draw_path(&c, r, NULL); |
144 | 142 |
145 SkPoint loc = { r.fLeft, r.fTop }; | 143 SkPoint loc = { r.fLeft, r.fTop }; |
146 canvas->getTotalMatrix().mapPoints(&loc, 1); | 144 canvas->getTotalMatrix().mapPoints(&loc, 1); |
147 canvas->drawSprite(bm, | 145 canvas->drawSprite(bm, |
148 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), | 146 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), |
149 &paint); | 147 &paint); |
150 } | 148 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 220 } |
223 | 221 |
224 private: | 222 private: |
225 typedef GM INHERITED; | 223 typedef GM INHERITED; |
226 }; | 224 }; |
227 | 225 |
228 /////////////////////////////////////////////////////////////////////////////// | 226 /////////////////////////////////////////////////////////////////////////////// |
229 | 227 |
230 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; } | 228 static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; } |
231 static skiagm::GMRegistry reg(MyFactory); | 229 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |