Revert "Add ToolUtils helper for generating GM UI sliders for variable fonts"

This reverts commit 5117907413.

Reason for revert: blocking G3 roll and red bots

Original change's description:
> Add ToolUtils helper for generating GM UI sliders for variable fonts
>
> Use this new tool in the COLRv1 GM test for creating sliders in the GM
> UI if the test font provides variable axes. Update GM
> "fontscalerdistortable" as well.
>
> Preparation for testing variable COLRv1 fonts while developing
> this feature in FreeType.
>
> Bug: chromium:1311241
> Change-Id: I55419d6dc058f420a567d8a50cca5d719206daf4
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/555476
> Reviewed-by: Ben Wagner <bungeman@google.com>
> Reviewed-by: Florin Malita <fmalita@google.com>
> Commit-Queue: Ben Wagner <bungeman@google.com>
> Commit-Queue: Dominik Röttsches <drott@chromium.org>

Bug: chromium:1311241
Change-Id: Icdd27da3b5c074964ca07fc6eee3e59aa90234b4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/556656
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Robert Phillips <robertphillips@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
This commit is contained in:
Robert Phillips 2022-07-07 19:01:49 +00:00 committed by SkCQ
parent 5117907413
commit 20402a69d0
4 changed files with 48 additions and 148 deletions

View File

@ -10,7 +10,6 @@
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontMetrics.h"
#include "include/core/SkGraphics.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
@ -25,10 +24,6 @@
namespace skiagm {
namespace {
bool ColrV1VariationsEnabledForTest() { return true; }
}
class ColrV1GM : public GM {
public:
@ -50,11 +45,7 @@ public:
};
ColrV1GM(ColrV1TestType testType, SkScalar skewX, SkScalar rotateDeg)
: fSkewX(skewX), fRotateDeg(rotateDeg), fTestType(testType) {
fPreviousFlagFunc = SkGraphics::SetVariableColrV1EnabledFunc(ColrV1VariationsEnabledForTest);
}
~ColrV1GM() override { SkGraphics::SetVariableColrV1EnabledFunc(fPreviousFlagFunc); }
: fSkewX(skewX), fRotateDeg(rotateDeg), fTestType(testType) {}
protected:
static SkString testTypeToString(ColrV1TestType testType) {
@ -146,8 +137,6 @@ protected:
fEmojiFont.fGlyphs = {73, 74, 75, 76, 77, 78, 79, 80};
break;
}
fVariationSliders = ToolUtils::VariationSliders(fEmojiFont.fTypeface.get());
}
SkString onShortName() override {
@ -163,14 +152,6 @@ protected:
return gm_name;
}
bool onGetControls(SkMetaData* controls) override {
return fVariationSliders.writeControls(controls);
}
void onSetControls(const SkMetaData& controls) override {
return fVariationSliders.readControls(controls);
}
SkISize onISize() override { return SkISize::Make(1400, 600); }
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
@ -187,14 +168,7 @@ protected:
canvas->rotate(fRotateDeg);
canvas->skew(fSkewX, 0);
SkSpan<const SkFontArguments::VariationPosition::Coordinate> coords =
fVariationSliders.getCoordinates();
SkFontArguments::VariationPosition varPos = {coords.data(),
static_cast<int>(coords.size())};
SkFontArguments args;
args.setVariationDesignPosition(varPos);
sk_sp<SkTypeface> axisAppliedTypeface = fEmojiFont.fTypeface->makeClone(args);
SkFont font(axisAppliedTypeface);
SkFont font(fEmojiFont.fTypeface);
SkFontMetrics metrics;
SkScalar y = 0;
@ -218,12 +192,9 @@ protected:
private:
using INHERITED = GM;
SkScalar fSkewX;
SkScalar fRotateDeg;
ColrV1TestType fTestType;
ToolUtils::VariationSliders fVariationSliders;
SkGraphics::VariableColrV1EnabledFunc fPreviousFlagFunc;
};
DEF_GM(return new ColrV1GM(ColrV1GM::kSkiaSampleFont, 0.f, 0.f);)

View File

@ -22,7 +22,6 @@
#include "include/core/SkTypes.h"
#include "tools/Resources.h"
#include "tools/SkMetaData.h"
#include "tools/ToolUtils.h"
#include <string.h>
#include <memory>
@ -49,11 +48,20 @@ private:
bool fDirty = true;
bool fOverride = false;
ToolUtils::VariationSliders fVariationSliders;
size_t fAxisSliderCount = 0;
struct AxisSlider {
SkFourByteTag axis;
SkScalar control[3];
SkString name;
};
std::unique_ptr<AxisSlider[]> fAxisSliders;
bool onGetControls(SkMetaData* controls) override {
controls->setBool("Override", fOverride);
return fVariationSliders.writeControls(controls);
for (size_t i = 0; i < fAxisSliderCount; ++i) {
controls->setScalars(fAxisSliders[i].name.c_str(), 3, fAxisSliders[i].control);
}
return true;
}
void onSetControls(const SkMetaData& controls) override {
@ -63,7 +71,13 @@ private:
fDirty = true;
}
return fVariationSliders.readControls(controls, &fDirty);
for (size_t i = 0; i < fAxisSliderCount; ++i) {
SkScalar oldValue = fAxisSliders[i].control[0];
controls.findScalars(fAxisSliders[i].name.c_str(), nullptr, fAxisSliders[i].control);
if (oldValue != fAxisSliders[i].control[0]) {
fDirty = true;
}
}
}
struct Info {
@ -85,7 +99,23 @@ private:
};
if (fInfo.distortable) {
fVariationSliders = ToolUtils::VariationSliders(fInfo.distortable.get());
int axisCount = fInfo.distortable->getVariationDesignParameters(nullptr, 0);
if (axisCount > 0) {
auto axes = std::make_unique<SkFontParameters::Variation::Axis[]>(axisCount);
axisCount = fInfo.distortable->getVariationDesignParameters(axes.get(), axisCount);
if (axisCount > 0) {
fAxisSliders = std::make_unique<AxisSlider[]>(axisCount);
for (int i = 0; i < axisCount; ++i) {
fAxisSliders[i].axis = axes[i].tag;
fAxisSliders[i].control[0] = axes[i].def;
fAxisSliders[i].control[1] = axes[i].min;
fAxisSliders[i].control[2] = axes[i].max;
fAxisSliders[i].name.append((const char *)&axes[i].tag, 4);
fAxisSliders[i].name.appendS32(i);
}
fAxisSliderCount = axisCount;
}
}
}
}
@ -102,21 +132,24 @@ private:
for (int row = 0; row < rows; ++row) {
for (int col = 0; col < cols; ++col) {
using Coordinate = SkFontArguments::VariationPosition::Coordinate;
SkFontArguments::VariationPosition position;
Coordinate coordinates[2];
int coordinateCount;
std::unique_ptr<Coordinate[]> coordinates;
if (fOverride) {
SkSpan<const Coordinate> user_coordinates = fVariationSliders.getCoordinates();
position = {user_coordinates.data(), static_cast<int>(user_coordinates.size())};
coordinateCount = fAxisSliderCount;
coordinates = std::make_unique<Coordinate[]>(coordinateCount);
for (size_t i = 0; i < fAxisSliderCount; ++i) {
coordinates[i].axis = fAxisSliders[i].axis;
coordinates[i].value = fAxisSliders[i].control[0];
}
} else {
const int coordinateCount = 2;
coordinateCount = 2;
coordinates = std::make_unique<Coordinate[]>(coordinateCount);
SkScalar styleValue = SkScalarInterp(fInfo.axisMin, fInfo.axisMax,
SkScalar(row*cols + col) / (rows*cols));
coordinates[0] = {fInfo.axisTag, styleValue};
coordinates[1] = {fInfo.axisTag, styleValue};
position = {coordinates, static_cast<int>(coordinateCount)};
}
SkFontArguments::VariationPosition position = {coordinates.get(), coordinateCount};
typeface[row][col] = [&]() -> sk_sp<SkTypeface> {
if (row == 0 && fInfo.distortable) {

View File

@ -554,75 +554,4 @@ sk_sp<SkImage> MakeTextureImage(SkCanvas* canvas, sk_sp<SkImage> orig) {
}
#endif
VariationSliders::VariationSliders(SkTypeface* typeface) {
if (!typeface) {
return;
}
int numAxes = typeface->getVariationDesignParameters(nullptr, 0);
if (!numAxes) {
return;
}
std::unique_ptr<SkFontParameters::Variation::Axis[]> copiedAxes =
std::make_unique<SkFontParameters::Variation::Axis[]>(numAxes);
numAxes = typeface->getVariationDesignParameters(copiedAxes.get(), numAxes);
if (!numAxes) {
return;
}
fAxisSliders.resize(numAxes);
for (int i = 0; i < numAxes; ++i) {
fAxisSliders[i].axis = copiedAxes[i];
fAxisSliders[i].current = copiedAxes[i].def;
fAxisSliders[i].name = tagToString(fAxisSliders[i].axis.tag);
}
fCoords = std::make_unique<SkFontArguments::VariationPosition::Coordinate[]>(numAxes);
}
/* static */
SkString VariationSliders::tagToString(SkFourByteTag tag) {
char tagAsString[5];
tagAsString[4] = 0;
tagAsString[0] = (char)(uint8_t)(tag >> 24);
tagAsString[1] = (char)(uint8_t)(tag >> 16);
tagAsString[2] = (char)(uint8_t)(tag >> 8);
tagAsString[3] = (char)(uint8_t)(tag >> 0);
return SkString(tagAsString);
}
bool VariationSliders::writeControls(SkMetaData* controls) {
for (size_t i = 0; i < fAxisSliders.size(); ++i) {
SkScalar axisVars[kAxisVarsSize];
axisVars[0] = fAxisSliders[i].current;
axisVars[1] = fAxisSliders[i].axis.min;
axisVars[2] = fAxisSliders[i].axis.max;
controls->setScalars(fAxisSliders[i].name.c_str(), kAxisVarsSize, axisVars);
}
return true;
}
void VariationSliders::readControls(const SkMetaData& controls, bool* changed) {
for (size_t i = 0; i < fAxisSliders.size(); ++i) {
SkScalar axisVars[kAxisVarsSize] = {0};
int resultAxisVarsSize = 0;
SkASSERT_RELEASE(controls.findScalars(
tagToString(fAxisSliders[i].axis.tag).c_str(), &resultAxisVarsSize, axisVars));
SkASSERT_RELEASE(resultAxisVarsSize == kAxisVarsSize);
if (changed) {
*changed |= fAxisSliders[i].current != axisVars[0];
}
fAxisSliders[i].current = axisVars[0];
fCoords[i] = { fAxisSliders[i].axis.tag, fAxisSliders[i].current };
}
}
SkSpan<const SkFontArguments::VariationPosition::Coordinate> VariationSliders::getCoordinates() {
return SkSpan<const SkFontArguments::VariationPosition::Coordinate>{fCoords.get(),
fAxisSliders.size()};
}
} // namespace ToolUtils

View File

@ -20,7 +20,6 @@
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSpan.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypeface.h"
@ -29,7 +28,6 @@
#include "include/private/SkTDArray.h"
#include "include/utils/SkRandom.h"
#include "src/core/SkTInternalLList.h"
#include "tools/SkMetaData.h"
class SkBitmap;
class SkCanvas;
@ -306,37 +304,6 @@ void sniff_paths(const char filepath[], std::function<PathSniffCallback>);
sk_sp<SkImage> MakeTextureImage(SkCanvas* canvas, sk_sp<SkImage> orig);
#endif
// Initialised with a font, this class can be called to setup GM UI with sliders for font
// variations, and returns a set of variation coordinates that matches what the sliders in the UI
// are set to. Useful for testing variable font properties, see colrv1.cpp.
class VariationSliders {
public:
VariationSliders() {}
VariationSliders(SkTypeface*);
bool writeControls(SkMetaData* controls);
/* Scans controls for information about the variation axes that the user may have configured.
* Optionally pass in a boolean to receive information on whether the axes were updated. */
void readControls(const SkMetaData& controls, bool* changed = nullptr);
SkSpan<const SkFontArguments::VariationPosition::Coordinate> getCoordinates();
private:
static SkString tagToString(SkFourByteTag tag);
struct AxisSlider {
SkScalar current;
SkFontParameters::Variation::Axis axis;
SkString name;
};
std::vector<AxisSlider> fAxisSliders;
std::unique_ptr<SkFontArguments::VariationPosition::Coordinate[]> fCoords;
static constexpr size_t kAxisVarsSize = 3;
};
} // namespace ToolUtils
#endif // ToolUtils_DEFINED