aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2015-04-22 11:34:46 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-22 11:34:46 -0700
commitc6534a28a634e501075fde2b483bf62336276cef (patch)
tree3278350bb03212c0091c382972d2b40db543f383 /gm
parent12c20e40a47a454049cda8240a9b3d8918ac06ef (diff)
Make pixel_snap GMs incur less platform-specific variation
Diffstat (limited to 'gm')
-rw-r--r--gm/pixelsnap.cpp72
1 files changed, 31 insertions, 41 deletions
diff --git a/gm/pixelsnap.cpp b/gm/pixelsnap.cpp
index a9652f6f87..8a513f3ca5 100644
--- a/gm/pixelsnap.cpp
+++ b/gm/pixelsnap.cpp
@@ -23,18 +23,13 @@ protected:
static const int kSubPixelSteps = 8;
static const int kLabelTextSize = 9;
+ SK_COMPILE_ASSERT(kSubPixelSteps < 99, label_offset_too_small);
+ static const int kLabelOffsetX = 2 * kLabelTextSize + kLabelPad;
+ static const int kLabelOffsetY = kLabelTextSize + kLabelPad;
+
SkISize onISize() override {
- SkPaint labelPaint;
- labelPaint.setAntiAlias(true);
- labelPaint.setColor(SK_ColorWHITE);
- labelPaint.setTextSize(SkIntToScalar(kLabelTextSize));
- // Assert that we only render double digit labels
- SkASSERT(kSubPixelSteps < 99);
- // Pick 88 as widest possible label rendered (?)
- int xoffset = SkScalarCeilToInt(labelPaint.measureText("88", 2));
- int yoffset = SkScalarCeilToInt(labelPaint.getTextSize());
- return SkISize::Make(kLabelPad + (kSubPixelSteps + 1) * kTrans + xoffset,
- kLabelPad + (kSubPixelSteps + 1) * kTrans + yoffset);
+ return SkISize::Make((kSubPixelSteps + 1) * kTrans + kLabelOffsetX + kLabelPad,
+ (kSubPixelSteps + 1) * kTrans + kLabelOffsetY + kLabelPad);
}
void onDraw(SkCanvas* canvas) override {
@@ -51,37 +46,32 @@ protected:
SkPaint linePaint;
linePaint.setColor(SK_ColorWHITE);
- // Draw row labels
- static const SkScalar labelOffsetY = labelPaint.getTextSize() + kLabelPad;
- SkScalar labelOffsetX = 0;
- canvas->save();
- canvas->translate(0, labelOffsetY);
- for (int i = 0; i <= kSubPixelSteps; ++i) {
- offset.printf("%d", i);
- canvas->drawText(offset.c_str(), offset.size(),
- 0, i * kTrans + labelPaint.getTextSize(),
- labelPaint);
- labelOffsetX = SkTMax(labelPaint.measureText(offset.c_str(), offset.size()),
- labelOffsetX);
- }
- canvas->restore();
- labelOffsetX += kLabelPad;
- labelOffsetX = SkScalarCeilToScalar(labelOffsetX);
-
- // Draw col labels
- canvas->save();
- canvas->translate(labelOffsetX, 0);
- for (int i = 0; i <= kSubPixelSteps; ++i) {
- offset.printf("%d", i);
- canvas->drawText(offset.c_str(), offset.size(),
- i * SkIntToScalar(kTrans), labelPaint.getTextSize(),
- labelPaint);
- }
- canvas->restore();
+ // Drawing labels is useful for debugging, but bad for baselining (x-platform txt diffs).
+ if (false) {
+ // Draw row labels
+ canvas->save();
+ canvas->translate(0, SkIntToScalar(kLabelOffsetY));
+ for (int i = 0; i <= kSubPixelSteps; ++i) {
+ offset.printf("%d", i);
+ canvas->drawText(offset.c_str(), offset.size(),
+ 0, i * kTrans + labelPaint.getTextSize(),
+ labelPaint);
+ }
+ canvas->restore();
+
+ // Draw col labels
+ canvas->save();
+ canvas->translate(SkIntToScalar(kLabelOffsetX), 0);
+ for (int i = 0; i <= kSubPixelSteps; ++i) {
+ offset.printf("%d", i);
+ canvas->drawText(offset.c_str(), offset.size(),
+ i * SkIntToScalar(kTrans), labelPaint.getTextSize(),
+ labelPaint);
+ }
+ canvas->restore();
+ }
- canvas->translate(labelOffsetX, labelOffsetY);
- SkASSERT((SkScalar)(int)labelOffsetX == labelOffsetX);
- SkASSERT((SkScalar)(int)labelOffsetY == labelOffsetY);
+ canvas->translate(SkIntToScalar(kLabelOffsetX), SkIntToScalar(kLabelOffsetY));
// Draw test case grid lines (Draw them all at pixel centers to hopefully avoid any
// snapping issues).