xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrDeferredDisplayList.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 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 "include/private/chromium/GrDeferredDisplayList.h"
9 
10 #include "include/gpu/ganesh/GrDirectContext.h"
11 #include "src/gpu/ganesh/GrDirectContextPriv.h"
12 #include "src/gpu/ganesh/GrRenderTargetProxy.h"
13 #include "src/gpu/ganesh/GrRenderTask.h"
14 #include "src/gpu/ganesh/surface/SkSurface_Ganesh.h"
15 #include "src/image/SkSurface_Base.h"
16 
17 #include <utility>
18 
GrDeferredDisplayList(const GrSurfaceCharacterization & characterization,sk_sp<GrRenderTargetProxy> targetProxy,sk_sp<LazyProxyData> lazyProxyData)19 GrDeferredDisplayList::GrDeferredDisplayList(const GrSurfaceCharacterization& characterization,
20                                              sk_sp<GrRenderTargetProxy> targetProxy,
21                                              sk_sp<LazyProxyData> lazyProxyData)
22         : fCharacterization(characterization)
23         , fArenas(true)
24         , fTargetProxy(std::move(targetProxy))
25         , fLazyProxyData(std::move(lazyProxyData)) {
26     SkASSERT(fTargetProxy->isDDLTarget());
27 }
28 
~GrDeferredDisplayList()29 GrDeferredDisplayList::~GrDeferredDisplayList() {
30 #if defined(SK_DEBUG)
31     for (auto& renderTask : fRenderTasks) {
32         SkASSERT(renderTask->unique());
33     }
34 #endif
35 }
36 
ProgramIterator(GrDirectContext * dContext,GrDeferredDisplayList * ddl)37 GrDeferredDisplayList::ProgramIterator::ProgramIterator(GrDirectContext* dContext,
38                                                         GrDeferredDisplayList* ddl)
39     : fDContext(dContext)
40     , fProgramData(ddl->programData())
41     , fIndex(0) {
42 }
43 
~ProgramIterator()44 GrDeferredDisplayList::ProgramIterator::~ProgramIterator() {}
45 
compile()46 bool GrDeferredDisplayList::ProgramIterator::compile() {
47     if (!fDContext || fIndex < 0 || fIndex >= (int) fProgramData.size()) {
48         return false;
49     }
50 
51     return fDContext->priv().compile(fProgramData[fIndex].desc(), fProgramData[fIndex].info());
52 }
53 
done() const54 bool GrDeferredDisplayList::ProgramIterator::done() const {
55     return fIndex >= (int) fProgramData.size();
56 }
57 
next()58 void GrDeferredDisplayList::ProgramIterator::next() {
59     ++fIndex;
60 }
61 
62 namespace skgpu::ganesh {
63 
DrawDDL(SkSurface * surface,sk_sp<const GrDeferredDisplayList> ddl)64 bool DrawDDL(SkSurface* surface, sk_sp<const GrDeferredDisplayList> ddl) {
65     if (!surface || !ddl) {
66         return false;
67     }
68     auto sb = asSB(surface);
69     if (!sb->isGaneshBacked()) {
70         return false;
71     }
72     auto gs = static_cast<SkSurface_Ganesh*>(surface);
73     return gs->draw(ddl);
74 }
75 
DrawDDL(sk_sp<SkSurface> surface,sk_sp<const GrDeferredDisplayList> ddl)76 bool DrawDDL(sk_sp<SkSurface> surface, sk_sp<const GrDeferredDisplayList> ddl) {
77     return DrawDDL(surface.get(), ddl);
78 }
79 
80 }
81