| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 9 |
| 10 #include "SkShader.h" | 10 #include "SkShader.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 static const int kLabelOffsetY = kLabelTextSize + kLabelPad; | 28 static const int kLabelOffsetY = kLabelTextSize + kLabelPad; |
| 29 | 29 |
| 30 SkISize onISize() override { | 30 SkISize onISize() override { |
| 31 return SkISize::Make((kSubPixelSteps + 1) * kTrans + kLabelOffsetX + kLa
belPad, | 31 return SkISize::Make((kSubPixelSteps + 1) * kTrans + kLabelOffsetX + kLa
belPad, |
| 32 (kSubPixelSteps + 1) * kTrans + kLabelOffsetY + kLa
belPad); | 32 (kSubPixelSteps + 1) * kTrans + kLabelOffsetY + kLa
belPad); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void onDraw(SkCanvas* canvas) override { | 35 void onDraw(SkCanvas* canvas) override { |
| 36 SkPaint bgPaint; | 36 SkPaint bgPaint; |
| 37 bgPaint.setShader( | 37 bgPaint.setShader( |
| 38 sk_tool_utils::create_checkerboard_shader(0xFFAAAAAA, 0xFF777777, 1)
)->unref(); | 38 sk_tool_utils::create_checkerboard_shader( |
| 39 sk_tool_utils::color_to_565(0xFFAAAAAA), |
| 40 sk_tool_utils::color_to_565(0xFF777777), 1))->unref(); |
| 39 canvas->drawPaint(bgPaint); | 41 canvas->drawPaint(bgPaint); |
| 40 | 42 |
| 41 SkString offset; | 43 SkString offset; |
| 42 SkPaint labelPaint; | 44 SkPaint labelPaint; |
| 43 labelPaint.setAntiAlias(true); | 45 labelPaint.setAntiAlias(true); |
| 44 labelPaint.setColor(SK_ColorWHITE); | 46 labelPaint.setColor(SK_ColorWHITE); |
| 45 labelPaint.setTextSize(SkIntToScalar(kLabelTextSize)); | 47 labelPaint.setTextSize(SkIntToScalar(kLabelTextSize)); |
| 48 sk_tool_utils::set_portable_typeface(&labelPaint); |
| 46 SkPaint linePaint; | 49 SkPaint linePaint; |
| 47 linePaint.setColor(SK_ColorWHITE); | 50 linePaint.setColor(SK_ColorWHITE); |
| 48 | 51 |
| 49 // Drawing labels is useful for debugging, but bad for baselining (x-pla
tform txt diffs). | 52 // Draw row labels |
| 50 if (false) { | 53 canvas->save(); |
| 51 // Draw row labels | 54 canvas->translate(0, SkIntToScalar(kLabelOffsetY)); |
| 52 canvas->save(); | 55 for (int i = 0; i <= kSubPixelSteps; ++i) { |
| 53 canvas->translate(0, SkIntToScalar(kLabelOffsetY)); | 56 offset.printf("%d", i); |
| 54 for (int i = 0; i <= kSubPixelSteps; ++i) { | 57 canvas->drawText(offset.c_str(), offset.size(), |
| 55 offset.printf("%d", i); | 58 0, i * kTrans + labelPaint.getTextSize(), |
| 56 canvas->drawText(offset.c_str(), offset.size(), | 59 labelPaint); |
| 57 0, i * kTrans + labelPaint.getTextSize(), | 60 } |
| 58 labelPaint); | 61 canvas->restore(); |
| 59 } | |
| 60 canvas->restore(); | |
| 61 | 62 |
| 62 // Draw col labels | 63 // Draw col labels |
| 63 canvas->save(); | 64 canvas->save(); |
| 64 canvas->translate(SkIntToScalar(kLabelOffsetX), 0); | 65 canvas->translate(SkIntToScalar(kLabelOffsetX), 0); |
| 65 for (int i = 0; i <= kSubPixelSteps; ++i) { | 66 for (int i = 0; i <= kSubPixelSteps; ++i) { |
| 66 offset.printf("%d", i); | 67 offset.printf("%d", i); |
| 67 canvas->drawText(offset.c_str(), offset.size(), | 68 canvas->drawText(offset.c_str(), offset.size(), |
| 68 i * SkIntToScalar(kTrans), labelPaint.getTe
xtSize(), | 69 i * SkIntToScalar(kTrans), labelPaint.getTex
tSize(), |
| 69 labelPaint); | 70 labelPaint); |
| 70 } | 71 } |
| 71 canvas->restore(); | 72 canvas->restore(); |
| 72 } | |
| 73 | 73 |
| 74 canvas->translate(SkIntToScalar(kLabelOffsetX), SkIntToScalar(kLabelOffs
etY)); | 74 canvas->translate(SkIntToScalar(kLabelOffsetX), SkIntToScalar(kLabelOffs
etY)); |
| 75 | 75 |
| 76 // Draw test case grid lines (Draw them all at pixel centers to hopefull
y avoid any | 76 // Draw test case grid lines (Draw them all at pixel centers to hopefull
y avoid any |
| 77 // snapping issues). | 77 // snapping issues). |
| 78 for (int i = 0; i <= kSubPixelSteps + 1; ++i) { | 78 for (int i = 0; i <= kSubPixelSteps + 1; ++i) { |
| 79 canvas->drawLine(0.5f, | 79 canvas->drawLine(0.5f, |
| 80 i * SkIntToScalar(kTrans) + 0.5f, | 80 i * SkIntToScalar(kTrans) + 0.5f, |
| 81 SkIntToScalar(kTrans) * (kSubPixelSteps + 1) + 0.5f
, | 81 SkIntToScalar(kTrans) * (kSubPixelSteps + 1) + 0.5f
, |
| 82 i * SkIntToScalar(kTrans) + 0.5f, | 82 i * SkIntToScalar(kTrans) + 0.5f, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 private: | 173 private: |
| 174 typedef PixelSnapGM INHERITED; | 174 typedef PixelSnapGM INHERITED; |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 ////////////////////////////////////////////////////////////////////////////// | 177 ////////////////////////////////////////////////////////////////////////////// |
| 178 DEF_GM( return SkNEW(PointSnapGM); ) | 178 DEF_GM( return SkNEW(PointSnapGM); ) |
| 179 DEF_GM( return SkNEW(LineSnapGM); ) | 179 DEF_GM( return SkNEW(LineSnapGM); ) |
| 180 DEF_GM( return SkNEW(RectSnapGM); ) | 180 DEF_GM( return SkNEW(RectSnapGM); ) |
| 181 DEF_GM( return SkNEW(ComboSnapGM); ) | 181 DEF_GM( return SkNEW(ComboSnapGM); ) |
| OLD | NEW |