Finish the DDL sk_sp migration
This will not be landed until chrome CL 2269958 lands.
Bug: skia:10425
Change-Id: I2a5081201ca3faed5232e8540086bd4c6f865767
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299292
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/bench/DDLRecorderBench.cpp b/bench/DDLRecorderBench.cpp
index 4014134..0f0bf21 100644
--- a/bench/DDLRecorderBench.cpp
+++ b/bench/DDLRecorderBench.cpp
@@ -81,7 +81,7 @@
}
std::unique_ptr<SkDeferredDisplayListRecorder> fRecorder = nullptr;
- std::vector<SkDDLPointer> fDDLs;
+ std::vector<sk_sp<SkDeferredDisplayList>> fDDLs;
typedef Benchmark INHERITED;
};
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 55a61a6..970c7f1 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1721,14 +1721,7 @@
iter.compile();
}
- SkAssertResult(dstSurface->draw(ddl));
-
-#ifdef SK_SP_IS_UNIQUE_POINTER
- // TODO: remove this flush once DDLs are reffed by the drawing manager
- context->flushAndSubmit();
-#endif
-
- ddl.reset();
+ SkAssertResult(dstSurface->draw(std::move(ddl)));
return Result::Ok();
}
diff --git a/docs/examples/Surface_characterize.cpp b/docs/examples/Surface_characterize.cpp
index bdec9d6..a83f14f 100644
--- a/docs/examples/Surface_characterize.cpp
+++ b/docs/examples/Surface_characterize.cpp
@@ -23,9 +23,9 @@
SkDeferredDisplayListRecorder recorder(characterization);
SkCanvas* subCanvas = recorder.getCanvas();
subCanvas->clear(SK_ColorGREEN);
- std::unique_ptr<SkDeferredDisplayList> displayList = recorder.detach();
+ sk_sp<SkDeferredDisplayList> displayList = recorder.detach();
// end of threadable work
- gpuSurface->draw(displayList.get());
+ gpuSurface->draw(displayList);
sk_sp<SkImage> img = gpuSurface->makeImageSnapshot();
canvas->drawImage(std::move(img), 0, 0);
}
diff --git a/docs/examples/Surface_draw_2.cpp b/docs/examples/Surface_draw_2.cpp
index 827f4ff..06beed8 100644
--- a/docs/examples/Surface_draw_2.cpp
+++ b/docs/examples/Surface_draw_2.cpp
@@ -17,9 +17,9 @@
SkDeferredDisplayListRecorder recorder(characterization);
SkCanvas* subCanvas = recorder.getCanvas();
subCanvas->clear(SK_ColorGREEN);
- std::unique_ptr<SkDeferredDisplayList> displayList = recorder.detach();
+ sk_sp<SkDeferredDisplayList> displayList = recorder.detach();
// end of threadable work
- gpuSurface->draw(displayList.get());
+ gpuSurface->draw(displayList);
sk_sp<SkImage> img = gpuSurface->makeImageSnapshot();
canvas->drawImage(std::move(img), 0, 0);
}
diff --git a/include/core/SkDeferredDisplayList.h b/include/core/SkDeferredDisplayList.h
index bcc055c..bba4170 100644
--- a/include/core/SkDeferredDisplayList.h
+++ b/include/core/SkDeferredDisplayList.h
@@ -25,26 +25,11 @@
using GrRenderTargetProxy = SkRefCnt;
#endif
-class SkDeferredDisplayList;
-
-// We are in the process of migrating DDL from unique_ptr to sk_sp. This macro can be defined
-// by the user to keep the old API until they've migrated. It will be removed soon.
-// This typedef is here temporarily and should not be used by the public.
-#ifndef SK_DDL_IS_UNIQUE_POINTER
-typedef sk_sp<SkDeferredDisplayList> SkDDLPointer;
-#else
-typedef std::unique_ptr<SkDeferredDisplayList> SkDDLPointer;
-#endif
-
/*
* This class contains pre-processed gpu operations that can be replayed into
* an SkSurface via SkSurface::draw(SkDeferredDisplayList*).
*/
-class SkDeferredDisplayList
-#ifndef SK_DDL_IS_UNIQUE_POINTER
- : public SkNVRefCnt<SkDeferredDisplayList>
-#endif
-{
+class SkDeferredDisplayList : public SkNVRefCnt<SkDeferredDisplayList> {
public:
SK_API ~SkDeferredDisplayList();
diff --git a/include/core/SkDeferredDisplayListRecorder.h b/include/core/SkDeferredDisplayListRecorder.h
index 97380c8..94a8ac5 100644
--- a/include/core/SkDeferredDisplayListRecorder.h
+++ b/include/core/SkDeferredDisplayListRecorder.h
@@ -50,7 +50,7 @@
// Note: ownership of the SkCanvas is not transferred via this call.
SkCanvas* getCanvas();
- SkDDLPointer detach();
+ sk_sp<SkDeferredDisplayList> detach();
using PromiseImageTextureContext = void*;
using PromiseImageTextureFulfillProc =
diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h
index 2adb32b..a665bb2 100644
--- a/include/core/SkSurface.h
+++ b/include/core/SkSurface.h
@@ -1046,12 +1046,7 @@
example: https://fiddle.skia.org/c/@Surface_draw_2
*/
-#ifndef SK_DDL_IS_UNIQUE_POINTER
bool draw(sk_sp<const SkDeferredDisplayList> deferredDisplayList);
-#else
- bool draw(const SkDeferredDisplayList* deferredDisplayList);
- bool draw(const std::unique_ptr<const SkDeferredDisplayList>& deferredDisplayList);
-#endif
protected:
SkSurface(int width, int height, const SkSurfaceProps* surfaceProps);
diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp
index bad30e7..227bc15 100644
--- a/src/core/SkDeferredDisplayListRecorder.cpp
+++ b/src/core/SkDeferredDisplayListRecorder.cpp
@@ -21,7 +21,7 @@
SkCanvas* SkDeferredDisplayListRecorder::getCanvas() { return nullptr; }
-SkDDLPointer SkDeferredDisplayListRecorder::detach() { return nullptr; }
+sk_sp<SkDeferredDisplayList> SkDeferredDisplayListRecorder::detach() { return nullptr; }
sk_sp<SkImage> SkDeferredDisplayListRecorder::makePromiseTexture(
const GrBackendFormat& backendFormat,
@@ -207,7 +207,7 @@
return fSurface->getCanvas();
}
-SkDDLPointer SkDeferredDisplayListRecorder::detach() {
+sk_sp<SkDeferredDisplayList> SkDeferredDisplayListRecorder::detach() {
if (!fContext) {
return nullptr;
}
@@ -217,16 +217,17 @@
canvas->restoreToCount(0);
}
- SkDeferredDisplayList* ddl = new SkDeferredDisplayList(fCharacterization,
- std::move(fTargetProxy),
- std::move(fLazyProxyData));
- fContext->priv().moveRenderTasksToDDL(ddl);
+ auto ddl = sk_sp<SkDeferredDisplayList>(new SkDeferredDisplayList(fCharacterization,
+ std::move(fTargetProxy),
+ std::move(fLazyProxyData)));
+
+ fContext->priv().moveRenderTasksToDDL(ddl.get());
// We want a new lazy proxy target for each recorded DDL so force the (lazy proxy-backed)
// SkSurface to be regenerated for each DDL.
fSurface = nullptr;
- return SkDDLPointer(ddl);
+ return ddl;
}
sk_sp<SkImage> SkDeferredDisplayListRecorder::makePromiseTexture(
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index bcbdba4..4b895d3 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -63,17 +63,10 @@
fContext->drawingManager()->moveRenderTasksToDDL(ddl);
}
-#ifndef SK_DDL_IS_UNIQUE_POINTER
void GrContextPriv::copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList> ddl,
GrRenderTargetProxy* newDest) {
fContext->drawingManager()->copyRenderTasksFromDDL(std::move(ddl), newDest);
}
-#else
-void GrContextPriv::copyRenderTasksFromDDL(const SkDeferredDisplayList* ddl,
- GrRenderTargetProxy* newDest) {
- fContext->drawingManager()->copyRenderTasksFromDDL(ddl, newDest);
-}
-#endif
bool GrContextPriv::compile(const GrProgramDesc& desc, const GrProgramInfo& info) {
GrGpu* gpu = this->getGpu();
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index b06bb9c..860c4b5 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -121,11 +121,7 @@
}
void moveRenderTasksToDDL(SkDeferredDisplayList*);
-#ifndef SK_DDL_IS_UNIQUE_POINTER
void copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest);
-#else
- void copyRenderTasksFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest);
-#endif
bool compile(const GrProgramDesc&, const GrProgramInfo&);
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index d6028a3..c8af207 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -648,13 +648,8 @@
SkDEBUGCODE(this->validate());
}
-#ifndef SK_DDL_IS_UNIQUE_POINTER
void GrDrawingManager::copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList> ddl,
GrRenderTargetProxy* newDest) {
-#else
-void GrDrawingManager::copyRenderTasksFromDDL(const SkDeferredDisplayList* ddl,
- GrRenderTargetProxy* newDest) {
-#endif
SkDEBUGCODE(this->validate());
if (fActiveOpsTask) {
@@ -690,11 +685,9 @@
fDAG.add(ddl->fRenderTasks);
-#ifndef SK_DDL_IS_UNIQUE_POINTER
// Add a task to unref the DDL after flush.
GrRenderTask* unrefTask = fDAG.add(sk_make_sp<GrUnrefDDLTask>(std::move(ddl)));
unrefTask->makeClosed(*fContext->priv().caps());
-#endif
SkDEBUGCODE(this->validate());
}
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index d869f24..fcdf3ec 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -119,11 +119,7 @@
void setLastRenderTask(const GrSurfaceProxy*, GrRenderTask*);
void moveRenderTasksToDDL(SkDeferredDisplayList* ddl);
-#ifndef SK_DDL_IS_UNIQUE_POINTER
void copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest);
-#else
- void copyRenderTasksFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest);
-#endif
private:
// This class encapsulates maintenance and manipulation of the drawing manager's DAG of
diff --git a/src/gpu/GrUnrefDDLTask.h b/src/gpu/GrUnrefDDLTask.h
index ea9f7f9..51979d8 100644
--- a/src/gpu/GrUnrefDDLTask.h
+++ b/src/gpu/GrUnrefDDLTask.h
@@ -8,8 +8,6 @@
#ifndef GrUnrefDDLTask_DEFINED
#define GrUnrefDDLTask_DEFINED
-#ifndef SK_DDL_IS_UNIQUE_POINTER
-
#include "src/gpu/GrRenderTask.h"
/** When a DDL is played back, the drawing manager refs the DDL and adds one
@@ -53,5 +51,4 @@
sk_sp<const SkDeferredDisplayList> fDDL;
};
-#endif // !SK_DDL_IS_UNIQUE_POINTER
#endif
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp
index aecca8a..62020e5 100644
--- a/src/image/SkSurface.cpp
+++ b/src/image/SkSurface.cpp
@@ -377,18 +377,9 @@
return asConstSB(this)->onIsCompatible(characterization);
}
-#ifndef SK_DDL_IS_UNIQUE_POINTER
bool SkSurface::draw(sk_sp<const SkDeferredDisplayList> ddl) {
- return asSB(this)->onDraw(ddl);
+ return asSB(this)->onDraw(std::move(ddl));
}
-#else
-bool SkSurface::draw(const SkDeferredDisplayList* ddl) {
- return asSB(this)->onDraw(ddl);
-}
-bool SkSurface::draw(const std::unique_ptr<const SkDeferredDisplayList>& ddl) {
- return asSB(this)->onDraw(ddl.get());
-}
-#endif
//////////////////////////////////////////////////////////////////////////////////////
#include "include/utils/SkNoDrawCanvas.h"
diff --git a/src/image/SkSurface_Base.h b/src/image/SkSurface_Base.h
index d7950fb..3803e1f 100644
--- a/src/image/SkSurface_Base.h
+++ b/src/image/SkSurface_Base.h
@@ -125,11 +125,7 @@
virtual bool onCharacterize(SkSurfaceCharacterization*) const { return false; }
virtual bool onIsCompatible(const SkSurfaceCharacterization&) const { return false; }
-#ifndef SK_DDL_IS_UNIQUE_POINTER
virtual bool onDraw(sk_sp<const SkDeferredDisplayList>) { return false; }
-#else
- virtual bool onDraw(const SkDeferredDisplayList*) { return false; }
-#endif
inline SkCanvas* getCachedCanvas();
inline sk_sp<SkImage> refCachedImage();
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index b65e2d3..bbadfe8 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -333,7 +333,6 @@
characterization.surfaceProps() == rtc->surfaceProps();
}
-#ifndef SK_DDL_IS_UNIQUE_POINTER
bool SkSurface_Gpu::onDraw(sk_sp<const SkDeferredDisplayList> ddl) {
if (!ddl || !this->isCompatible(ddl->characterization())) {
return false;
@@ -345,19 +344,6 @@
ctx->priv().copyRenderTasksFromDDL(std::move(ddl), rtc->asRenderTargetProxy());
return true;
}
-#else
-bool SkSurface_Gpu::onDraw(const SkDeferredDisplayList* ddl) {
- if (!ddl || !this->isCompatible(ddl->characterization())) {
- return false;
- }
-
- GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext();
- GrContext* ctx = fDevice->context();
-
- ctx->priv().copyRenderTasksFromDDL(ddl, rtc->asRenderTargetProxy());
- return true;
-}
-#endif
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/image/SkSurface_Gpu.h b/src/image/SkSurface_Gpu.h
index 07d1654..fe83ee1 100644
--- a/src/image/SkSurface_Gpu.h
+++ b/src/image/SkSurface_Gpu.h
@@ -58,11 +58,7 @@
bool onCharacterize(SkSurfaceCharacterization*) const override;
bool onIsCompatible(const SkSurfaceCharacterization&) const override;
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) override;
-#ifndef SK_DDL_IS_UNIQUE_POINTER
bool onDraw(sk_sp<const SkDeferredDisplayList>) override;
-#else
- bool onDraw(const SkDeferredDisplayList*) override;
-#endif
SkGpuDevice* getDevice() { return fDevice.get(); }
diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp
index 78ad503..7573cbc 100644
--- a/tests/DeferredDisplayListTest.cpp
+++ b/tests/DeferredDisplayListTest.cpp
@@ -166,7 +166,7 @@
}
// Create a DDL whose characterization captures the current settings
- SkDDLPointer createDDL(GrContext* context) const {
+ sk_sp<SkDeferredDisplayList> createDDL(GrContext* context) const {
SkSurfaceCharacterization c = this->createCharacterization(context);
SkAssertResult(c.isValid());
@@ -335,7 +335,7 @@
SkBitmap bitmap;
bitmap.allocPixels(imageInfo);
- SkDDLPointer ddl;
+ sk_sp<SkDeferredDisplayList> ddl;
// First, create a DDL using the stock SkSurface parameters
{
@@ -726,7 +726,7 @@
bitmap.allocPixels(imageInfo);
for (bool textureability : { true, false }) {
- SkDDLPointer ddl;
+ sk_sp<SkDeferredDisplayList> ddl;
// First, create a DDL w/o textureability (and thus no mipmaps). TODO: once we have
// reusable DDLs, move this outside of the loop.
@@ -1047,7 +1047,7 @@
FulfillInfo fulfillInfo;
fulfillInfo.fTex = SkPromiseImageTexture::Make(backendTexture);
- SkDDLPointer ddl;
+ sk_sp<SkDeferredDisplayList> ddl;
{
SkDeferredDisplayListRecorder recorder(characterization);
@@ -1126,7 +1126,7 @@
canvas1->save();
canvas1->clipRect(SkRect::MakeXYWH(8, 8, 16, 16));
- SkDDLPointer ddl1 = recorder.detach();
+ sk_sp<SkDeferredDisplayList> ddl1 = recorder.detach();
SkCanvas* canvas2 = recorder.getCanvas();
@@ -1134,7 +1134,7 @@
p.setColor(SK_ColorGREEN);
canvas2->drawRect(SkRect::MakeWH(32, 32), p);
- SkDDLPointer ddl2 = recorder.detach();
+ sk_sp<SkDeferredDisplayList> ddl2 = recorder.detach();
REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData());
REPORTER_ASSERT(reporter, ddl2->priv().lazyProxyData());
diff --git a/tools/DDLTileHelper.cpp b/tools/DDLTileHelper.cpp
index 9b996ad..ef7185f 100644
--- a/tools/DDLTileHelper.cpp
+++ b/tools/DDLTileHelper.cpp
@@ -289,11 +289,6 @@
tile->draw(context);
-#ifdef SK_SP_IS_UNIQUE_POINTER
- // TODO: remove this flush once DDLs are reffed by the drawing manager
- context->flushAndSubmit();
-#endif
-
tile->dropDDL();
}
diff --git a/tools/DDLTileHelper.h b/tools/DDLTileHelper.h
index 20796d0..3956306 100644
--- a/tools/DDLTileHelper.h
+++ b/tools/DDLTileHelper.h
@@ -87,12 +87,12 @@
// after 'fDisplayList' has been flushed (bc it owns the proxy the DDL's destination
// trampoline points at).
// TODO: fix the ref-order so we don't need 'fTileSurface' here
- sk_sp<SkSurface> fTileSurface;
+ sk_sp<SkSurface> fTileSurface;
- sk_sp<SkPicture> fReconstitutedPicture;
- SkTArray<sk_sp<SkImage>> fPromiseImages; // All the promise images in the
+ sk_sp<SkPicture> fReconstitutedPicture;
+ SkTArray<sk_sp<SkImage>> fPromiseImages; // All the promise images in the
// reconstituted picture
- SkDDLPointer fDisplayList;
+ sk_sp<SkDeferredDisplayList> fDisplayList;
};
DDLTileHelper(GrContext* context,
@@ -110,7 +110,7 @@
// Create the DDL that will compose all the tile images into a final result.
void createComposeDDL();
- const SkDDLPointer& composeDDL() const { return fComposeDDL; }
+ const sk_sp<SkDeferredDisplayList>& composeDDL() const { return fComposeDDL; }
void precompileAndDrawAllTiles(GrContext*);
@@ -137,7 +137,7 @@
int fNumDivisions; // number of tiles along a side
SkAutoTArray<TileData> fTiles; // 'fNumDivisions' x 'fNumDivisions'
- SkDDLPointer fComposeDDL;
+ sk_sp<SkDeferredDisplayList> fComposeDDL;
const SkSurfaceCharacterization fDstCharacterization;
};