Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrDDLContext.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google Inc.
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
10#include "src/core/SkLRUCache.h"
17
18using namespace skia_private;
19
20/**
21 * The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and
22 * cannot allocate any GPU resources.
23 */
24class GrDDLContext final : public GrRecordingContext {
25public:
29
30 ~GrDDLContext() override {}
31
32 void abandonContext() override {
33 SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
35 }
36
37private:
38 // Add to the set of unique program infos required by this DDL
39 void recordProgramInfo(const GrProgramInfo* programInfo) final {
40 if (!programInfo) {
41 return;
42 }
43
44 const GrCaps* caps = this->caps();
45
46 if (this->backend() == GrBackendApi::kMetal || this->backend() == GrBackendApi::kDirect3D) {
47 // Currently Metal and Direct3D require a live renderTarget to compute the key
48 return;
49 }
50
51 GrProgramDesc desc = caps->makeDesc(nullptr, *programInfo);
52 if (!desc.isValid()) {
53 return;
54 }
55
56 fProgramInfoMap.add(desc, programInfo);
57 }
58
60 SkASSERT(dst->empty());
61
62 fProgramInfoMap.toArray(dst);
63 }
64
65
66private:
67 class ProgramInfoMap : public ::SkNoncopyable {
68 typedef const GrProgramDesc CacheKey;
69 typedef const GrProgramInfo* CacheValue;
70
71 public:
72 // All the programInfo data should be stored in the record-time arena so there is no
73 // need to ref them here or to delete them in the destructor.
74 ProgramInfoMap() : fMap(10) {}
75 ~ProgramInfoMap() {}
76
77 // TODO: this is doing a lot of reallocating of the ProgramDesc! Once the program descs
78 // are allocated in the record-time area there won't be a problem.
79 void add(CacheKey& desc, const GrProgramInfo* programInfo) {
80 SkASSERT(desc.isValid());
81
82 const CacheValue* preExisting = fMap.find(desc);
83 if (preExisting) {
84 return;
85 }
86
87 fMap.insert(desc, programInfo);
88 }
89
90 void toArray(TArray<ProgramData>* dst) {
91 fMap.foreach([dst](CacheKey* programDesc, CacheValue* programInfo) {
92 // TODO: remove this allocation once the program descs are stored
93 // in the record-time arena.
94 dst->emplace_back(std::make_unique<const GrProgramDesc>(*programDesc),
95 *programInfo);
96 });
97 }
98
99 private:
100 struct DescHash {
101 uint32_t operator()(CacheKey& desc) const {
102 return SkChecksum::Hash32(desc.asKey(), desc.keyLength());
103 }
104 };
105
107 };
108
109 ProgramInfoMap fProgramInfoMap;
110
111 using INHERITED = GrRecordingContext;
112};
113
115 sk_sp<GrRecordingContext> context(new GrDDLContext(std::move(proxy)));
116
117 if (!context->init()) {
118 return nullptr;
119 }
120 return context;
121}
#define SkASSERT(cond)
Definition SkAssert.h:116
virtual GrProgramDesc makeDesc(GrRenderTarget *, const GrProgramInfo &, ProgramDescOverrideFlags overrideFlags=ProgramDescOverrideFlags::kNone) const =0
const GrCaps * caps() const
SK_API GrBackendApi backend() const
~GrDDLContext() override
void detachProgramData(TArray< ProgramData > *dst) final
GrDDLContext(sk_sp< GrContextThreadSafeProxy > proxy)
void recordProgramInfo(const GrProgramInfo *programInfo) final
void abandonContext() override
static sk_sp< GrRecordingContext > MakeDDL(sk_sp< GrContextThreadSafeProxy >)
GrRecordingContext * context()
void abandonContext() override
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
dst
Definition cp.py:12
Definition ref_ptr.h:256