cc4d21f980
Since the SkShaders, etc will need access to SkPaintParamKeys and the SkShaderCodeDictionary they can't be buried in the skgpu namespace. The currently planned signature for addToKey is: void addToKey(SkShaderCodeDictionary*, SkBackend, SkPaintParamsKey*) const; This CL doesn't modify the classes beyond what is needed to move them. Bug: skia:12701 Change-Id: I18bbf6d6c3a768427112a3d19a9ccf2d46a23ad2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/494237 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
102 lines
3.9 KiB
C++
102 lines
3.9 KiB
C++
/*
|
|
* Copyright 2021 Google LLC
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "experimental/graphite/src/ContextPriv.h"
|
|
#include "experimental/graphite/src/ContextUtils.h"
|
|
#include "experimental/graphite/src/PaintParams.h"
|
|
#include "include/core/SkPaint.h"
|
|
#include "include/effects/SkGradientShader.h"
|
|
#include "include/private/SkShaderCodeDictionary.h"
|
|
#include "include/private/SkUniquePaintParamsID.h"
|
|
#include "src/core/SkKeyHelpers.h"
|
|
|
|
namespace {
|
|
|
|
std::tuple<SkPaint, int> create_paint(skgpu::ShaderCombo::ShaderType shaderType,
|
|
SkTileMode tm,
|
|
SkBlendMode bm) {
|
|
SkPoint pts[2] = {{-100, -100},
|
|
{100, 100}};
|
|
SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN};
|
|
SkScalar offsets[2] = {0.0f, 1.0f};
|
|
|
|
sk_sp<SkShader> s;
|
|
int numUniforms = 0;
|
|
switch (shaderType) {
|
|
case skgpu::ShaderCombo::ShaderType::kNone:
|
|
SkDEBUGFAIL("kNone cannot be represented as an SkPaint");
|
|
break;
|
|
case skgpu::ShaderCombo::ShaderType::kSolidColor:
|
|
numUniforms += 1;
|
|
break;
|
|
case skgpu::ShaderCombo::ShaderType::kLinearGradient:
|
|
s = SkGradientShader::MakeLinear(pts, colors, offsets, 2, tm);
|
|
numUniforms += 6;
|
|
break;
|
|
case skgpu::ShaderCombo::ShaderType::kRadialGradient:
|
|
s = SkGradientShader::MakeRadial({0, 0}, 100, colors, offsets, 2, tm);
|
|
numUniforms += 6;
|
|
break;
|
|
case skgpu::ShaderCombo::ShaderType::kSweepGradient:
|
|
s = SkGradientShader::MakeSweep(0, 0, colors, offsets, 2, tm,
|
|
0, 359, 0, nullptr);
|
|
numUniforms += 6;
|
|
break;
|
|
case skgpu::ShaderCombo::ShaderType::kConicalGradient:
|
|
s = SkGradientShader::MakeTwoPointConical({100, 100}, 100,
|
|
{-100, -100}, 100,
|
|
colors, offsets, 2, tm);
|
|
numUniforms += 6;
|
|
break;
|
|
}
|
|
SkPaint p;
|
|
p.setColor(SK_ColorRED);
|
|
p.setShader(std::move(s));
|
|
p.setBlendMode(bm);
|
|
return { p, numUniforms };
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
DEF_GRAPHITE_TEST_FOR_CONTEXTS(UniformTest, reporter, context) {
|
|
using namespace skgpu;
|
|
|
|
// Intentionally does not include ShaderType::kNone, which represents no fragment shading stage
|
|
// and is thus not relevant to uniform extraction/caching.
|
|
for (auto s : { ShaderCombo::ShaderType::kSolidColor,
|
|
ShaderCombo::ShaderType::kLinearGradient,
|
|
ShaderCombo::ShaderType::kRadialGradient,
|
|
ShaderCombo::ShaderType::kSweepGradient,
|
|
ShaderCombo::ShaderType::kConicalGradient }) {
|
|
for (auto tm: { SkTileMode::kClamp,
|
|
SkTileMode::kRepeat,
|
|
SkTileMode::kMirror,
|
|
SkTileMode::kDecal }) {
|
|
if (s == ShaderCombo::ShaderType::kSolidColor) {
|
|
tm = SkTileMode::kClamp; // the TileMode doesn't matter for this case
|
|
}
|
|
|
|
for (auto bm : { SkBlendMode::kSrc, SkBlendMode::kSrcOver }) {
|
|
SkPaintParamsKey expected = CreateKey(s, tm, bm);
|
|
|
|
auto [ p, expectedNumUniforms ] = create_paint(s, tm, bm);
|
|
auto [ actualID, ud] = ExtractPaintData(context, PaintParams(p));
|
|
|
|
auto entry = context->priv().shaderCodeDictionary()->lookup(actualID);
|
|
|
|
REPORTER_ASSERT(reporter, expected == entry->paintParamsKey());
|
|
REPORTER_ASSERT(reporter, expectedNumUniforms == ud->count());
|
|
for (int i = 0; i < ud->count(); ++i) {
|
|
REPORTER_ASSERT(reporter, ud->offset(i) >= 0 && ud->offset(i) < ud->dataSize());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|