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
8 #include "include/core/SkDeferredDisplayList.h"
9
10 #include "include/core/SkRefCnt.h"
11 #include "include/core/SkTypes.h"
12 #include "src/core/SkArenaAlloc.h"
13 #include <utility>
14 class SkSurfaceCharacterization;
15
16 #if SK_SUPPORT_GPU
17 #include "src/gpu/GrDirectContextPriv.h"
18 #include "src/gpu/GrRenderTask.h"
19 #include "src/gpu/ccpr/GrCCPerOpsTaskPaths.h"
20 #endif
21
SkDeferredDisplayList(const SkSurfaceCharacterization & characterization,sk_sp<GrRenderTargetProxy> targetProxy,sk_sp<LazyProxyData> lazyProxyData)22 SkDeferredDisplayList::SkDeferredDisplayList(const SkSurfaceCharacterization& characterization,
23 sk_sp<GrRenderTargetProxy> targetProxy,
24 sk_sp<LazyProxyData> lazyProxyData)
25 : fCharacterization(characterization)
26 #if SK_SUPPORT_GPU
27 , fArenas(true)
28 , fTargetProxy(std::move(targetProxy))
29 , fLazyProxyData(std::move(lazyProxyData))
30 #endif
31 {
32 #if SK_SUPPORT_GPU
33 SkASSERT(fTargetProxy->isDDLTarget());
34 #endif
35 }
36
~SkDeferredDisplayList()37 SkDeferredDisplayList::~SkDeferredDisplayList() {
38 #if SK_SUPPORT_GPU && defined(SK_DEBUG)
39 for (auto& renderTask : fRenderTasks) {
40 SkASSERT(renderTask->unique());
41 }
42 #endif
43 }
44
45 //-------------------------------------------------------------------------------------------------
46 #if SK_SUPPORT_GPU
47
ProgramIterator(GrDirectContext * dContext,SkDeferredDisplayList * ddl)48 SkDeferredDisplayList::ProgramIterator::ProgramIterator(GrDirectContext* dContext,
49 SkDeferredDisplayList* ddl)
50 : fDContext(dContext)
51 , fProgramData(ddl->programData())
52 , fIndex(0) {
53 }
54
~ProgramIterator()55 SkDeferredDisplayList::ProgramIterator::~ProgramIterator() {}
56
compile()57 bool SkDeferredDisplayList::ProgramIterator::compile() {
58 if (!fDContext || fIndex < 0 || fIndex >= (int) fProgramData.size()) {
59 return false;
60 }
61
62 return fDContext->priv().compile(fProgramData[fIndex].desc(), fProgramData[fIndex].info());
63 }
64
done() const65 bool SkDeferredDisplayList::ProgramIterator::done() const {
66 return fIndex >= (int) fProgramData.size();
67 }
68
next()69 void SkDeferredDisplayList::ProgramIterator::next() {
70 ++fIndex;
71 }
72
73 #endif
74