skia2/tests/graphite/KeyTest.cpp
Robert Phillips b2e3f57866 [graphite] Pull the ShaderType enum out of the ShaderCombo
The ShaderType enum seems like it will persist while the ShaderCombo will not.

Bug: skia:12701
Change-Id: Idf9ed89a50bac46b93a81da3e814207c83b3a1ea
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541723
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
2022-05-20 14:48:11 +00:00

81 lines
2.5 KiB
C++

/*
* Copyright 2022 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 "src/core/SkPaintParamsKey.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/gpu/graphite/ContextPriv.h"
namespace {
SkPaintParamsKey create_key(SkPaintParamsKeyBuilder* builder, int dummySnippetID, int size) {
SkASSERT(size <= 1024);
static const uint8_t kDummyData[1024] = { 0 };
SkDEBUGCODE(builder->checkReset());
builder->beginBlock(dummySnippetID);
builder->addBytes(size, kDummyData);
builder->endBlock();
return builder->lockAsKey();
}
} // anonymous namespace
// This is intended to be a unit test of the SkPaintParamsKeyBuilder and SkPaintParamsKey.
DEF_GRAPHITE_TEST_FOR_CONTEXTS(KeyTest, reporter, context) {
auto dict = context->priv().shaderCodeDictionary();
SkPaintParamsKeyBuilder builder(dict, SkBackend::kGraphite);
// invalid code snippet ID
{
SkPaintParamsKey key = create_key(&builder, kBuiltInCodeSnippetIDCount, 32);
// key creation fails
REPORTER_ASSERT(reporter, key.isErrorKey());
}
// _Just_ on the edge of being too big
{
static const int kMaxBlockDataSize = SkPaintParamsKey::kMaxBlockSize -
SkPaintParamsKey::kBlockHeaderSizeInBytes;
static constexpr int kNumFields1 = 1;
static constexpr SkPaintParamsKey::DataPayloadField kDataFields1[kNumFields1] = {
{ "data", SkPaintParamsKey::DataPayloadType::kByte, kMaxBlockDataSize },
};
int dummySnippetID1 = dict->addUserDefinedSnippet("keyAlmostTooBig",
SkMakeSpan(kDataFields1, kNumFields1));
SkPaintParamsKey key = create_key(&builder, dummySnippetID1, kMaxBlockDataSize);
REPORTER_ASSERT(reporter, key.sizeInBytes() == SkPaintParamsKey::kMaxBlockSize);
}
// Too big
{
static constexpr int kNumFields2 = 1;
static constexpr SkPaintParamsKey::DataPayloadField kDataFields2[kNumFields2] = {
{ "data", SkPaintParamsKey::DataPayloadType::kByte, 1024 },
};
int dummySnippetID2 = dict->addUserDefinedSnippet("keyTooBig",
SkMakeSpan(kDataFields2, kNumFields2));
SkPaintParamsKey key = create_key(&builder, dummySnippetID2, 1024);
// key creation fails
REPORTER_ASSERT(reporter, key.isErrorKey());
}
}