Create hardstop_gradients_many test slide.

This GM presents different gradients with an increasing number of
hardstops, from 1 to 100.

Change-Id: I1c279c6ea1a25f9785001aa29db632547a38ab68
Bug: skia:8401
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/457437
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2021-10-08 17:33:47 -04:00 committed by SkCQ
parent cbaf52b373
commit eafb39fc7e
2 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,90 @@
/*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
* This GM presents different gradients with an increasing number of
* hardstops, from 1 to 100.
*/
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
#include "include/effects/SkGradientShader.h"
const int kWidth = 1000;
const int kHeight = 2000;
const int kNumRows = 100;
const int kCellHeight = kHeight / kNumRows;
const int kPadHeight = 1;
const int kRectHeight = kCellHeight - (2 * kPadHeight);
class HardstopGradientsManyGM : public skiagm::GM {
public:
HardstopGradientsManyGM() {}
protected:
SkString onShortName() override {
return SkString("hardstop_gradients_many");
}
SkISize onISize() override {
return SkISize::Make(kWidth, kHeight);
}
void onDraw(SkCanvas* canvas) override {
static constexpr SkPoint points[] = {
SkPoint::Make(0, kRectHeight / 2),
SkPoint::Make(kWidth, kRectHeight / 2),
};
std::vector<SkColor> colors;
std::vector<SkScalar> positions;
for (int row = 1; row <= kNumRows; ++row) {
// Assemble a gradient containing a blue-to-white blend, repeated N times per row.
colors.push_back(SK_ColorBLUE);
colors.push_back(SK_ColorWHITE);
positions = {0.0f};
for (int pos = 1; pos < row; ++pos) {
float place = SkScalar(pos) / SkScalar(row);
positions.push_back(place);
positions.push_back(place);
}
positions.push_back(1.0f);
SkASSERT(positions.size() == colors.size());
// Draw it.
auto shader = SkGradientShader::MakeLinear(points,
colors.data(),
positions.data(),
colors.size(),
SkTileMode::kClamp,
/*flags=*/0,
/*localMatrix=*/nullptr);
SkPaint paint;
paint.setShader(shader);
canvas->drawRect(SkRect::MakeXYWH(0, kPadHeight, kWidth, kRectHeight), paint);
canvas->translate(0, kCellHeight);
}
}
private:
using INHERITED = skiagm::GM;
};
DEF_GM(return new HardstopGradientsManyGM;)

View File

@ -200,6 +200,7 @@ gm_sources = [
"$_gm/hairlines.cpp",
"$_gm/hairmodes.cpp",
"$_gm/hardstop_gradients.cpp",
"$_gm/hardstop_gradients_many.cpp",
"$_gm/highcontrastfilter.cpp",
"$_gm/hittestpath.cpp",
"$_gm/hsl.cpp",