| 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 16 matching lines...) Expand all Loading... |
| 27 canvas->clipRect(r); | 27 canvas->clipRect(r); |
| 28 canvas->drawPaint(paint); | 28 canvas->drawPaint(paint); |
| 29 canvas->restore(); | 29 canvas->restore(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 32 static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
| 33 SkPaint paint; | 33 SkPaint paint; |
| 34 paint.setColor(SK_ColorMAGENTA); | 34 paint.setColor(SK_ColorMAGENTA); |
| 35 paint.setImageFilter(imf); | 35 paint.setImageFilter(imf); |
| 36 paint.setAntiAlias(true); | 36 paint.setAntiAlias(true); |
| 37 canvas->save(); | |
| 38 canvas->clipRect(r); | |
| 39 canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint); | 37 canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint); |
| 40 canvas->restore(); | |
| 41 } | 38 } |
| 42 | 39 |
| 43 static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 40 static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
| 44 SkPaint paint; | 41 SkPaint paint; |
| 45 paint.setImageFilter(imf); | 42 paint.setImageFilter(imf); |
| 46 paint.setColor(SK_ColorGREEN); | 43 paint.setColor(SK_ColorGREEN); |
| 47 paint.setAntiAlias(true); | 44 paint.setAntiAlias(true); |
| 48 sk_tool_utils::set_portable_typeface(&paint); | 45 sk_tool_utils::set_portable_typeface(&paint); |
| 49 paint.setTextSize(r.height()/2); | 46 paint.setTextSize(r.height()/2); |
| 50 paint.setTextAlign(SkPaint::kCenter_Align); | 47 paint.setTextAlign(SkPaint::kCenter_Align); |
| 51 canvas->save(); | |
| 52 canvas->clipRect(r); | |
| 53 canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint); | 48 canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint); |
| 54 canvas->restore(); | |
| 55 } | 49 } |
| 56 | 50 |
| 57 static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 51 static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
| 58 SkPaint paint; | 52 SkPaint paint; |
| 59 | 53 |
| 60 SkIRect bounds; | 54 SkIRect bounds; |
| 61 r.roundOut(&bounds); | 55 r.roundOut(&bounds); |
| 62 | 56 |
| 63 SkBitmap bm; | 57 SkBitmap bm; |
| 64 bm.allocN32Pixels(bounds.width(), bounds.height()); | 58 bm.allocN32Pixels(bounds.width(), bounds.height()); |
| 65 bm.eraseColor(SK_ColorTRANSPARENT); | 59 bm.eraseColor(SK_ColorTRANSPARENT); |
| 66 SkCanvas c(bm); | 60 SkCanvas c(bm); |
| 67 draw_path(&c, r, NULL); | 61 draw_path(&c, r, NULL); |
| 68 | 62 |
| 69 paint.setImageFilter(imf); | 63 paint.setImageFilter(imf); |
| 70 canvas->save(); | |
| 71 canvas->clipRect(r); | |
| 72 canvas->drawBitmap(bm, 0, 0, &paint); | 64 canvas->drawBitmap(bm, 0, 0, &paint); |
| 73 canvas->restore(); | |
| 74 } | 65 } |
| 75 | 66 |
| 76 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 67 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
| 77 SkPaint paint; | 68 SkPaint paint; |
| 78 | 69 |
| 79 SkIRect bounds; | 70 SkIRect bounds; |
| 80 r.roundOut(&bounds); | 71 r.roundOut(&bounds); |
| 81 | 72 |
| 82 SkBitmap bm; | 73 SkBitmap bm; |
| 83 bm.allocN32Pixels(bounds.width(), bounds.height()); | 74 bm.allocN32Pixels(bounds.width(), bounds.height()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 164 } |
| 174 | 165 |
| 175 private: | 166 private: |
| 176 typedef GM INHERITED; | 167 typedef GM INHERITED; |
| 177 }; | 168 }; |
| 178 | 169 |
| 179 /////////////////////////////////////////////////////////////////////////////// | 170 /////////////////////////////////////////////////////////////////////////////// |
| 180 | 171 |
| 181 static skiagm::GM* MyFactory(void*) { return new ImageFiltersCroppedGM; } | 172 static skiagm::GM* MyFactory(void*) { return new ImageFiltersCroppedGM; } |
| 182 static skiagm::GMRegistry reg(MyFactory); | 173 static skiagm::GMRegistry reg(MyFactory); |
| OLD | NEW |