[graphite] Use SkTDArray in SkPaintParamsKeyBuilder

SkTArray::reset() got rid of any reserved space, so previously we never
actually got to a high-water allocation. Updated the stack to use
SkTDArray just for consistency so we only had to include that instead of
<vector>, too.

Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac-Clang-arm64-Debug-ASAN_Graphite,Build-Mac-Clang-arm64-Debug-Graphite,Build-Mac-Clang-arm64-Debug-Graphite_NoGpu,Build-Mac-Clang-arm64-Debug-iOS_Graphite,Build-Mac-Clang-arm64-Release-Graphite,Build-Mac-Clang-arm64-Release-iOS_Graphite,Build-Mac-Clang-x86_64-Debug-Graphite,Build-Mac-Clang-x86_64-Release-Graphite,Perf-Mac10.15.7-Clang-MacBookPro11.5-GPU-RadeonHD8870M-x86_64-Release-All-Graphite,Perf-Mac11-Clang-MacMini9.1-GPU-AppleM1-arm64-Release-All-Graphite,Test-Mac11-Clang-MacMini9.1-GPU-AppleM1-arm64-Debug-All-ASAN_Graphite,Test-Mac10.15.7-Clang-MacBookPro11.5-GPU-RadeonHD8870M-x86_64-Debug-All-Graphite,Test-Mac11-Clang-MacMini9.1-GPU-AppleM1-arm64-Release-All-Graphite,Test-Mac12-Clang-MacBookPro16.2-GPU-IntelIrisPlus-x86_64-Debug-All-Graphite
Change-Id: I94c9a38d0e630c7d7f1a3eeeb85076067e066a2f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/524000
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
Michael Ludwig 2022-03-23 16:36:14 -04:00 committed by SkCQ
parent 6ccc3b0658
commit f3539b6c47
3 changed files with 18 additions and 20 deletions

View File

@ -33,11 +33,8 @@ public:
constexpr SkSpan(const SkSpan<U>& that) : fPtr(that.data()), fSize{that.size()} {}
constexpr SkSpan(const SkSpan& o) = default;
constexpr SkSpan& operator=(const SkSpan& that) {
fPtr = that.fPtr;
fSize = that.fSize;
return *this;
}
constexpr SkSpan& operator=(const SkSpan& that) = default;
constexpr T& operator [] (size_t i) const {
SkASSERT(i < this->size());
return fPtr[i];

View File

@ -58,7 +58,6 @@ void SkPaintParamsKeyBuilder::beginBlock(int codeSnippetID) {
SkASSERT(!this->isLocked());
fData.reserve_back(SkPaintParamsKey::kBlockHeaderSizeInBytes);
fStack.push_back({ codeSnippetID, this->sizeInBytes(),
SkDEBUGCODE(kHeaderExpectations, 0) });
@ -102,7 +101,7 @@ void SkPaintParamsKeyBuilder::endBlock() {
fData[headerOffset+SkPaintParamsKey::kBlockSizeOffsetInBytes] = blockSize;
fStack.pop_back();
fStack.pop();
#ifdef SK_DEBUG
if (!fStack.empty()) {
@ -140,7 +139,7 @@ void SkPaintParamsKeyBuilder::addBytes(uint32_t numBytes, const uint8_t* data) {
SkASSERT(!this->isLocked());
fData.push_back_n(numBytes, data);
fData.append(numBytes, data);
}
SkPaintParamsKey SkPaintParamsKeyBuilder::lockAsKey() {
@ -154,17 +153,17 @@ SkPaintParamsKey SkPaintParamsKeyBuilder::lockAsKey() {
// Partially reset for reuse. Note that the key resulting from this call will be holding a lock
// on this builder and must be deleted before this builder is fully reset.
fIsValid = true;
fStack.clear();
fStack.rewind();
return SkPaintParamsKey(SkMakeSpan(fData.data(), fData.count()), this);
return SkPaintParamsKey(SkMakeSpan(fData.begin(), fData.count()), this);
}
void SkPaintParamsKeyBuilder::makeInvalid() {
SkASSERT(fIsValid);
SkASSERT(!this->isLocked());
fStack.clear();
fData.reset();
fStack.rewind();
fData.rewind();
this->beginBlock(SkBuiltInCodeSnippetID::kError);
this->endBlock();

View File

@ -10,12 +10,11 @@
#include "include/core/SkSpan.h"
#include "include/core/SkTypes.h"
#include "include/private/SkTArray.h"
#include "include/private/SkTDArray.h"
#include "src/core/SkBuiltInCodeSnippetID.h"
#include <array>
#include <limits>
#include <vector>
enum class SkBackend : uint8_t {
kGanesh,
@ -195,7 +194,7 @@ public:
void unlock() {
SkASSERT(fLocked);
fData.reset();
fData.rewind();
SkDEBUGCODE(fLocked = false;)
SkDEBUGCODE(this->checkReset();)
}
@ -215,15 +214,18 @@ private:
#endif
};
bool fIsValid = true;
const SkShaderCodeDictionary* fDict;
const SkBackend fBackend;
std::vector<StackFrame> fStack;
// TODO: It is probably overkill but we could encode the SkBackend in the first byte of
// the key.
const SkBackend fBackend;
bool fIsValid = true;
SkDEBUGCODE(bool fLocked = false;)
SkTArray<uint8_t, true> fData;
// Use SkTDArray so that we can guarantee that rewind() preserves the underlying storage and
// repeated use of the builder will hit a high-water mark and avoid lots of allocations.
SkTDArray<StackFrame> fStack;
SkTDArray<uint8_t> fData;
};
#endif // SkPaintParamsKey_DEFINED