skia2/gm/strokerect_anisotropic.cpp
Robert Phillips d5caeb8d66 Improve handling of anisotropic scaling for stroked rects
This doesn't resolve all the problems here but does substantially improve the situation. In particular, if the device-space stroke is greater than 1 in one axis and less than 1 in the other, the smaller side will still appear darker than expected.

Bug: 935303
Change-Id: I3ff9bc73cad5ad5b8e13ef5aa7b46bbf4835753b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263024
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2020-01-09 14:41:44 +00:00

83 lines
2.4 KiB
C++

/*
* Copyright 2020 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPath.h"
static void draw_sqooshed_rect(SkCanvas* canvas, SkVector xlate, const SkPaint& p) {
canvas->save();
canvas->translate(xlate.fX, xlate.fY);
canvas->scale(0.03f, 2.0f);
canvas->drawRect(SkRect::MakeLTRB(-500, -10, 500, 10), p);
canvas->restore();
}
/*
* This GM is intended to wring out any lingering anisotropic
* stroke rect bugs. It contains a repro case for crbug.com/935303
* The pattern is:
*
* miter @ miter @ bevel @ bevel @
* whole pixels half pixels whole pixels half pixels
*
* AA
*
* non-AA
*
*/
class StrokeRectAnisotropicGM : public skiagm::GM {
public:
StrokeRectAnisotropicGM() {}
protected:
SkString onShortName() override {
return SkString("strokerect_anisotropic");
}
SkISize onISize() override {
return SkISize::Make(160, 160);
}
void onDraw(SkCanvas* canvas) override {
SkPaint aaPaint;
aaPaint.setColor(SkColorSetARGB(255, 0, 0, 0));
aaPaint.setAntiAlias(true);
aaPaint.setStrokeWidth(10);
aaPaint.setStyle(SkPaint::kStroke_Style);
SkPaint bwPaint;
bwPaint.setColor(SkColorSetARGB(255, 0, 0, 0));
bwPaint.setStrokeWidth(10);
bwPaint.setStyle(SkPaint::kStroke_Style);
// The two miter columns
draw_sqooshed_rect(canvas, { 20.0f, 40.5f }, aaPaint); // whole pixels
draw_sqooshed_rect(canvas, { 20.0f, 110.5f }, bwPaint); // whole pixels
draw_sqooshed_rect(canvas, { 60.5f, 40.0f }, aaPaint); // half pixels
draw_sqooshed_rect(canvas, { 60.5f, 110.0f }, bwPaint); // half pixels
aaPaint.setStrokeJoin(SkPaint::kBevel_Join);
bwPaint.setStrokeJoin(SkPaint::kBevel_Join);
// The two bevel columns
draw_sqooshed_rect(canvas, { 100.0f, 40.5f }, aaPaint); // whole pixels
draw_sqooshed_rect(canvas, { 100.0f, 110.5f }, bwPaint); // whole pixels
draw_sqooshed_rect(canvas, { 140.5f, 40.0f }, aaPaint); // half pixels
draw_sqooshed_rect(canvas, { 140.5f, 110.0f }, bwPaint); // half pixels
}
private:
typedef GM INHERITED;
};
DEF_GM(return new StrokeRectAnisotropicGM;)