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 #endif
20
SkDeferredDisplayList(const SkSurfaceCharacterization & characterization,sk_sp<GrRenderTargetProxy> targetProxy,sk_sp<LazyProxyData> lazyProxyData)21 SkDeferredDisplayList::SkDeferredDisplayList(const SkSurfaceCharacterization& characterization,
22 sk_sp<GrRenderTargetProxy> targetProxy,
23 sk_sp<LazyProxyData> lazyProxyData)
24 : fCharacterization(characterization)
25 #if SK_SUPPORT_GPU
26 , fArenas(true)
27 , fTargetProxy(std::move(targetProxy))
28 , fLazyProxyData(std::move(lazyProxyData))
29 #endif
30 {
31 #if SK_SUPPORT_GPU
32 SkASSERT(fTargetProxy->isDDLTarget());
33 #endif
34 }
35
~SkDeferredDisplayList()36 SkDeferredDisplayList::~SkDeferredDisplayList() {
37 #if SK_SUPPORT_GPU && defined(SK_DEBUG)
38 for (auto& renderTask : fRenderTasks) {
39 SkASSERT(renderTask->unique());
40 }
41 #endif
42 }
43
44 //-------------------------------------------------------------------------------------------------
45 #if SK_SUPPORT_GPU
46
ProgramIterator(GrDirectContext * dContext,SkDeferredDisplayList * ddl)47 SkDeferredDisplayList::ProgramIterator::ProgramIterator(GrDirectContext* dContext,
48 SkDeferredDisplayList* ddl)
49 : fDContext(dContext)
50 , fProgramData(ddl->programData())
51 , fIndex(0) {
52 }
53
~ProgramIterator()54 SkDeferredDisplayList::ProgramIterator::~ProgramIterator() {}
55
compile()56 bool SkDeferredDisplayList::ProgramIterator::compile() {
57 if (!fDContext || fIndex < 0 || fIndex >= (int) fProgramData.size()) {
58 return false;
59 }
60
61 return fDContext->priv().compile(fProgramData[fIndex].desc(), fProgramData[fIndex].info());
62 }
63
done() const64 bool SkDeferredDisplayList::ProgramIterator::done() const {
65 return fIndex >= (int) fProgramData.size();
66 }
67
next()68 void SkDeferredDisplayList::ProgramIterator::next() {
69 ++fIndex;
70 }
71
72 #endif
73