Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 1 | /* |
Dominik Röttsches | 7368c6d | 2021-11-01 17:54:47 +0200 | [diff] [blame] | 2 | * Copyright 2021 Google Inc. |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkFont.h" |
| 12 | #include "include/core/SkFontMetrics.h" |
Dominik Röttsches | 0443e02 | 2024-01-10 19:49:19 +0200 | [diff] [blame] | 13 | #include "include/core/SkFontMgr.h" |
Dominik Röttsches | f27608b | 2022-07-08 17:35:18 +0300 | [diff] [blame] | 14 | #include "include/core/SkGraphics.h" |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 15 | #include "include/core/SkPaint.h" |
| 16 | #include "include/core/SkRefCnt.h" |
| 17 | #include "include/core/SkScalar.h" |
| 18 | #include "include/core/SkSize.h" |
Dominik Röttsches | 0443e02 | 2024-01-10 19:49:19 +0200 | [diff] [blame] | 19 | #include "include/core/SkStream.h" |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 20 | #include "include/core/SkString.h" |
| 21 | #include "include/core/SkTypeface.h" |
| 22 | #include "tools/Resources.h" |
| 23 | #include "tools/ToolUtils.h" |
Kevin Lubick | 1e97119 | 2023-11-10 16:14:44 -0500 | [diff] [blame] | 24 | #include "tools/fonts/FontToolUtils.h" |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 25 | |
Dominik Röttsches | 0443e02 | 2024-01-10 19:49:19 +0200 | [diff] [blame] | 26 | #include "include/ports/SkTypeface_fontations.h" |
| 27 | // #include "include/ports/SkFontMgr_empty.h" |
| 28 | |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include <initializer_list> |
| 31 | |
| 32 | namespace skiagm { |
| 33 | |
Dominik Röttsches | f27608b | 2022-07-08 17:35:18 +0300 | [diff] [blame] | 34 | namespace { |
Dominik Röttsches | 0443e02 | 2024-01-10 19:49:19 +0200 | [diff] [blame] | 35 | enum TypefaceBackend { UseDefault, UseFontations }; |
| 36 | |
| 37 | // TODO(b/318667611): Move the explicit instantation to font manager for Fontations. |
| 38 | #if defined(SK_TYPEFACE_FACTORY_FONTATIONS) |
| 39 | constexpr auto kBackend = TypefaceBackend::UseFontations; |
| 40 | #else |
| 41 | constexpr auto kBackend = TypefaceBackend::UseDefault; |
| 42 | #endif |
| 43 | |
| 44 | template <TypefaceBackend variant> sk_sp<SkTypeface> MakeTypefaceFromResource(const char* resource); |
| 45 | |
| 46 | #if defined(SK_TYPEFACE_FACTORY_FONTATIONS) |
| 47 | template <> sk_sp<SkTypeface> MakeTypefaceFromResource<UseFontations>(const char* resource) { |
| 48 | std::unique_ptr<SkStreamAsset> resourceStream(GetResourceAsStream(resource, false)); |
| 49 | return SkTypeface_Make_Fontations(std::move(resourceStream), SkFontArguments()); |
| 50 | } |
| 51 | #else |
| 52 | template <> sk_sp<SkTypeface> MakeTypefaceFromResource<UseDefault>(const char* resource) { |
| 53 | return ToolUtils::CreateTypefaceFromResource(resource, 0); |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | } // namespace |
| 58 | |
| 59 | namespace { |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 60 | const SkScalar kTextSizes[] = {12, 18, 30, 120}; |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 61 | const char kTestFontName[] = "fonts/test_glyphs-glyf_colr_1.ttf"; |
| 62 | const char kTestFontNameVariable[] = "fonts/test_glyphs-glyf_colr_1_variable.ttf"; |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 63 | const SkScalar xWidth = 1200; |
| 64 | const SkScalar xTranslate = 200; |
Dominik Röttsches | 0443e02 | 2024-01-10 19:49:19 +0200 | [diff] [blame] | 65 | } // namespace |
Dominik Röttsches | f27608b | 2022-07-08 17:35:18 +0300 | [diff] [blame] | 66 | |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 67 | class ColrV1GM : public GM { |
| 68 | public: |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 69 | ColrV1GM(const char* testName, |
| 70 | SkSpan<const uint32_t> codepoints, |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 71 | SkScalar skewX, |
| 72 | SkScalar rotateDeg, |
| 73 | std::initializer_list<SkFontArguments::VariationPosition::Coordinate> |
| 74 | specifiedVariations) |
Dominik Röttsches | 0443e02 | 2024-01-10 19:49:19 +0200 | [diff] [blame] | 75 | : fTestName(testName), fCodepoints(codepoints), fSkewX(skewX), fRotateDeg(rotateDeg) { |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 76 | fVariationPosition.coordinateCount = specifiedVariations.size(); |
| 77 | fCoordinates = std::make_unique<SkFontArguments::VariationPosition::Coordinate[]>( |
| 78 | specifiedVariations.size()); |
| 79 | for (size_t i = 0; i < specifiedVariations.size(); ++i) { |
| 80 | fCoordinates[i] = std::data(specifiedVariations)[i]; |
| 81 | } |
| 82 | |
| 83 | fVariationPosition.coordinates = fCoordinates.get(); |
| 84 | } |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 85 | |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 86 | protected: |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 87 | void onOnceBeforeDraw() override { |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 88 | if (fVariationPosition.coordinateCount) { |
Dominik Röttsches | 0443e02 | 2024-01-10 19:49:19 +0200 | [diff] [blame] | 89 | fTypeface = MakeTypefaceFromResource<kBackend>(kTestFontNameVariable); |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 90 | } else { |
Dominik Röttsches | 0443e02 | 2024-01-10 19:49:19 +0200 | [diff] [blame] | 91 | fTypeface = MakeTypefaceFromResource<kBackend>(kTestFontName); |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 92 | } |
| 93 | fVariationSliders = ToolUtils::VariationSliders(fTypeface.get(), fVariationPosition); |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Leandro Lovisolo | 24fa211 | 2023-08-15 19:05:17 +0000 | [diff] [blame] | 96 | SkString getName() const override { |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 97 | SkASSERT(!fTestName.isEmpty()); |
| 98 | SkString gm_name = SkStringPrintf("colrv1_%s", fTestName.c_str()); |
| 99 | |
Dominik Röttsches | 2da029b | 2021-05-11 15:59:43 +0300 | [diff] [blame] | 100 | if (fSkewX) { |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 101 | gm_name.append(SkStringPrintf("_skew_%.2f", fSkewX)); |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 102 | } |
Dominik Röttsches | 2da029b | 2021-05-11 15:59:43 +0300 | [diff] [blame] | 103 | |
| 104 | if (fRotateDeg) { |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 105 | gm_name.append(SkStringPrintf("_rotate_%.2f", fRotateDeg)); |
Dominik Röttsches | 2da029b | 2021-05-11 15:59:43 +0300 | [diff] [blame] | 106 | } |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 107 | |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 108 | for (int i = 0; i < fVariationPosition.coordinateCount; ++i) { |
| 109 | SkString tagName = ToolUtils::VariationSliders::tagToString( |
| 110 | fVariationPosition.coordinates[i].axis); |
| 111 | gm_name.append(SkStringPrintf( |
| 112 | "_%s_%.2f", tagName.c_str(), fVariationPosition.coordinates[i].value)); |
| 113 | } |
| 114 | |
Dominik Röttsches | 2da029b | 2021-05-11 15:59:43 +0300 | [diff] [blame] | 115 | return gm_name; |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Dominik Röttsches | f27608b | 2022-07-08 17:35:18 +0300 | [diff] [blame] | 118 | bool onGetControls(SkMetaData* controls) override { |
| 119 | return fVariationSliders.writeControls(controls); |
| 120 | } |
| 121 | |
| 122 | void onSetControls(const SkMetaData& controls) override { |
| 123 | return fVariationSliders.readControls(controls); |
| 124 | } |
| 125 | |
Leandro Lovisolo | 8f02388 | 2023-08-15 21:13:52 +0000 | [diff] [blame] | 126 | SkISize getISize() override { |
Dominik Röttsches | 18b0e15 | 2022-08-15 12:01:10 +0300 | [diff] [blame] | 127 | // Sweep tests get a slightly wider canvas so that glyphs from one group fit in one row. |
| 128 | if (fTestName.equals("sweep_varsweep")) { |
| 129 | return SkISize::Make(xWidth + 500, xWidth); |
| 130 | } |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 131 | return SkISize::Make(xWidth, xWidth); |
| 132 | } |
| 133 | |
| 134 | sk_sp<SkTypeface> makeVariedTypeface() { |
| 135 | if (!fTypeface) { |
| 136 | return nullptr; |
| 137 | } |
| 138 | SkSpan<const SkFontArguments::VariationPosition::Coordinate> coords = |
| 139 | fVariationSliders.getCoordinates(); |
| 140 | SkFontArguments::VariationPosition varPos = {coords.data(), |
| 141 | static_cast<int>(coords.size())}; |
| 142 | SkFontArguments args; |
| 143 | args.setVariationDesignPosition(varPos); |
| 144 | return fTypeface->makeClone(args); |
| 145 | } |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 146 | |
| 147 | DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override { |
| 148 | canvas->drawColor(SK_ColorWHITE); |
| 149 | SkPaint paint; |
| 150 | |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 151 | canvas->translate(xTranslate, 20); |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 152 | |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 153 | if (!fTypeface) { |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 154 | *errorMsg = "Did not recognize COLR v1 font format."; |
| 155 | return DrawResult::kSkip; |
| 156 | } |
| 157 | |
| 158 | canvas->rotate(fRotateDeg); |
| 159 | canvas->skew(fSkewX, 0); |
| 160 | |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 161 | SkFont font(makeVariedTypeface()); |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 162 | |
| 163 | SkFontMetrics metrics; |
| 164 | SkScalar y = 0; |
Dominik Röttsches | 612c733 | 2021-11-09 16:13:19 +0200 | [diff] [blame] | 165 | std::vector<SkColor> paint_colors = { |
| 166 | SK_ColorBLACK, SK_ColorGREEN, SK_ColorRED, SK_ColorBLUE}; |
| 167 | auto paint_color_iterator = paint_colors.begin(); |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 168 | for (SkScalar textSize : kTextSizes) { |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 169 | font.setSize(textSize); |
| 170 | font.getMetrics(&metrics); |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 171 | SkScalar y_shift = -(metrics.fAscent + metrics.fDescent + metrics.fLeading) * 1.2; |
| 172 | y += y_shift; |
Dominik Röttsches | 612c733 | 2021-11-09 16:13:19 +0200 | [diff] [blame] | 173 | paint.setColor(*paint_color_iterator); |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 174 | int x = 0; |
| 175 | // Perform simple line breaking to fit more glyphs into the GM canvas. |
| 176 | for (size_t i = 0; i < fCodepoints.size(); ++i) { |
| 177 | canvas->drawSimpleText(&fCodepoints[i], |
| 178 | sizeof(uint32_t), |
| 179 | SkTextEncoding::kUTF32, |
| 180 | x, |
| 181 | y, |
| 182 | font, |
| 183 | paint); |
| 184 | SkScalar glyphAdvance = font.measureText( |
| 185 | &fCodepoints[i], sizeof(uint32_t), SkTextEncoding::kUTF32, nullptr); |
Leandro Lovisolo | 8f02388 | 2023-08-15 21:13:52 +0000 | [diff] [blame] | 186 | if (x + glyphAdvance < getISize().width() - xTranslate) { |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 187 | x += glyphAdvance + glyphAdvance * 0.05f; |
| 188 | } else { |
| 189 | y += y_shift; |
| 190 | x = 0; |
| 191 | } |
| 192 | } |
Dominik Röttsches | 612c733 | 2021-11-09 16:13:19 +0200 | [diff] [blame] | 193 | paint_color_iterator++; |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 194 | } |
| 195 | return DrawResult::kOk; |
| 196 | } |
| 197 | |
| 198 | private: |
| 199 | using INHERITED = GM; |
Dominik Röttsches | f27608b | 2022-07-08 17:35:18 +0300 | [diff] [blame] | 200 | |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 201 | SkString fTestName; |
| 202 | sk_sp<SkTypeface> fTypeface; |
| 203 | SkSpan<const uint32_t> fCodepoints; |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 204 | SkScalar fSkewX; |
| 205 | SkScalar fRotateDeg; |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 206 | std::unique_ptr<SkFontArguments::VariationPosition::Coordinate[]> fCoordinates; |
| 207 | SkFontArguments::VariationPosition fVariationPosition; |
Dominik Röttsches | f27608b | 2022-07-08 17:35:18 +0300 | [diff] [blame] | 208 | ToolUtils::VariationSliders fVariationSliders; |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 209 | }; |
| 210 | |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 211 | // Generated using test glyphs generator script from https://github.com/googlefonts/color-fonts: |
| 212 | // $ python3 config/test_glyphs-glyf_colr_1.py -vvv --generate-descriptions fonts/ |
| 213 | // Regenerate descriptions and paste the generated arrays here when updating the test font. |
| 214 | namespace ColrV1TestDefinitions { |
| 215 | const uint32_t gradient_stops_repeat[] = {0xf0100, 0xf0101, 0xf0102, 0xf0103}; |
Dominik Röttsches | 18b0e15 | 2022-08-15 12:01:10 +0300 | [diff] [blame] | 216 | const uint32_t sweep_varsweep[] = { |
| 217 | 0xf0200, 0xf0201, 0xf0202, 0xf0203, 0xf0204, 0xf0205, 0xf0206, 0xf0207, 0xf0208, |
| 218 | 0xf0209, 0xf020a, 0xf020b, 0xf020c, 0xf020d, 0xf020e, 0xf020f, 0xf0210, 0xf0211, |
| 219 | 0xf0212, 0xf0213, 0xf0214, 0xf0215, 0xf0216, 0xf0217, 0xf0218, 0xf0219, 0xf021a, |
| 220 | 0xf021b, 0xf021c, 0xf021d, 0xf021e, 0xf021f, 0xf0220, 0xf0221, 0xf0222, 0xf0223, |
| 221 | 0xf0224, 0xf0225, 0xf0226, 0xf0227, 0xf0228, 0xf0229, 0xf022a, 0xf022b, 0xf022c, |
| 222 | 0xf022d, 0xf022e, 0xf022f, 0xf0230, 0xf0231, 0xf0232, 0xf0233, 0xf0234, 0xf0235, |
| 223 | 0xf0236, 0xf0237, 0xf0238, 0xf0239, 0xf023a, 0xf023b, 0xf023c, 0xf023d, 0xf023e, |
| 224 | 0xf023f, 0xf0240, 0xf0241, 0xf0242, 0xf0243, 0xf0244, 0xf0245, 0xf0246, 0xf0247}; |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 225 | const uint32_t paint_scale[] = {0xf0300, 0xf0301, 0xf0302, 0xf0303, 0xf0304, 0xf0305}; |
Dominik Röttsches | 3ed97a8 | 2022-08-16 18:59:21 +0300 | [diff] [blame] | 226 | const uint32_t extend_mode[] = { |
| 227 | 0xf0500, 0xf0501, 0xf0502, 0xf0503, 0xf0504, 0xf0505, 0xf0506, 0xf0507, 0xf0508}; |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 228 | const uint32_t paint_rotate[] = {0xf0600, 0xf0601, 0xf0602, 0xf0603}; |
| 229 | const uint32_t paint_skew[] = {0xf0700, 0xf0701, 0xf0702, 0xf0703, 0xf0704, 0xf0705}; |
| 230 | const uint32_t paint_transform[] = {0xf0800, 0xf0801, 0xf0802, 0xf0803}; |
| 231 | const uint32_t paint_translate[] = {0xf0900, 0xf0901, 0xf0902, 0xf0903, 0xf0904, 0xf0905, 0xf0906}; |
| 232 | const uint32_t composite_mode[] = {0xf0a00, 0xf0a01, 0xf0a02, 0xf0a03, 0xf0a04, 0xf0a05, 0xf0a06, |
| 233 | 0xf0a07, 0xf0a08, 0xf0a09, 0xf0a0a, 0xf0a0b, 0xf0a0c, 0xf0a0d, |
| 234 | 0xf0a0e, 0xf0a0f, 0xf0a10, 0xf0a11, 0xf0a12, 0xf0a13, 0xf0a14, |
| 235 | 0xf0a15, 0xf0a16, 0xf0a17, 0xf0a18, 0xf0a19, 0xf0a1a, 0xf0a1b}; |
| 236 | const uint32_t foreground_color[] = { |
| 237 | 0xf0b00, 0xf0b01, 0xf0b02, 0xf0b03, 0xf0b04, 0xf0b05, 0xf0b06, 0xf0b07}; |
| 238 | const uint32_t clipbox[] = {0xf0c00, 0xf0c01, 0xf0c02, 0xf0c03, 0xf0c04}; |
| 239 | const uint32_t gradient_p2_skewed[] = {0xf0d00}; |
| 240 | const uint32_t variable_alpha[] = {0xf1000}; |
Dominik Röttsches | ad8cd0e | 2023-12-21 18:36:49 +0200 | [diff] [blame] | 241 | const uint32_t paintcolrglyph_cycle[] = { 0xf1100, 0xf1101, 0xf1200 }; |
Dominik Röttsches | cf84bab | 2023-12-15 19:10:47 +0200 | [diff] [blame] | 242 | const uint32_t sweep_coincident[] = { 0xf1300, 0xf1301, 0xf1302, 0xf1303, 0xf1304, 0xf1305, |
| 243 | 0xf1306, 0xf1307, 0xf1308, 0xf1309, 0xf130a, 0xf130b, |
| 244 | 0xf130c, 0xf130d, 0xf130e, 0xf130f, 0xf1310, 0xf1311, |
| 245 | 0xf1312, 0xf1313, 0xf1314, 0xf1315, 0xf1316, 0xf1317}; |
Dominik Röttsches | 90ce051 | 2024-01-18 17:41:52 +0200 | [diff] [blame] | 246 | const uint32_t paint_glyph_nested[] = { 0xf1400, 0xf1401, 0xf1402, 0xf1403, |
| 247 | 0xf1404, 0xf1405, 0xf1406, 0xf1407, |
| 248 | 0xf1408, 0xf1409, 0xf140a, 0xf140b, |
| 249 | 0xf140c, 0xf140d, 0xf140e, 0xf140f }; |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 250 | }; // namespace ColrV1TestDefinitions |
| 251 | |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 252 | namespace { |
| 253 | std::unique_ptr<ColrV1GM> F( |
| 254 | const char* name, |
| 255 | SkSpan<const uint32_t> codepoints, |
| 256 | SkScalar skewX, |
| 257 | SkScalar rotateDeg, |
| 258 | std::initializer_list<SkFontArguments::VariationPosition::Coordinate> variations) |
| 259 | { |
| 260 | return std::make_unique<ColrV1GM>(name, codepoints, skewX, rotateDeg, variations); |
| 261 | } |
Dominik Röttsches | 0962774 | 2022-07-28 18:26:02 +0300 | [diff] [blame] | 262 | |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 263 | SkFourByteTag constexpr operator "" _t(const char* tagName, size_t size) { |
| 264 | SkASSERT(size == 4); |
| 265 | return SkSetFourByteTag(tagName[0], tagName[1], tagName[2], tagName[3]); |
| 266 | } |
| 267 | } |
| 268 | #define C(TEST_CATEGORY) #TEST_CATEGORY, ColrV1TestDefinitions::TEST_CATEGORY |
| 269 | DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) |
Dominik Röttsches | a57f08a | 2022-08-12 14:09:02 +0300 | [diff] [blame] | 270 | DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {{"CLIO"_t, 200.f}})) |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 271 | DEF_GM(return F(C(composite_mode), 0.0f, 0.0f, {})) |
| 272 | DEF_GM(return F(C(composite_mode), -0.5f, 0.0f, {})) |
| 273 | DEF_GM(return F(C(composite_mode), -0.5f, 20.0f, {})) |
| 274 | DEF_GM(return F(C(composite_mode), 0.0f, 20.0f, {})) |
| 275 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {})) |
Dominik Röttsches | bd506e3 | 2022-08-24 15:03:15 +0300 | [diff] [blame] | 276 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"COL1"_t, -0.25f}, {"COL3"_t, 0.25f}})) |
| 277 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"COL1"_t, 0.5f}, {"COL3"_t, -0.5f}})) |
Dominik Röttsches | ebf9b2d | 2022-08-19 19:43:45 +0300 | [diff] [blame] | 278 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"COL3"_t, 0.5f}})) |
| 279 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"COL3"_t, 1.f}})) |
Dominik Röttsches | 85b2c7d | 2022-10-03 17:31:27 +0300 | [diff] [blame] | 280 | // Radial gradient tests where radii become negative |
| 281 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"COL1"_t, -1.5f}})) |
| 282 | // Both radii negative and equal, nothing should render. |
| 283 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"GRR0"_t, -200.f}, {"GRR1"_t, -300.f}})) |
| 284 | // Small cones opening to the right. |
| 285 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"GRX0"_t, -1000.f}, {"GRX1"_t, -1000.f}, {"GRR0"_t, -1000.f}, {"GRR1"_t, -900.f}})) |
| 286 | // Small cones opening to the left. |
| 287 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"GRX0"_t, 1000.f}, {"GRX1"_t, -1000.f}, {"GRR0"_t, -1000.f}, {"GRR1"_t, 200.f}})) |
| 288 | // Pad cone should appear green. |
| 289 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"GRR0"_t, -50.f}, {"COL3"_t, -2.f}, {"COL2"_t, -2.f}, {"COL1"_t, -0.9f}})) |
| 290 | // Pad cone should appear red. |
| 291 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"GRR0"_t, -50.f}, {"COL3"_t, -2.f}, {"COL2"_t, -2.f}, {"COL1"_t, -1.1f}})) |
Dominik Röttsches | 3edd61c | 2022-10-07 17:31:05 +0300 | [diff] [blame] | 292 | // Hard boundary for pad mode, should appear on the right inside the glyph for linear and radial. |
| 293 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"COL3"_t, 1.f}, {"COL2"_t, 1.5f}, {"COL1"_t, 2.f}})) |
Dominik Röttsches | 85b2c7d | 2022-10-03 17:31:27 +0300 | [diff] [blame] | 294 | // Extend mode with rotation or skew below. |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 295 | DEF_GM(return F(C(extend_mode), -0.5f, 0.0f, {})) |
| 296 | DEF_GM(return F(C(extend_mode), -0.5f, 20.0f, {})) |
| 297 | DEF_GM(return F(C(extend_mode), 0.0f, 20.0f, {})) |
Dominik Röttsches | a57f08a | 2022-08-12 14:09:02 +0300 | [diff] [blame] | 298 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"COL2"_t, -0.3f}})) |
| 299 | DEF_GM(return F(C(extend_mode), 0.0f, 0.0f, {{"GRR0"_t, 430.f}, {"GRR1"_t, 40.f}})) |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 300 | DEF_GM(return F(C(foreground_color), 0.0f, 0.0f, {})) |
| 301 | DEF_GM(return F(C(gradient_p2_skewed), 0.0f, 0.0f, {})) |
| 302 | DEF_GM(return F(C(gradient_stops_repeat), 0.0f, 0.0f, {})) |
| 303 | DEF_GM(return F(C(gradient_stops_repeat), -0.5f, 0.0f, {})) |
| 304 | DEF_GM(return F(C(gradient_stops_repeat), -0.5f, 20.0f, {})) |
| 305 | DEF_GM(return F(C(gradient_stops_repeat), 0.0f, 20.0f, {})) |
| 306 | DEF_GM(return F(C(paint_rotate), 0.0f, 0.0f, {})) |
Dominik Röttsches | a57f08a | 2022-08-12 14:09:02 +0300 | [diff] [blame] | 307 | DEF_GM(return F(C(paint_rotate), 0.0f, 0.0f, {{"ROTA"_t, 40.f}})) |
| 308 | DEF_GM(return F(C(paint_rotate), 0.0f, 0.0f, {{"ROTX"_t, -250.f}, {"ROTY"_t, -250.f}})) |
| 309 | DEF_GM(return F(C(paint_scale), 0.0f, 0.0f, {})) |
| 310 | DEF_GM(return F(C(paint_scale), 0.0f, 0.0f, {{"SCOX"_t, 200.f}, {"SCOY"_t, 200.f}})) |
| 311 | DEF_GM(return F(C(paint_scale), 0.0f, 0.0f, {{"SCSX"_t, 0.25f}, {"SCOY"_t, 0.25f}})) |
| 312 | DEF_GM(return F(C(paint_scale), 0.0f, 0.0f, {{"SCSX"_t, -1.f}, {"SCOY"_t, -1.f}})) |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 313 | DEF_GM(return F(C(paint_skew), 0.0f, 0.0f, {})) |
Dominik Röttsches | a57f08a | 2022-08-12 14:09:02 +0300 | [diff] [blame] | 314 | DEF_GM(return F(C(paint_skew), 0.0f, 0.0f, {{"SKXA"_t, 20.f}})) |
| 315 | DEF_GM(return F(C(paint_skew), 0.0f, 0.0f, {{"SKYA"_t, 20.f}})) |
| 316 | DEF_GM(return F(C(paint_skew), 0.0f, 0.0f, {{"SKCX"_t, 200.f},{"SKCY"_t, 200.f}})) |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 317 | DEF_GM(return F(C(paint_transform), 0.0f, 0.0f, {})) |
| 318 | DEF_GM(return F(C(paint_translate), 0.0f, 0.0f, {})) |
Dominik Röttsches | a57f08a | 2022-08-12 14:09:02 +0300 | [diff] [blame] | 319 | DEF_GM(return F(C(paint_translate), 0.0f, 0.0f, {{"TLDX"_t, 100.f}, {"TLDY"_t, 100.f}})) |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 320 | DEF_GM(return F(C(sweep_varsweep), 0.0f, 0.0f, {})) |
| 321 | DEF_GM(return F(C(sweep_varsweep), -0.5f, 0.0f, {})) |
| 322 | DEF_GM(return F(C(sweep_varsweep), -0.5f, 20.0f, {})) |
| 323 | DEF_GM(return F(C(sweep_varsweep), 0.0f, 20.0f, {})) |
Dominik Röttsches | 18b0e15 | 2022-08-15 12:01:10 +0300 | [diff] [blame] | 324 | DEF_GM(return F(C(sweep_varsweep), 0.0f, 0.0f, {{"SWPS"_t, 0.f}})) |
| 325 | DEF_GM(return F(C(sweep_varsweep), 0.0f, 0.0f, {{"SWPS"_t, 90.f}})) |
| 326 | DEF_GM(return F(C(sweep_varsweep), 0.0f, 0.0f, {{"SWPE"_t, -90.f}})) |
| 327 | DEF_GM(return F(C(sweep_varsweep), 0.0f, 0.0f, {{"SWPE"_t, -45.f}})) |
| 328 | DEF_GM(return F(C(sweep_varsweep), 0.0f, 0.0f, {{"SWPS"_t, -45.f},{"SWPE"_t, 45.f}})) |
| 329 | DEF_GM(return F(C(sweep_varsweep), |
| 330 | 0.0f, |
| 331 | 0.0f, |
| 332 | {{"SWC1"_t, -0.25f}, |
| 333 | {"SWC2"_t, 0.083333333f}, |
| 334 | {"SWC3"_t, 0.083333333f}, |
| 335 | {"SWC4"_t, +0.25f}})) |
Dominik Röttsches | ebdd78b | 2022-08-11 18:44:40 +0300 | [diff] [blame] | 336 | DEF_GM(return F(C(variable_alpha), 0.0f, 0.0f, {})) |
Dominik Röttsches | a57f08a | 2022-08-12 14:09:02 +0300 | [diff] [blame] | 337 | DEF_GM(return F(C(variable_alpha), 0.0f, 0.0f, {{"APH1"_t, -0.7f}})) |
| 338 | DEF_GM(return F(C(variable_alpha), 0.0f, 0.0f, {{"APH2"_t, -0.7f}, {"APH3"_t, -0.2f}})) |
Dominik Röttsches | ad8cd0e | 2023-12-21 18:36:49 +0200 | [diff] [blame] | 339 | DEF_GM(return F(C(paintcolrglyph_cycle), 0.0f, 0.0f, {})) |
Dominik Röttsches | cf84bab | 2023-12-15 19:10:47 +0200 | [diff] [blame] | 340 | DEF_GM(return F(C(sweep_coincident), 0.0f, 0.0f, {})) |
Dominik Röttsches | 90ce051 | 2024-01-18 17:41:52 +0200 | [diff] [blame] | 341 | DEF_GM(return F(C(paint_glyph_nested), 0.0f, 0.0f, {})) |
Dominik Röttsches | 691a794 | 2021-02-11 21:08:44 +0200 | [diff] [blame] | 342 | |
| 343 | } // namespace skiagm |