Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: gm/pixelsnap.cpp

Issue 1080393009: Make pixel_snap GMs incur less platform-specific variation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/pixelsnap.cpp
diff --git a/gm/pixelsnap.cpp b/gm/pixelsnap.cpp
index a9652f6f870082faeb0e65b95ccb89d6ec74b7d4..8a513f3ca5409725def3c39ea2bb0c08a6d62c3a 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).
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698