Debian Codegraph @

tools/graphite/PipelineCallbackHandler.cpp

raw
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/PipelineCallbackHandler.h"
9
10 #include <algorithm>
11
12 namespace skiatools::graphite {
13
14 void PipelineCallBackHandler::add(skgpu::graphite::ContextOptions::PipelineCacheOp op,
15 const std::string& label,
16 uint32_t uniqueKeyHash,
17 bool fromPrecompile,
18 sk_sp<SkData> androidStyleKey) {
19 SkAutoSpinlock lock{ fSpinLock };
20
21 std::unique_ptr<PipelineData>* foundData = fMap.find({ &label, uniqueKeyHash });
22 if (foundData) {
23 if (op == skgpu::graphite::ContextOptions::PipelineCacheOp::kPipelineFound) {
24 (*foundData)->fUses++;
25 }
26 } else {
27 SkASSERT(op == skgpu::graphite::ContextOptions::PipelineCacheOp::kAddingPipeline);
28
29 std::unique_ptr<PipelineData> newData = std::make_unique<PipelineData>(
30 label, uniqueKeyHash, fromPrecompile, std::move(androidStyleKey));
31
32 fMap.set(std::move(newData));
33 }
34 }
35
36 void PipelineCallBackHandler::report() {
37 // The assumption is that we're just doing this once at the end so we just lock for the
38 // entire method.
39 SkAutoSpinlock lock{ fSpinLock };
40
41 std::vector<const PipelineData*> tmp;
42
43 tmp.reserve(fMap.count());
44 fMap.foreach([&tmp](std::unique_ptr<PipelineData>* data) -> void {
45 tmp.push_back((*data).get());
46 });
47
48 std::sort(tmp.begin(), tmp.end(), [](const PipelineData* a, const PipelineData* b) {
49 if (a->fUses != b->fUses) {
50 return a->fUses > b->fUses;
51 }
52 return a->fLabel < b->fLabel;
53 });
54
55 for (const PipelineData* data : tmp) {
56 if (data->fFromPrecompile && !data->fUses) {
57 SkDebugf("!! "); // A needless precompiled Pipeline
58 }
59 SkDebugf("%u %s\n", data->fUses, data->fLabel.c_str());
60 }
61 }
62
63 } // namespace skiatools::graphite