OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 | 10 |
11 static void test_nulldev(SkCanvas* canvas) { | |
bsalomon
2014/03/14 14:03:45
should this be in a unit test?
| |
12 SkBitmap bm; | |
13 bm.setConfig(SkBitmap::kARGB_8888_Config, 30, 30); | |
14 // notice: no pixels mom! be sure we don't crash | |
15 // https://code.google.com/p/chromium/issues/detail?id=352616 | |
16 SkCanvas c(bm); | |
17 | |
18 SkBitmap src; | |
19 src.allocN32Pixels(10, 10); | |
20 src.eraseColor(SK_ColorRED); | |
21 | |
22 // ensure we don't crash | |
23 c.writePixels(src, 0, 0); | |
24 } | |
25 | |
11 static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint) { | 26 static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint) { |
12 SkPaint p(paint); | 27 SkPaint p(paint); |
13 SkPoint loc = { 20, 450 }; | 28 SkPoint loc = { 20, 450 }; |
14 | 29 |
15 canvas->drawText("P", 1, loc.fX, loc.fY - 225, p); | 30 canvas->drawText("P", 1, loc.fX, loc.fY - 225, p); |
16 canvas->drawPosText("P", 1, &loc, p); | 31 canvas->drawPosText("P", 1, &loc, p); |
17 | 32 |
18 p.setColor(SK_ColorRED); | 33 p.setColor(SK_ColorRED); |
19 p.setStyle(SkPaint::kStroke_Style); | 34 p.setStyle(SkPaint::kStroke_Style); |
20 p.setStrokeWidth(10); | 35 p.setStrokeWidth(10); |
(...skipping 16 matching lines...) Expand all Loading... | |
37 protected: | 52 protected: |
38 virtual SkString onShortName() SK_OVERRIDE { | 53 virtual SkString onShortName() SK_OVERRIDE { |
39 return SkString("stroketext"); | 54 return SkString("stroketext"); |
40 } | 55 } |
41 | 56 |
42 virtual SkISize onISize() SK_OVERRIDE { | 57 virtual SkISize onISize() SK_OVERRIDE { |
43 return SkISize::Make(640, 480); | 58 return SkISize::Make(640, 480); |
44 } | 59 } |
45 | 60 |
46 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 61 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
62 if (true) { test_nulldev(canvas); } | |
47 SkPaint paint; | 63 SkPaint paint; |
48 paint.setAntiAlias(true); | 64 paint.setAntiAlias(true); |
49 | 65 |
50 paint.setTextSize(kBelowThreshold_TextSize); | 66 paint.setTextSize(kBelowThreshold_TextSize); |
51 draw_text_stroked(canvas, paint); | 67 draw_text_stroked(canvas, paint); |
52 | 68 |
53 canvas->translate(200, 0); | 69 canvas->translate(200, 0); |
54 paint.setTextSize(kAboveThreshold_TextSize); | 70 paint.setTextSize(kAboveThreshold_TextSize); |
55 draw_text_stroked(canvas, paint); | 71 draw_text_stroked(canvas, paint); |
56 } | 72 } |
57 | 73 |
58 private: | 74 private: |
59 typedef skiagm::GM INHERITED; | 75 typedef skiagm::GM INHERITED; |
60 }; | 76 }; |
61 | 77 |
62 DEF_GM( return SkNEW(StrokeTextGM); ) | 78 DEF_GM( return SkNEW(StrokeTextGM); ) |
OLD | NEW |