Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6b95516

Browse files
lhkbobSkia Commit-Bot
authored andcommitted
Detach op memory pool from recording context
This changes GrOpMemoryPool to no longer extend SkRefCnt, and all usages either are std::unique_ptr for owners, or GrOpMemoryPool* when ownership is held somewhere else. The culmination of this is that DDLs explicitly detach the memory pool from the recording context instead of the GrOpsTask maintaining a strong ref that preserved the memory somewhat sneakily. Change-Id: I33e2caebea70cebe8fd7681207c631feeaf2c703 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259424 Commit-Queue: Michael Ludwig <michaelludwig@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
1 parent b79f1b5 commit 6b95516

13 files changed

+44
-45
lines changed

include/private/GrRecordingContext.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ class GrRecordingContext : public GrImageContext {
5454

5555
GrDrawingManager* drawingManager();
5656

57-
sk_sp<GrOpMemoryPool> refOpMemoryPool();
5857
GrOpMemoryPool* opMemoryPool();
58+
// This entry point should only be used for DDL creation where we want the ops' lifetime to
59+
// match that of the DDL.
60+
std::unique_ptr<GrOpMemoryPool> detachOpMemoryPool();
5961

6062
SkArenaAlloc* recordTimeAllocator();
6163
// This entry point should only be used for DDL creation where we want the ops' data's lifetime
@@ -148,7 +150,7 @@ class GrRecordingContext : public GrImageContext {
148150
private:
149151
std::unique_ptr<GrDrawingManager> fDrawingManager;
150152
// All the GrOp-derived classes use this pool.
151-
sk_sp<GrOpMemoryPool> fOpMemoryPool;
153+
std::unique_ptr<GrOpMemoryPool> fOpMemoryPool;
152154
std::unique_ptr<SkArenaAlloc> fRecordTimeAllocator;
153155

154156
std::unique_ptr<GrStrikeCache> fStrikeCache;

include/private/SkDeferredDisplayList.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class SkDeferredDisplayListPriv;
1717
#if SK_SUPPORT_GPU
1818
#include "include/private/SkTArray.h"
1919
#include <map>
20+
class GrOpMemoryPool;
2021
class GrRenderTask;
2122
class GrRenderTargetProxy;
2223
struct GrCCPerOpsTaskPaths;
@@ -79,6 +80,7 @@ class SkDeferredDisplayList {
7980

8081
SkTArray<sk_sp<GrRenderTask>> fRenderTasks;
8182
PendingPathsMap fPendingPaths; // This is the path data from CCPR.
83+
std::unique_ptr<GrOpMemoryPool> fOpMemoryPool;
8284
std::unique_ptr<SkArenaAlloc> fRecordTimeData;
8385

8486
// The program infos should be stored in 'fRecordTimeData' so do not need to be ref counted

src/atlastext/SkAtlasTextTarget.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ class SkInternalAtlasTextTarget : public GrTextTarget, public SkAtlasTextTarget
8585
void* handle)
8686
: GrTextTarget(width, height, kColorInfo)
8787
, SkAtlasTextTarget(std::move(context), width, height, handle)
88-
, fGlyphPainter(kProps, kColorInfo) {
89-
fOpMemoryPool = fContext->internal().grContext()->priv().refOpMemoryPool();
90-
}
88+
, fGlyphPainter(kProps, kColorInfo) {}
9189

9290
~SkInternalAtlasTextTarget() override {
9391
this->deleteOps();
@@ -124,11 +122,14 @@ class SkInternalAtlasTextTarget : public GrTextTarget, public SkAtlasTextTarget
124122
private:
125123
void deleteOps();
126124

125+
GrOpMemoryPool* opMemoryPool() {
126+
return fContext->internal().grContext()->priv().opMemoryPool();
127+
}
128+
127129
uint32_t fColor;
128130
using SkAtlasTextTarget::fWidth;
129131
using SkAtlasTextTarget::fHeight;
130132
SkTArray<std::unique_ptr<GrAtlasTextOp>, true> fOps;
131-
sk_sp<GrOpMemoryPool> fOpMemoryPool;
132133
SkGlyphRunListPainter fGlyphPainter;
133134
};
134135

@@ -175,10 +176,12 @@ void SkInternalAtlasTextTarget::addDrawOp(const GrClip& clip, std::unique_ptr<Gr
175176
const GrCaps& caps = *this->context()->internal().grContext()->priv().caps();
176177
op->finalizeForTextTarget(fColor, caps);
177178
int n = SkTMin(kMaxBatchLookBack, fOps.count());
179+
180+
GrOpMemoryPool* pool = this->opMemoryPool();
178181
for (int i = 0; i < n; ++i) {
179182
GrAtlasTextOp* other = fOps.fromBack(i).get();
180183
if (other->combineIfPossible(op.get(), caps) == GrOp::CombineResult::kMerged) {
181-
fOpMemoryPool->release(std::move(op));
184+
pool->release(std::move(op));
182185
return;
183186
}
184187
if (GrRectsOverlap(op->bounds(), other->bounds())) {
@@ -189,9 +192,10 @@ void SkInternalAtlasTextTarget::addDrawOp(const GrClip& clip, std::unique_ptr<Gr
189192
}
190193

191194
void SkInternalAtlasTextTarget::deleteOps() {
195+
GrOpMemoryPool* pool = this->opMemoryPool();
192196
for (int i = 0; i < fOps.count(); ++i) {
193197
if (fOps[i]) {
194-
fOpMemoryPool->release(std::move(fOps[i]));
198+
pool->release(std::move(fOps[i]));
195199
}
196200
}
197201
fOps.reset();

src/core/SkDeferredDisplayList.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
class SkSurfaceCharacterization;
1414

1515
#if SK_SUPPORT_GPU
16+
#include "src/gpu/GrMemoryPool.h"
1617
#include "src/gpu/GrRenderTask.h"
1718
#include "src/gpu/ccpr/GrCCPerOpsTaskPaths.h"
1819
#endif

src/gpu/GrContextPriv.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ sk_sp<GrSkSLFPFactoryCache> GrContextPriv::fpFactoryCache() {
4141
return fContext->fpFactoryCache();
4242
}
4343

44-
sk_sp<GrOpMemoryPool> GrContextPriv::refOpMemoryPool() {
45-
return fContext->refOpMemoryPool();
46-
}
47-
4844
void GrContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
4945
fContext->addOnFlushCallbackObject(onFlushCBObject);
5046
}

src/gpu/GrContextPriv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class GrContextPriv {
5959
// from GrRecordingContext
6060
GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
6161

62-
sk_sp<GrOpMemoryPool> refOpMemoryPool();
6362
GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); }
6463

6564
GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); }

src/gpu/GrDrawingManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ void GrDrawingManager::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) {
581581
renderTask->prePrepare(fContext);
582582
}
583583

584+
ddl->fOpMemoryPool = fContext->priv().detachOpMemoryPool();
584585
ddl->fRecordTimeData = fContext->priv().detachRecordTimeAllocator();
585586

586587
fContext->priv().detachProgramInfos(&ddl->fProgramInfos);
@@ -680,7 +681,7 @@ sk_sp<GrOpsTask> GrDrawingManager::newOpsTask(GrSurfaceProxyView surfaceView,
680681
GrSurfaceProxy* proxy = surfaceView.proxy();
681682
this->closeRenderTasksForNewRenderTask(proxy);
682683

683-
sk_sp<GrOpsTask> opsTask(new GrOpsTask(fContext->priv().refOpMemoryPool(),
684+
sk_sp<GrOpsTask> opsTask(new GrOpsTask(fContext->priv().opMemoryPool(),
684685
std::move(surfaceView), fContext->priv().auditTrail()));
685686
SkASSERT(proxy->getLastRenderTask() == opsTask.get());
686687

src/gpu/GrMemoryPool.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ class GrMemoryPool {
126126

127127
class GrOp;
128128

129-
// DDL TODO: for the DLL use case this could probably be the non-intrinsic-based style of
130-
// ref counting
131-
class GrOpMemoryPool : public SkRefCnt {
129+
class GrOpMemoryPool {
132130
public:
133131
GrOpMemoryPool(size_t preallocSize, size_t minAllocSize)
134132
: fMemoryPool(preallocSize, minAllocSize) {

src/gpu/GrOpsTask.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,11 @@ inline void GrOpsTask::OpChain::validate() const {
352352

353353
////////////////////////////////////////////////////////////////////////////////
354354

355-
GrOpsTask::GrOpsTask(sk_sp<GrOpMemoryPool> opMemoryPool,
355+
GrOpsTask::GrOpsTask(GrOpMemoryPool* opMemoryPool,
356356
GrSurfaceProxyView view,
357357
GrAuditTrail* auditTrail)
358358
: GrRenderTask(std::move(view))
359-
, fOpMemoryPool(std::move(opMemoryPool))
359+
, fOpMemoryPool(opMemoryPool)
360360
, fAuditTrail(auditTrail)
361361
, fLastClipStackGenID(SK_InvalidUniqueID)
362362
SkDEBUGCODE(, fNumClips(0)) {
@@ -366,7 +366,7 @@ GrOpsTask::GrOpsTask(sk_sp<GrOpMemoryPool> opMemoryPool,
366366

367367
void GrOpsTask::deleteOps() {
368368
for (auto& chain : fOpChains) {
369-
chain.deleteOps(fOpMemoryPool.get());
369+
chain.deleteOps(fOpMemoryPool);
370370
}
371371
fOpChains.reset();
372372
}
@@ -815,7 +815,7 @@ void GrOpsTask::recordOp(
815815
while (true) {
816816
OpChain& candidate = fOpChains.fromBack(i);
817817
op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps,
818-
fOpMemoryPool.get(), fAuditTrail);
818+
fOpMemoryPool, fAuditTrail);
819819
if (!op) {
820820
return;
821821
}
@@ -850,7 +850,7 @@ void GrOpsTask::forwardCombine(const GrCaps& caps) {
850850
int j = i + 1;
851851
while (true) {
852852
OpChain& candidate = fOpChains[j];
853-
if (candidate.prependChain(&chain, caps, fOpMemoryPool.get(), fAuditTrail)) {
853+
if (candidate.prependChain(&chain, caps, fOpMemoryPool, fAuditTrail)) {
854854
break;
855855
}
856856
// Stop traversing if we would cause a painter's order violation.

src/gpu/GrOpsTask.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class GrOpsTask : public GrRenderTask {
3838
using DstProxyView = GrXferProcessor::DstProxyView;
3939

4040
public:
41-
GrOpsTask(sk_sp<GrOpMemoryPool>, GrSurfaceProxyView, GrAuditTrail*);
41+
// The GrOpMemoryPool must outlive the GrOpsTask, either by preserving the context that owns
42+
// the pool, or by moving the pool to the DDL that takes over the GrOpsTask.
43+
GrOpsTask(GrOpMemoryPool*, GrSurfaceProxyView, GrAuditTrail*);
4244
~GrOpsTask() override;
4345

4446
GrOpsTask* asOpsTask() override { return this; }
@@ -275,10 +277,10 @@ class GrOpsTask : public GrRenderTask {
275277
friend class GrRenderTargetContext;
276278

277279
// This is a backpointer to the GrOpMemoryPool that holds the memory for this GrOpsTask's ops.
278-
// In the DDL case, these back pointers keep the DDL's GrOpMemoryPool alive as long as its
279-
// constituent GrOpsTask survives.
280-
sk_sp<GrOpMemoryPool> fOpMemoryPool;
281-
GrAuditTrail* fAuditTrail;
280+
// In the DDL case, the GrOpMemoryPool must have been detached from the original recording
281+
// context and moved into the owning DDL.
282+
GrOpMemoryPool* fOpMemoryPool;
283+
GrAuditTrail* fAuditTrail;
282284

283285
GrLoadOp fColorLoadOp = GrLoadOp::kLoad;
284286
SkPMColor4f fLoadClearColor = SK_PMColor4fTRANSPARENT;

0 commit comments

Comments
 (0)