| 1 |
/* |
| 2 |
* Copyright 2025 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "tools/graphite/GraphiteMemoryPipelineStorage.h" |
| 9 |
|
| 10 |
// Define this to log data loads and stores using SkDebugf. |
| 11 |
// #define LOG_MEMORY_CACHE |
| 12 |
|
| 13 |
#if defined(LOG_MEMORY_CACHE) |
| 14 |
#include "include/core/SkString.h" |
| 15 |
#include "src/base/SkBase64.h" |
| 16 |
|
| 17 |
static SkString data_to_str(const SkData& data) { |
| 18 |
size_t encodeLength = SkBase64::EncodedSize(data.size()); |
| 19 |
SkString str; |
| 20 |
str.resize(encodeLength); |
| 21 |
SkBase64::Encode(data.data(), data.size(), str.data()); |
| 22 |
static constexpr size_t kMaxLength = 60; |
| 23 |
static constexpr char kTail[] = "..."; |
| 24 |
static const size_t kTailLen = strlen(kTail); |
| 25 |
bool overlength = encodeLength > kMaxLength; |
| 26 |
if (overlength) { |
| 27 |
str = SkString(str.c_str(), kMaxLength - kTailLen); |
| 28 |
str.append(kTail); |
| 29 |
} |
| 30 |
return str; |
| 31 |
} |
| 32 |
#endif |
| 33 |
|
| 34 |
namespace sk_gpu_test { |
| 35 |
|
| 36 |
sk_sp<SkData> GraphiteMemoryPipelineStorage::load() { |
| 37 |
if (!fData) { |
| 38 |
#if defined(LOG_MEMORY_CACHE) |
| 39 |
SkDebugf("No data to load\n"); |
| 40 |
#endif |
| 41 |
return nullptr; |
| 42 |
} |
| 43 |
|
| 44 |
#if defined(LOG_MEMORY_CACHE) |
| 45 |
SkDebugf("Loading data: %zu %s\n", fData->size(), data_to_str(*fData).c_str()); |
| 46 |
#endif |
| 47 |
|
| 48 |
++fLoadCount; |
| 49 |
return fData; |
| 50 |
} |
| 51 |
|
| 52 |
void GraphiteMemoryPipelineStorage::store(const SkData& data) { |
| 53 |
#if defined(LOG_MEMORY_CACHE) |
| 54 |
SkDebugf("Storing data: %zu %s\n", data.size(), data_to_str(data).c_str()); |
| 55 |
#endif |
| 56 |
|
| 57 |
++fStoreCount; |
| 58 |
fData = SkData::MakeWithCopy(data.data(), data.size()); |
| 59 |
} |
| 60 |
|
| 61 |
} // namespace sk_gpu_test |