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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 canvas->restore(); | 53 canvas->restore(); |
54 } | 54 } |
55 | 55 |
56 static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 56 static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
57 SkPaint paint; | 57 SkPaint paint; |
58 | 58 |
59 SkIRect bounds; | 59 SkIRect bounds; |
60 r.roundOut(&bounds); | 60 r.roundOut(&bounds); |
61 | 61 |
62 SkBitmap bm; | 62 SkBitmap bm; |
63 bm.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), bounds.height()); | 63 bm.allocN32Pixels(bounds.width(), bounds.height()); |
64 bm.allocPixels(); | |
65 bm.eraseColor(SK_ColorTRANSPARENT); | 64 bm.eraseColor(SK_ColorTRANSPARENT); |
66 SkCanvas c(bm); | 65 SkCanvas c(bm); |
67 draw_path(&c, r, NULL); | 66 draw_path(&c, r, NULL); |
68 | 67 |
69 paint.setImageFilter(imf); | 68 paint.setImageFilter(imf); |
70 canvas->save(); | 69 canvas->save(); |
71 canvas->clipRect(r); | 70 canvas->clipRect(r); |
72 canvas->drawBitmap(bm, 0, 0, &paint); | 71 canvas->drawBitmap(bm, 0, 0, &paint); |
73 canvas->restore(); | 72 canvas->restore(); |
74 } | 73 } |
75 | 74 |
76 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 75 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
77 SkPaint paint; | 76 SkPaint paint; |
78 | 77 |
79 SkIRect bounds; | 78 SkIRect bounds; |
80 r.roundOut(&bounds); | 79 r.roundOut(&bounds); |
81 | 80 |
82 SkBitmap bm; | 81 SkBitmap bm; |
83 bm.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), bounds.height()); | 82 bm.allocN32Pixels(bounds.width(), bounds.height()); |
84 bm.allocPixels(); | |
85 bm.eraseColor(SK_ColorRED); | 83 bm.eraseColor(SK_ColorRED); |
86 SkCanvas c(bm); | 84 SkCanvas c(bm); |
87 | 85 |
88 SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44); | 86 SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44); |
89 paint.setColor(SK_ColorGREEN); | 87 paint.setColor(SK_ColorGREEN); |
90 c.drawRect(SkRect::Make(cropRect), paint); | 88 c.drawRect(SkRect::Make(cropRect), paint); |
91 | 89 |
92 paint.setImageFilter(imf); | 90 paint.setImageFilter(imf); |
93 SkPoint loc = { r.fLeft, r.fTop }; | 91 SkPoint loc = { r.fLeft, r.fTop }; |
94 canvas->getTotalMatrix().mapPoints(&loc, 1); | 92 canvas->getTotalMatrix().mapPoints(&loc, 1); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 173 } |
176 | 174 |
177 private: | 175 private: |
178 typedef GM INHERITED; | 176 typedef GM INHERITED; |
179 }; | 177 }; |
180 | 178 |
181 /////////////////////////////////////////////////////////////////////////////// | 179 /////////////////////////////////////////////////////////////////////////////// |
182 | 180 |
183 static skiagm::GM* MyFactory(void*) { return new ImageFiltersCroppedGM; } | 181 static skiagm::GM* MyFactory(void*) { return new ImageFiltersCroppedGM; } |
184 static skiagm::GMRegistry reg(MyFactory); | 182 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |