[graphite] Add SkTileModeToStr

This is to be used in the PaintParamKey's block dumping methods.

Bug: skia:12701
Change-Id: I14de21d2d8b30e0fa69ac2e33fa975dc20f6656c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/493217
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2022-01-11 10:41:44 -05:00 committed by SkCQ
parent 41e994f735
commit bf489abbf6
6 changed files with 63 additions and 38 deletions

View File

@ -9,6 +9,7 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkGradientShader.h"
#include "src/core/SkDebugUtils.h"
#include "src/core/SkTLazy.h"
#include "tools/flags/CommandLineFlags.h"
@ -95,11 +96,7 @@ static void logLinearGradient(const SkPoint pts[2],
}
SkDebugf("]\n");
static const char* gModeName[] = {
"kClamp_TileMode", "kRepeat_TileMode", "kMirror_TileMode", "kDecal_TileMode"
};
SkASSERT((unsigned)mode < SK_ARRAY_COUNT(gModeName));
SkDebugf(" mode:\t\t%s\n", gModeName[(unsigned)mode]);
SkDebugf(" mode:\t\t%s\n", SkTileModeToStr(mode));
SkDebugf(" flags:\t0x%x\n", flags);
logOptionalMatrix("local matrix", localMatrix);
logOptionalMatrix("global matrix", globalMatrix);

View File

@ -388,7 +388,7 @@ static DrawResult do_very_large_blur_gm(GrRecordingContext* rContext,
int x = 10;
int y = 10;
for (auto blurDirs : {0b01, 0b10, 0b11}) {
for (int t = 0; t <= static_cast<int>(SkTileMode::kLastTileMode); ++t) {
for (int t = 0; t < kSkTileModeCount; ++t) {
auto tm = static_cast<SkTileMode>(t);
auto dstB = srcB.makeOutset(30, 30);
for (float sigma : {0.f, 5.f, 25.f, 80.f}) {

View File

@ -176,6 +176,7 @@ skia_core_sources = [
"$_src/core/SkData.cpp",
"$_src/core/SkDataTable.cpp",
"$_src/core/SkDebug.cpp",
"$_src/core/SkDebugUtils.h",
"$_src/core/SkDeferredDisplayList.cpp",
"$_src/core/SkDeferredDisplayListPriv.h",
"$_src/core/SkDeferredDisplayListRecorder.cpp",

23
src/core/SkDebugUtils.h Normal file
View File

@ -0,0 +1,23 @@
/*
* Copyright 2022 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkDebugUtils_DEFINED
#define SkDebugUtils_DEFINED
#include "include/core/SkTileMode.h"
static constexpr const char* SkTileModeToStr(SkTileMode tm) {
switch (tm) {
case SkTileMode::kClamp: return "Clamp";
case SkTileMode::kRepeat: return "Repeat";
case SkTileMode::kMirror: return "Mirror";
case SkTileMode::kDecal: return "Decal";
}
SkUNREACHABLE;
}
#endif // SkDebugUtils_DEFINED

View File

@ -63,17 +63,41 @@ private:
using INHERITED = SkXfermode;
};
const char* SkBlendMode_Name(SkBlendMode mode) {
SkASSERT((unsigned) mode <= (unsigned)SkBlendMode::kLastMode);
const char* gModeStrings[] = {
"Clear", "Src", "Dst", "SrcOver", "DstOver", "SrcIn", "DstIn",
"SrcOut", "DstOut", "SrcATop", "DstATop", "Xor", "Plus",
"Modulate", "Screen", "Overlay", "Darken", "Lighten", "ColorDodge",
"ColorBurn", "HardLight", "SoftLight", "Difference", "Exclusion",
"Multiply", "Hue", "Saturation", "Color", "Luminosity"
};
return gModeStrings[(int)mode];
static_assert(SK_ARRAY_COUNT(gModeStrings) == (size_t)SkBlendMode::kLastMode + 1, "mode_count");
const char* SkBlendMode_Name(SkBlendMode bm) {
switch (bm) {
case SkBlendMode::kClear: return "Clear";
case SkBlendMode::kSrc: return "Src";
case SkBlendMode::kDst: return "Dst";
case SkBlendMode::kSrcOver: return "SrcOver";
case SkBlendMode::kDstOver: return "DstOver";
case SkBlendMode::kSrcIn: return "SrcIn";
case SkBlendMode::kDstIn: return "DstIn";
case SkBlendMode::kSrcOut: return "SrcOut";
case SkBlendMode::kDstOut: return "DstOut";
case SkBlendMode::kSrcATop: return "SrcATop";
case SkBlendMode::kDstATop: return "DstATop";
case SkBlendMode::kXor: return "Xor";
case SkBlendMode::kPlus: return "Plus";
case SkBlendMode::kModulate: return "Modulate";
case SkBlendMode::kScreen: return "Screen";
case SkBlendMode::kOverlay: return "Overlay";
case SkBlendMode::kDarken: return "Darken";
case SkBlendMode::kLighten: return "Lighten";
case SkBlendMode::kColorDodge: return "ColorDodge";
case SkBlendMode::kColorBurn: return "ColorBurn";
case SkBlendMode::kHardLight: return "HardLight";
case SkBlendMode::kSoftLight: return "SoftLight";
case SkBlendMode::kDifference: return "Difference";
case SkBlendMode::kExclusion: return "Exclusion";
case SkBlendMode::kMultiply: return "Multiply";
case SkBlendMode::kHue: return "Hue";
case SkBlendMode::kSaturation: return "Saturation";
case SkBlendMode::kColor: return "Color";
case SkBlendMode::kLuminosity: return "Luminosity";
}
SkUNREACHABLE;
}
sk_sp<SkXfermode> SkXfermode::Make(SkBlendMode mode) {
@ -149,4 +173,3 @@ const GrXPFactory* SkBlendMode_AsXPFactory(SkBlendMode mode) {
return GrCustomXfermode::Get(mode);
}
#endif

View File

@ -362,29 +362,10 @@ void render_shadow(SkCanvas* canvas, const SkPath& path, SkDrawShadowRec rec) {
canvas->private_draw_shadow_rec(path, rec);
}
static const char* const gBlendModeMap[] = {
"clear", "src", "dst", "srcOver", "dstOver", "srcIn", "dstIn",
"srcOut", "dstOut", "srcATop", "dstATop", "xor", "plus", "modulate",
"screen",
"overlay", "darken", "lighten", "colorDodge", "colorBurn", "hardLight", "softLight",
"difference", "exclusion", "multiply",
"hue", "saturation", "color", "luminosity",
};
static_assert(SK_ARRAY_COUNT(gBlendModeMap) == static_cast<size_t>(SkBlendMode::kLastMode) + 1,
"blendMode mismatch");
static_assert(SK_ARRAY_COUNT(gBlendModeMap) == static_cast<size_t>(SkBlendMode::kLuminosity) + 1,
"blendMode mismatch");
void apply_paint_blend_mode(const SkPaint& paint, SkJSONWriter& writer) {
const auto mode = paint.getBlendMode_or(SkBlendMode::kSrcOver);
if (mode != SkBlendMode::kSrcOver) {
SkASSERT(static_cast<size_t>(mode) < SK_ARRAY_COUNT(gBlendModeMap));
writer.appendString(DEBUGCANVAS_ATTRIBUTE_BLENDMODE,
gBlendModeMap[static_cast<size_t>(mode)]);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_BLENDMODE, SkBlendMode_Name(mode));
}
}