sk_sp-ify opList creation & storage
authorRobert Phillips <robertphillips@google.com>
Thu, 13 Apr 2017 16:23:54 +0000 (12:23 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 14 Apr 2017 15:55:47 +0000 (15:55 +0000)
Change-Id: Idd4d81cd248ad2b2169028ac2e269a66c9cad26b
Reviewed-on: https://skia-review.googlesource.com/13400
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>

13 files changed:
src/gpu/GrDrawingManager.cpp
src/gpu/GrDrawingManager.h
src/gpu/GrOpList.cpp
src/gpu/GrOpList.h
src/gpu/GrPreFlushResourceProvider.cpp
src/gpu/GrRenderTargetContext.cpp
src/gpu/GrRenderTargetContext.h
src/gpu/GrRenderTargetOpList.cpp
src/gpu/GrRenderTargetOpList.h
src/gpu/GrTextureContext.cpp
src/gpu/GrTextureContext.h
src/gpu/GrTextureOpList.cpp
src/gpu/GrTextureOpList.h

index b64b9ee..cecf52f 100644 (file)
@@ -197,7 +197,7 @@ void GrDrawingManager::addPreFlushCallbackObject(sk_sp<GrPreFlushCallbackObject>
     fPreFlushCBObjects.push_back(preFlushCBObject);
 }
 
-GrRenderTargetOpList* GrDrawingManager::newOpList(GrRenderTargetProxy* rtp) {
+sk_sp<GrRenderTargetOpList> GrDrawingManager::newRTOpList(sk_sp<GrRenderTargetProxy> rtp) {
     SkASSERT(fContext);
 
 #ifndef ENABLE_MDB
@@ -210,7 +210,7 @@ GrRenderTargetOpList* GrDrawingManager::newOpList(GrRenderTargetProxy* rtp) {
         // DrawingManager gets the creation ref - this ref is for the caller
 
         // TODO: although this is true right now it isn't cool
-        return SkRef((GrRenderTargetOpList*) fOpLists[0]);
+        return sk_ref_sp((GrRenderTargetOpList*) fOpLists[0]);
     }
 #endif
 
@@ -219,18 +219,19 @@ GrRenderTargetOpList* GrDrawingManager::newOpList(GrRenderTargetProxy* rtp) {
                                                             fContext->resourceProvider(),
                                                             fContext->getAuditTrail(),
                                                             fOptionsForOpLists);
+    SkASSERT(rtp->getLastOpList() == opList);
 
     *fOpLists.append() = opList;
 
     // DrawingManager gets the creation ref - this ref is for the caller
-    return SkRef(opList);
+    return sk_ref_sp(opList);
 }
 
-GrTextureOpList* GrDrawingManager::newOpList(GrTextureProxy* textureProxy) {
+sk_sp<GrTextureOpList> GrDrawingManager::newTextureOpList(sk_sp<GrTextureProxy> textureProxy) {
     SkASSERT(fContext);
 
-    GrTextureOpList* opList = new GrTextureOpList(textureProxy, fContext->getGpu(),
-                                                  fContext->getAuditTrail());
+    sk_sp<GrTextureOpList> opList(new GrTextureOpList(std::move(textureProxy), fContext->getGpu(),
+                                                      fContext->getAuditTrail()));
 
 #ifndef ENABLE_MDB
     // When MDB is disabled we still create a new GrOpList, but don't store or ref it - we rely
@@ -240,7 +241,7 @@ GrTextureOpList* GrDrawingManager::newOpList(GrTextureProxy* textureProxy) {
     *fOpLists.append() = opList;
 
     // Drawing manager gets the creation ref - this ref is for the caller
-    return SkRef(opList);
+    return opList;
 #endif
 }
 
index f30273f..ac6bbb4 100644 (file)
@@ -44,8 +44,8 @@ public:
 
     // The caller automatically gets a ref on the returned opList. It must
     // be balanced by an unref call.
-    GrRenderTargetOpList* newOpList(GrRenderTargetProxy* rtp);
-    GrTextureOpList* newOpList(GrTextureProxy* textureProxy);
+    sk_sp<GrRenderTargetOpList> newRTOpList(sk_sp<GrRenderTargetProxy> rtp);
+    sk_sp<GrTextureOpList> newTextureOpList(sk_sp<GrTextureProxy> textureProxy);
 
     GrContext* getContext() { return fContext; }
 
index 1f90f43..28b972d 100644 (file)
@@ -21,12 +21,13 @@ uint32_t GrOpList::CreateUniqueID() {
     return id;
 }
 
-GrOpList::GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail)
-    : fUniqueID(CreateUniqueID())
-    , fFlags(0)
-    , fTarget(surfaceProxy)
-    , fAuditTrail(auditTrail) {
-
+GrOpList::GrOpList(sk_sp<GrSurfaceProxy> surfaceProxy, GrAuditTrail* auditTrail)
+    // MDB TODO: in the future opLists will own the GrSurfaceProxy they target.
+    // For now, preserve the status quo.
+    : fTarget(surfaceProxy.get())
+    , fAuditTrail(auditTrail)
+    , fUniqueID(CreateUniqueID())
+    , fFlags(0) {
     surfaceProxy->setLastOpList(this);
 }
 
index 5571266..0139b6b 100644 (file)
@@ -22,7 +22,7 @@ class GrTextureOpList;
 
 class GrOpList : public SkRefCnt {
 public:
-    GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail);
+    GrOpList(sk_sp<GrSurfaceProxy> surfaceProxy, GrAuditTrail* auditTrail);
     ~GrOpList() override;
 
     // These two methods are invoked as flush time
@@ -80,6 +80,10 @@ public:
      */
     SkDEBUGCODE(virtual void dump() const;)
 
+protected:
+    GrSurfaceProxy*      fTarget;
+    GrAuditTrail*        fAuditTrail;
+
 private:
     friend class GrDrawingManager; // for resetFlag & TopoSortTraits
 
@@ -132,14 +136,10 @@ private:
 
     uint32_t             fUniqueID;
     uint32_t             fFlags;
-    GrSurfaceProxy*      fTarget;
 
     // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
     SkTDArray<GrOpList*> fDependencies;
 
-protected:
-    GrAuditTrail*        fAuditTrail;
-
     typedef SkRefCnt INHERITED;
 };
 
index 7a10560..3c6ddc4 100644 (file)
@@ -30,8 +30,10 @@ sk_sp<GrRenderTargetContext> GrPreFlushResourceProvider::makeRenderTargetContext
         return nullptr;
     }
 
+    // MDB TODO: This explicit resource creation is required in the pre-MDB world so that the
+    // pre-Flush ops are placed in their own opList.
     sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(
-                                                    proxy->asRenderTargetProxy(),
+                                                    sk_ref_sp(proxy->asRenderTargetProxy()),
                                                     fDrawingMgr->fContext->getGpu(),
                                                     fDrawingMgr->fContext->resourceProvider(),
                                                     fDrawingMgr->fContext->getAuditTrail(),
@@ -58,9 +60,10 @@ sk_sp<GrRenderTargetContext> GrPreFlushResourceProvider::makeRenderTargetContext
                                                         sk_sp<GrSurfaceProxy> proxy,
                                                         sk_sp<SkColorSpace> colorSpace,
                                                         const SkSurfaceProps* props) {
-
+    // MDB TODO: This explicit resource creation is required in the pre-MDB world so that the
+    // pre-Flush ops are placed in their own opList.
     sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(
-                                                    proxy->asRenderTargetProxy(),
+                                                    sk_ref_sp(proxy->asRenderTargetProxy()),
                                                     fDrawingMgr->fContext->getGpu(),
                                                     fDrawingMgr->fContext->resourceProvider(),
                                                     fDrawingMgr->fContext->getAuditTrail(),
index 40ccbea..8ad9a4e 100644 (file)
@@ -82,7 +82,7 @@ GrRenderTargetContext::GrRenderTargetContext(GrContext* context,
                                              GrSingleOwner* singleOwner)
     : GrSurfaceContext(context, drawingMgr, std::move(colorSpace), auditTrail, singleOwner)
     , fRenderTargetProxy(std::move(rtp))
-    , fOpList(SkSafeRef(fRenderTargetProxy->getLastRenderTargetOpList()))
+    , fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList()))
     , fInstancedPipelineInfo(fRenderTargetProxy.get())
     , fColorXformFromSRGB(nullptr)
     , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) {
@@ -100,14 +100,13 @@ void GrRenderTargetContext::validate() const {
     fRenderTargetProxy->validate(fContext);
 
     if (fOpList && !fOpList->isClosed()) {
-        SkASSERT(fRenderTargetProxy->getLastOpList() == fOpList);
+        SkASSERT(fRenderTargetProxy->getLastOpList() == fOpList.get());
     }
 }
 #endif
 
 GrRenderTargetContext::~GrRenderTargetContext() {
     ASSERT_SINGLE_OWNER
-    SkSafeUnref(fOpList);
 }
 
 GrTextureProxy* GrRenderTargetContext::asTextureProxy() {
@@ -123,10 +122,10 @@ GrRenderTargetOpList* GrRenderTargetContext::getOpList() {
     SkDEBUGCODE(this->validate();)
 
     if (!fOpList || fOpList->isClosed()) {
-        fOpList = this->drawingManager()->newOpList(fRenderTargetProxy.get());
+        fOpList = this->drawingManager()->newRTOpList(fRenderTargetProxy);
     }
 
-    return fOpList;
+    return fOpList.get();
 }
 
 // TODO: move this (and GrTextContext::copy) to GrSurfaceContext?
index 1d1f9ec..dd42db6 100644 (file)
@@ -479,7 +479,7 @@ private:
 
     // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
     // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
-    GrRenderTargetOpList*             fOpList;
+    sk_sp<GrRenderTargetOpList>       fOpList;
     GrInstancedPipelineInfo           fInstancedPipelineInfo;
 
     sk_sp<GrColorSpaceXform>          fColorXformFromSRGB;
index 3d38c99..5730e2e 100644 (file)
@@ -25,16 +25,15 @@ using gr_instanced::InstancedRendering;
 static const int kDefaultMaxOpLookback = 10;
 static const int kDefaultMaxOpLookahead = 10;
 
-GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* rtp, GrGpu* gpu,
+GrRenderTargetOpList::GrRenderTargetOpList(sk_sp<GrRenderTargetProxy> proxy, GrGpu* gpu,
                                            GrResourceProvider* resourceProvider,
                                            GrAuditTrail* auditTrail, const Options& options)
-        : INHERITED(rtp, auditTrail)
+        : INHERITED(std::move(proxy), auditTrail)
         , fGpu(SkRef(gpu))
         , fResourceProvider(resourceProvider)
         , fLastClipStackGenID(SK_InvalidUniqueID)
         , fClipAllocator(fClipAllocatorStorage, sizeof(fClipAllocatorStorage),
                          sizeof(fClipAllocatorStorage)) {
-
     fMaxOpLookback = (options.fMaxOpCombineLookback < 0) ? kDefaultMaxOpLookback
                                                          : options.fMaxOpCombineLookback;
     fMaxOpLookahead = (options.fMaxOpCombineLookahead < 0) ? kDefaultMaxOpLookahead
index cd08559..1b6f086 100644 (file)
@@ -39,7 +39,7 @@ public:
         int fMaxOpCombineLookahead = -1;
     };
 
-    GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrResourceProvider*,
+    GrRenderTargetOpList(sk_sp<GrRenderTargetProxy>, GrGpu*, GrResourceProvider*,
                          GrAuditTrail*, const Options&);
 
     ~GrRenderTargetOpList() override;
index 76b7588..68e94f9 100644 (file)
@@ -26,7 +26,7 @@ GrTextureContext::GrTextureContext(GrContext* context,
                                    GrSingleOwner* singleOwner)
     : GrSurfaceContext(context, drawingMgr, std::move(colorSpace), auditTrail, singleOwner)
     , fTextureProxy(std::move(textureProxy))
-    , fOpList(SkSafeRef(fTextureProxy->getLastTextureOpList())) {
+    , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
     SkDEBUGCODE(this->validate();)
 }
 
@@ -36,14 +36,13 @@ void GrTextureContext::validate() const {
     fTextureProxy->validate(fContext);
 
     if (fOpList && !fOpList->isClosed()) {
-        SkASSERT(fTextureProxy->getLastOpList() == fOpList);
+        SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
     }
 }
 #endif
 
 GrTextureContext::~GrTextureContext() {
     ASSERT_SINGLE_OWNER
-    SkSafeUnref(fOpList);
 }
 
 GrRenderTargetProxy* GrTextureContext::asRenderTargetProxy() {
@@ -63,10 +62,10 @@ GrTextureOpList* GrTextureContext::getOpList() {
     SkDEBUGCODE(this->validate();)
 
     if (!fOpList || fOpList->isClosed()) {
-        fOpList = this->drawingManager()->newOpList(fTextureProxy.get());
+        fOpList = this->drawingManager()->newTextureOpList(fTextureProxy);
     }
 
-    return fOpList;
+    return fOpList.get();
 }
 
 // TODO: move this (and GrRenderTargetContext::copy) to GrSurfaceContext?
index 995ebf5..4cde61b 100644 (file)
@@ -54,7 +54,7 @@ private:
 
     // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
     // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
-    GrTextureOpList*             fOpList;
+    sk_sp<GrTextureOpList>       fOpList;
 
     typedef GrSurfaceContext INHERITED;
 };
index d2d9226..d4becad 100644 (file)
@@ -15,8 +15,8 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-GrTextureOpList::GrTextureOpList(GrTextureProxy* tex, GrGpu* gpu, GrAuditTrail* auditTrail)
-    : INHERITED(tex, auditTrail)
+GrTextureOpList::GrTextureOpList(sk_sp<GrTextureProxy> proxy, GrGpu* gpu, GrAuditTrail* auditTrail)
+    : INHERITED(std::move(proxy), auditTrail)
     , fGpu(SkRef(gpu)) {
 }
 
index 22828fd..ca5bda4 100644 (file)
@@ -23,7 +23,7 @@ struct SkIRect;
 
 class GrTextureOpList final : public GrOpList {
 public:
-    GrTextureOpList(GrTextureProxy*, GrGpu*, GrAuditTrail*);
+    GrTextureOpList(sk_sp<GrTextureProxy>, GrGpu*, GrAuditTrail*);
 
     ~GrTextureOpList() override;