02f1bcf6d1
This updates the key builder system so the builder can be used in a tight loop with the memory backing the key being reused. Bug: skia:12701 Change-Id: I79a72ca26570dcfea9aa45b0fbad8e598688ee98 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/510016 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
63 lines
1.6 KiB
C++
63 lines
1.6 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 "experimental/graphite/src/ContextPriv.h"
|
|
|
|
namespace {
|
|
|
|
SkPaintParamsKey create_key(SkPaintParamsKeyBuilder* builder, int dummySnippetID, int size) {
|
|
|
|
SkDEBUGCODE(builder->checkReset());
|
|
|
|
builder->beginBlock(dummySnippetID);
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
builder->addByte(i % 256);
|
|
}
|
|
|
|
builder->endBlock();
|
|
|
|
return builder->lockAsKey();
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
DEF_GRAPHITE_TEST_FOR_CONTEXTS(KeyTest, reporter, context) {
|
|
|
|
auto dict = context->priv().shaderCodeDictionary();
|
|
|
|
SkPaintParamsKeyBuilder builder(dict);
|
|
|
|
static const int kMaxBlockDataSize = SkPaintParamsKey::kMaxBlockSize -
|
|
SkPaintParamsKey::kBlockHeaderSizeInBytes;
|
|
|
|
// invalid code snippet ID
|
|
{
|
|
SkPaintParamsKey key = create_key(&builder, kBuiltInCodeSnippetIDCount, kMaxBlockDataSize);
|
|
REPORTER_ASSERT(reporter, key.isErrorKey());
|
|
}
|
|
|
|
int dummySnippetID = dict->addUserDefinedSnippet();
|
|
|
|
// _Just_ on the edge of being too big
|
|
{
|
|
SkPaintParamsKey key = create_key(&builder, dummySnippetID, kMaxBlockDataSize);
|
|
REPORTER_ASSERT(reporter, key.sizeInBytes() == SkPaintParamsKey::kMaxBlockSize);
|
|
}
|
|
|
|
// Too big
|
|
{
|
|
SkPaintParamsKey key = create_key(&builder, dummySnippetID, 1024);
|
|
REPORTER_ASSERT(reporter, key.isErrorKey());
|
|
}
|
|
}
|