diff options
author | bungeman <bungeman@google.com> | 2016-10-27 09:30:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-27 09:30:08 -0700 |
commit | 6bd5284415bd983b0628c4941dff5def40018f5a (patch) | |
tree | 7de7e45431f76db69807204ecdce3ed6fcc4d9e8 /src | |
parent | 56380524d903f27627a75e2e1189463999725008 (diff) |
Remove SkAutoTUnref and SkAutoTDelete from public includes.
This also makes the required changed to src, tests, and tools. The few
public APIs modified by this change appear to be unused outside of Skia.
Removing these from the public API makes it easier to ensure users are
no longer using them.
This also updates GrGpu::wrapBackendXXX and the
::onWrapBackendXXX methods to clarify ownership.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2448593002
Review-Url: https://codereview.chromium.org/2448593002
Diffstat (limited to 'src')
42 files changed, 197 insertions, 224 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index bcda0f2526..7c9f5c6cd5 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -319,15 +319,14 @@ static SkIRect compute_device_bounds(SkBaseDevice* device) { class SkDrawIter : public SkDraw { public: SkDrawIter(SkCanvas* canvas) { - canvas = canvas->canvasForDrawIter(); canvas->updateDeviceCMCache(); - fClipStack = canvas->fClipStack; + fClipStack = canvas->getClipStack(); fCurrLayer = canvas->fMCRec->fTopLayer; fMultiDeviceCS = nullptr; if (fCurrLayer->fNext) { - fMultiDeviceCS = canvas->fClipStack; + fMultiDeviceCS = canvas->fClipStack.get(); fMultiDeviceCS->save(); } } @@ -966,10 +965,6 @@ bool SkCanvas::writePixels(const SkImageInfo& origInfo, const void* pixels, size return device->writePixels(info, pixels, rowBytes, target.x(), target.y()); } -SkCanvas* SkCanvas::canvasForDrawIter() { - return this; -} - ////////////////////////////////////////////////////////////////////////////// void SkCanvas::updateDeviceCMCache() { diff --git a/src/core/SkMaskGamma.h b/src/core/SkMaskGamma.h index 94219d42ac..f90f75a878 100644 --- a/src/core/SkMaskGamma.h +++ b/src/core/SkMaskGamma.h @@ -174,11 +174,11 @@ private: */ template <int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS> class SkTMaskPreBlend { private: - SkTMaskPreBlend(const SkTMaskGamma<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>* parent, + SkTMaskPreBlend(sk_sp<const SkTMaskGamma<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>> parent, const uint8_t* r, const uint8_t* g, const uint8_t* b) - : fParent(SkSafeRef(parent)), fR(r), fG(g), fB(b) { } + : fParent(std::move(parent)), fR(r), fG(g), fB(b) { } - SkAutoTUnref<const SkTMaskGamma<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS> > fParent; + sk_sp<const SkTMaskGamma<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>> fParent; friend class SkTMaskGamma<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>; public: /** Creates a non applicable SkTMaskPreBlend. */ @@ -189,7 +189,7 @@ public: * when return value optimization is enabled. */ SkTMaskPreBlend(const SkTMaskPreBlend<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>& that) - : fParent(SkSafeRef(that.fParent.get())), fR(that.fR), fG(that.fG), fB(that.fB) { } + : fParent(that.fParent), fR(that.fR), fG(that.fG), fB(that.fB) { } ~SkTMaskPreBlend() { } @@ -205,7 +205,7 @@ template <int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS> SkTMaskPreBlend<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS> SkTMaskGamma<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>::preBlend(SkColor color) const { return fIsLinear ? SkTMaskPreBlend<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>() - : SkTMaskPreBlend<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>(this, + : SkTMaskPreBlend<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>(sk_ref_sp(this), fGammaTables[SkColorGetR(color) >> (8 - MAX_LUM_BITS)], fGammaTables[SkColorGetG(color) >> (8 - MAX_LUM_BITS)], fGammaTables[SkColorGetB(color) >> (8 - MAX_LUM_BITS)]); diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index d65687630c..4dc2f96656 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -220,7 +220,7 @@ bool SkPath::interpolate(const SkPath& ending, SkScalar weight, SkPath* out) con } out->reset(); out->addPath(*this); - fPathRef->interpolate(*ending.fPathRef, weight, out->fPathRef); + fPathRef->interpolate(*ending.fPathRef, weight, out->fPathRef.get()); return true; } diff --git a/src/core/SkPathRef.cpp b/src/core/SkPathRef.cpp index 844c40a505..ef051f7e84 100644 --- a/src/core/SkPathRef.cpp +++ b/src/core/SkPathRef.cpp @@ -12,7 +12,7 @@ #include <limits> ////////////////////////////////////////////////////////////////////////////// -SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef, +SkPathRef::Editor::Editor(sk_sp<SkPathRef>* pathRef, int incReserveVerbs, int incReservePoints) { @@ -23,7 +23,7 @@ SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef, copy->copy(**pathRef, incReserveVerbs, incReservePoints); pathRef->reset(copy); } - fPathRef = *pathRef; + fPathRef = pathRef->get(); fPathRef->callGenIDChangeListeners(); fPathRef->fGenerationID = 0; SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);) @@ -111,12 +111,12 @@ static void transform_dir_and_start(const SkMatrix& matrix, bool isRRect, bool* } } -void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, +void SkPathRef::CreateTransformedCopy(sk_sp<SkPathRef>* dst, const SkPathRef& src, const SkMatrix& matrix) { SkDEBUGCODE(src.validate();) if (matrix.isIdentity()) { - if (*dst != &src) { + if (dst->get() != &src) { src.ref(); dst->reset(const_cast<SkPathRef*>(&src)); SkDEBUGCODE((*dst)->validate();) @@ -128,7 +128,7 @@ void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, dst->reset(new SkPathRef); } - if (*dst != &src) { + if (dst->get() != &src) { (*dst)->resetToSize(src.fVerbCnt, src.fPointCnt, src.fConicWeights.count()); sk_careful_memcpy((*dst)->verbsMemWritable(), src.verbsMemBegin(), src.fVerbCnt * sizeof(uint8_t)); @@ -242,7 +242,7 @@ SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer) { return ref; } -void SkPathRef::Rewind(SkAutoTUnref<SkPathRef>* pathRef) { +void SkPathRef::Rewind(sk_sp<SkPathRef>* pathRef) { if ((*pathRef)->unique()) { SkDEBUGCODE((*pathRef)->validate();) (*pathRef)->callGenIDChangeListeners(); diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index 68789acddf..cc529e3eca 100644 --- a/src/core/SkPictureData.cpp +++ b/src/core/SkPictureData.cpp @@ -268,7 +268,7 @@ void SkPictureData::serialize(SkWStream* stream, SkFactorySet factSet; // buffer refs factSet, so factSet must come first. SkBinaryWriteBuffer buffer(SkBinaryWriteBuffer::kCrossProcess_Flag); buffer.setFactoryRecorder(&factSet); - buffer.setPixelSerializer(pixelSerializer); + buffer.setPixelSerializer(sk_ref_sp(pixelSerializer)); buffer.setTypefaceRecorder(typefaceSet); this->flattenToBuffer(buffer); diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp index 5631a081d4..758aa3e5ec 100644 --- a/src/core/SkPictureRecorder.cpp +++ b/src/core/SkPictureRecorder.cpp @@ -62,7 +62,7 @@ sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture(uint32_t finishFlag } // TODO: delay as much of this work until just before first playback? - SkRecordOptimize(fRecord); + SkRecordOptimize(fRecord.get()); if (fRecord->count() == 0) { if (finishFlags & kReturnNullForEmpty_FinishFlag) { @@ -122,7 +122,7 @@ sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable(uint32_t finishFl fRecorder->flushMiniRecorder(); fRecorder->restoreToCount(1); // If we were missing any restores, add them now. - SkRecordOptimize(fRecord); + SkRecordOptimize(fRecord.get()); if (fRecord->count() == 0) { if (finishFlags & kReturnNullForEmpty_FinishFlag) { @@ -137,11 +137,8 @@ sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable(uint32_t finishFl } sk_sp<SkDrawable> drawable = - sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawableList(), fCullRect); - - // release our refs now, so only the drawable will be the owner. - fRecord.reset(nullptr); - fBBH.reset(nullptr); + sk_make_sp<SkRecordedDrawable>(std::move(fRecord), std::move(fBBH), + fRecorder->detachDrawableList(), fCullRect); return drawable; } diff --git a/src/core/SkRecordedDrawable.cpp b/src/core/SkRecordedDrawable.cpp index 9e68be1d25..62a9339c6a 100644 --- a/src/core/SkRecordedDrawable.cpp +++ b/src/core/SkRecordedDrawable.cpp @@ -21,7 +21,7 @@ void SkRecordedDrawable::onDraw(SkCanvas* canvas) { drawables = fDrawableList->begin(); drawableCount = fDrawableList->count(); } - SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, fBBH, nullptr/*callback*/); + SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, fBBH.get(), nullptr); } SkPicture* SkRecordedDrawable::onNewPictureSnapshot() { diff --git a/src/core/SkRecordedDrawable.h b/src/core/SkRecordedDrawable.h index 7e2d9bc599..de1fca5233 100644 --- a/src/core/SkRecordedDrawable.h +++ b/src/core/SkRecordedDrawable.h @@ -12,11 +12,11 @@ class SkRecordedDrawable : public SkDrawable { public: - SkRecordedDrawable(SkRecord* record, SkBBoxHierarchy* bbh, SkDrawableList* drawableList, - const SkRect& bounds) - : fRecord(SkRef(record)) - , fBBH(SkSafeRef(bbh)) - , fDrawableList(drawableList) // we take ownership + SkRecordedDrawable(sk_sp<SkRecord> record, sk_sp<SkBBoxHierarchy> bbh, + std::unique_ptr<SkDrawableList> drawableList, const SkRect& bounds) + : fRecord(std::move(record)) + , fBBH(std::move(bbh)) + , fDrawableList(std::move(drawableList)) , fBounds(bounds) {} @@ -34,8 +34,8 @@ protected: SkPicture* onNewPictureSnapshot() override; private: - SkAutoTUnref<SkRecord> fRecord; - SkAutoTUnref<SkBBoxHierarchy> fBBH; - SkAutoTDelete<SkDrawableList> fDrawableList; + sk_sp<SkRecord> fRecord; + sk_sp<SkBBoxHierarchy> fBBH; + std::unique_ptr<SkDrawableList> fDrawableList; const SkRect fBounds; }; diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h index 8efae17c6e..715fc9399c 100644 --- a/src/core/SkRecorder.h +++ b/src/core/SkRecorder.h @@ -48,7 +48,7 @@ public: size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; } SkDrawableList* getDrawableList() const { return fDrawableList.get(); } - SkDrawableList* detachDrawableList() { return fDrawableList.release(); } + std::unique_ptr<SkDrawableList> detachDrawableList() { return std::move(fDrawableList); } // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail. void forgetRecord(); @@ -173,7 +173,7 @@ private: DrawPictureMode fDrawPictureMode; size_t fApproxBytesUsedBySubPictures; SkRecord* fRecord; - SkAutoTDelete<SkDrawableList> fDrawableList; + std::unique_ptr<SkDrawableList> fDrawableList; SkMiniRecorder* fMiniRecorder; }; diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index 5d62c6bc62..eeb00c995e 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -370,7 +370,7 @@ public: this->subset().width(), this->subset().height()); auto img = sk_sp<SkImage>(new SkImage_Gpu(fTexture->width(), fTexture->height(), - this->uniqueID(), fAlphaType, fTexture.get(), + this->uniqueID(), fAlphaType, fTexture, fColorSpace, SkBudgeted::kNo)); canvas->drawImageRect(img, this->subset(), @@ -439,7 +439,7 @@ public: // The existing GrTexture is already tight so reuse it in the SkImage return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height(), kNeedNewImageUniqueID, - fAlphaType, fTexture.get(), fColorSpace, + fAlphaType, fTexture, fColorSpace, SkBudgeted::kYes); } @@ -454,7 +454,7 @@ public: } ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0, 0)); return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, - fAlphaType, subTx.get(), fColorSpace, SkBudgeted::kYes); + fAlphaType, std::move(subTx), fColorSpace, SkBudgeted::kYes); } sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps, diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp index 019bc247b5..3d12889fa1 100644 --- a/src/core/SkWriteBuffer.cpp +++ b/src/core/SkWriteBuffer.cpp @@ -236,11 +236,8 @@ SkRefCntSet* SkBinaryWriteBuffer::setTypefaceRecorder(SkRefCntSet* rec) { return rec; } -void SkBinaryWriteBuffer::setPixelSerializer(SkPixelSerializer* serializer) { - fPixelSerializer.reset(serializer); - if (serializer) { - serializer->ref(); - } +void SkBinaryWriteBuffer::setPixelSerializer(sk_sp<SkPixelSerializer> serializer) { + fPixelSerializer = std::move(serializer); } void SkBinaryWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) { diff --git a/src/gpu/GrAuditTrail.cpp b/src/gpu/GrAuditTrail.cpp index 82dc7f713f..ff6debd032 100644 --- a/src/gpu/GrAuditTrail.cpp +++ b/src/gpu/GrAuditTrail.cpp @@ -88,7 +88,7 @@ void GrAuditTrail::batchingResultCombined(const GrBatch* consumer, const GrBatch void GrAuditTrail::copyOutFromBatchList(BatchInfo* outBatchInfo, int batchListID) { SkASSERT(batchListID < fBatchList.count()); - const BatchNode* bn = fBatchList[batchListID]; + const BatchNode* bn = fBatchList[batchListID].get(); SkASSERT(bn); outBatchInfo->fBounds = bn->fBounds; outBatchInfo->fRenderTargetUniqueID = bn->fRenderTargetUniqueID; diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index a0884f9274..dfb2fce279 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -132,11 +132,11 @@ GrContext::~GrContext() { fCaps->unref(); } -GrContextThreadSafeProxy* GrContext::threadSafeProxy() { +sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() { if (!fThreadSafeProxy) { - fThreadSafeProxy.reset(new GrContextThreadSafeProxy(fCaps, this->uniqueID())); + fThreadSafeProxy.reset(new GrContextThreadSafeProxy(sk_ref_sp(fCaps), this->uniqueID())); } - return SkRef(fThreadSafeProxy.get()); + return fThreadSafeProxy; } void GrContext::abandonContext() { diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index 29eb151b6c..398fc8a549 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -15,7 +15,7 @@ data members or virtual methods. */ class GrContextPriv { public: - GrDrawingManager* drawingManager() { return fContext->fDrawingManager; } + GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); } // Create a drawContext that wraps an existing renderTarget sk_sp<GrDrawContext> makeWrappedDrawContext(sk_sp<GrRenderTarget> rt, diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 0de9fedb8c..f576424889 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -190,7 +190,8 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget return tex; } -GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) { +sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, + GrWrapOwnership ownership) { this->handleDirtyContext(); if (!this->caps()->isConfigTexturable(desc.fConfig)) { return nullptr; @@ -203,22 +204,20 @@ GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn if (desc.fWidth > maxSize || desc.fHeight > maxSize) { return nullptr; } - GrTexture* tex = this->onWrapBackendTexture(desc, ownership); - if (nullptr == tex) { + sk_sp<GrTexture> tex = this->onWrapBackendTexture(desc, ownership); + if (!tex) { return nullptr; } // TODO: defer this and attach dynamically GrRenderTarget* tgt = tex->asRenderTarget(); if (tgt && !fContext->resourceProvider()->attachStencilAttachment(tgt)) { - tex->unref(); return nullptr; - } else { - return tex; } + return tex; } -GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc, - GrWrapOwnership ownership) { +sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc, + GrWrapOwnership ownership) { if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { return nullptr; } @@ -226,7 +225,7 @@ GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& return this->onWrapBackendRenderTarget(desc, ownership); } -GrRenderTarget* GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) { +sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) { this->handleDirtyContext(); if (!(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) { return nullptr; diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index ba7ed6f47e..8e9407a458 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -124,17 +124,17 @@ public: /** * Implements GrTextureProvider::wrapBackendTexture */ - GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); + sk_sp<GrTexture> wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); /** * Implements GrTextureProvider::wrapBackendRenderTarget */ - GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&, GrWrapOwnership); + sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTargetDesc&,GrWrapOwnership); /** * Implements GrTextureProvider::wrapBackendTextureAsRenderTarget */ - GrRenderTarget* wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&); + sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&); /** * Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked. @@ -532,10 +532,10 @@ private: SkBudgeted budgeted, const SkTArray<GrMipLevel>& texels) = 0; - virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0; - virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, - GrWrapOwnership) = 0; - virtual GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) = 0; + virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0; + virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, + GrWrapOwnership) = 0; + virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&)=0; virtual GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, const void* data) = 0; diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp index e641e749ff..3eb047c1a8 100644 --- a/src/gpu/GrRenderTargetOpList.cpp +++ b/src/gpu/GrRenderTargetOpList.cpp @@ -113,7 +113,7 @@ bool GrRenderTargetOpList::setupDstReadIfNecessary(const GrPipelineBuilder& pipe if (GrTexture* rtTex = rt->asTexture()) { // The render target is a texture, so we can read from it directly in the shader. The XP // will be responsible to detect this situation and request a texture barrier. - dstTexture->setTexture(rtTex); + dstTexture->setTexture(sk_ref_sp(rtTex)); dstTexture->setOffset(0, 0); return true; } @@ -145,15 +145,15 @@ bool GrRenderTargetOpList::setupDstReadIfNecessary(const GrPipelineBuilder& pipe desc.fHeight = copyRect.height(); static const uint32_t kFlags = 0; - SkAutoTUnref<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags)); + sk_sp<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags)); if (!copy) { SkDebugf("Failed to create temporary copy of destination texture.\n"); return false; } SkIPoint dstPoint = {0, 0}; - this->copySurface(copy, rt, copyRect, dstPoint); - dstTexture->setTexture(copy); + this->copySurface(copy.get(), rt, copyRect, dstPoint); + dstTexture->setTexture(std::move(copy)); dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); return true; } diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index b63a7eaa45..9739b05ad7 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -205,8 +205,9 @@ GrStencilAttachment* GrResourceProvider::attachStencilAttachment(GrRenderTarget* return rt->renderTargetPriv().getStencilAttachment(); } -GrRenderTarget* GrResourceProvider::wrapBackendTextureAsRenderTarget( - const GrBackendTextureDesc& desc) { +sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendTextureAsRenderTarget( + const GrBackendTextureDesc& desc) +{ if (this->isAbandoned()) { return nullptr; } diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index 4c90cddd4d..c29a40a2b4 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -164,7 +164,7 @@ public: * * @return GrRenderTarget object or NULL on failure. */ - GrRenderTarget* wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc); + sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc); private: const GrBuffer* createInstancedIndexBuffer(const uint16_t* pattern, diff --git a/src/gpu/GrTextureProvider.cpp b/src/gpu/GrTextureProvider.cpp index 68a5540484..dba24b5926 100644 --- a/src/gpu/GrTextureProvider.cpp +++ b/src/gpu/GrTextureProvider.cpp @@ -158,8 +158,8 @@ GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& inDesc, return nullptr; } -GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& desc, - GrWrapOwnership ownership) { +sk_sp<GrTexture> GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& desc, + GrWrapOwnership ownership) { ASSERT_SINGLE_OWNER if (this->isAbandoned()) { return nullptr; @@ -167,10 +167,12 @@ GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des return fGpu->wrapBackendTexture(desc, ownership); } -GrRenderTarget* GrTextureProvider::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) { +sk_sp<GrRenderTarget> GrTextureProvider::wrapBackendRenderTarget( + const GrBackendRenderTargetDesc& desc) +{ ASSERT_SINGLE_OWNER - return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc, - kBorrow_GrWrapOwnership); + return this->isAbandoned() ? nullptr + : fGpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwnership); } void GrTextureProvider::assignUniqueKeyToResource(const GrUniqueKey& key, GrGpuResource* resource) { diff --git a/src/gpu/gl/GrGLExtensions.cpp b/src/gpu/gl/GrGLExtensions.cpp index 43a147d763..29f7799462 100644 --- a/src/gpu/gl/GrGLExtensions.cpp +++ b/src/gpu/gl/GrGLExtensions.cpp @@ -9,6 +9,7 @@ #include "gl/GrGLDefines.h" #include "gl/GrGLUtil.h" +#include "SkMakeUnique.h" #include "SkTSearch.h" #include "SkTSort.h" @@ -99,12 +100,12 @@ bool GrGLExtensions::init(GrGLStandard standard, if (!extensions) { return false; } - eat_space_sep_strings(fStrings, extensions); + eat_space_sep_strings(fStrings.get(), extensions); } if (queryString) { const char* extensions = queryString(eglDisplay, GR_EGL_EXTENSIONS); - eat_space_sep_strings(fStrings, extensions); + eat_space_sep_strings(fStrings.get(), extensions); } if (!fStrings->empty()) { SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; @@ -122,27 +123,26 @@ bool GrGLExtensions::has(const char ext[]) const { bool GrGLExtensions::remove(const char ext[]) { SkASSERT(fInitialized); int idx = find_string(*fStrings, ext); - if (idx >= 0) { - // This is not terribly effecient but we really only expect this function to be called at - // most a handful of times when our test programs start. - SkAutoTDelete< SkTArray<SkString> > oldStrings(fStrings.release()); - fStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1)); - fStrings->push_back_n(idx, &oldStrings->front()); - fStrings->push_back_n(oldStrings->count() - idx - 1, &(*oldStrings)[idx] + 1); - return true; - } else { + if (idx < 0) { return false; } + + // This is not terribly effecient but we really only expect this function to be called at + // most a handful of times when our test programs start. + fStrings->removeShuffle(idx); + SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; + SkTInsertionSort(&(fStrings->operator[](idx)), &fStrings->back(), cmp); + return true; } void GrGLExtensions::add(const char ext[]) { int idx = find_string(*fStrings, ext); if (idx < 0) { - // This is not the most effecient approach since we end up doing a full sort of the + // This is not the most effecient approach since we end up looking at all of the // extensions after the add - fStrings->push_back().set(ext); + fStrings->emplace_back(ext); SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; - SkTQSort(&fStrings->front(), &fStrings->back(), cmp); + SkTInsertionSort(&fStrings->front(), &fStrings->back(), cmp); } } diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 4e579cc543..485a9bd09a 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -624,8 +624,8 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) } } -GrTexture* GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, - GrWrapOwnership ownership) { +sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, + GrWrapOwnership ownership) { const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle); if (!info || !info->fID) { return nullptr; @@ -681,25 +681,18 @@ GrTexture* GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, surfDesc.fOrigin = desc.fOrigin; } - GrGLTexture* texture = nullptr; if (renderTarget) { GrGLRenderTarget::IDDesc rtIDDesc; if (!this->createRenderTargetObjects(surfDesc, idDesc.fInfo, &rtIDDesc)) { return nullptr; } - texture = GrGLTextureRenderTarget::CreateWrapped(this, surfDesc, idDesc, rtIDDesc); - } else { - texture = GrGLTexture::CreateWrapped(this, surfDesc, idDesc); - } - if (nullptr == texture) { - return nullptr; + return GrGLTextureRenderTarget::MakeWrapped(this, surfDesc, idDesc, rtIDDesc); } - - return texture; + return GrGLTexture::MakeWrapped(this, surfDesc, idDesc); } -GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc, - GrWrapOwnership ownership) { +sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc, + GrWrapOwnership ownership) { GrGLRenderTarget::IDDesc idDesc; idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); idDesc.fMSColorRenderbufferID = 0; @@ -719,10 +712,10 @@ GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()); desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); - return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencilBits); + return GrGLRenderTarget::MakeWrapped(this, desc, idDesc, wrapDesc.fStencilBits); } -GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) { +sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc){ const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle); if (!info || !info->fID) { return nullptr; @@ -759,7 +752,7 @@ GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu if (!this->createRenderTargetObjects(surfDesc, texInfo, &rtIDDesc)) { return nullptr; } - return GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0); + return GrGLRenderTarget::MakeWrapped(this, surfDesc, rtIDDesc, 0); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 29d20e4b63..4420c658fe 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -164,10 +164,10 @@ private: GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, const void* data) override; - GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override; - GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, - GrWrapOwnership) override; - GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override; + sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override; + sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, + GrWrapOwnership) override; + sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override; gr_instanced::InstancedRendering* onCreateInstancedRendering() override; diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp index f6ad3ba611..65366bd380 100644 --- a/src/gpu/gl/GrGLRenderTarget.cpp +++ b/src/gpu/gl/GrGLRenderTarget.cpp @@ -64,10 +64,10 @@ void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { SkASSERT(fGpuMemorySize <= WorstCaseSize(desc)); } -GrGLRenderTarget* GrGLRenderTarget::CreateWrapped(GrGLGpu* gpu, - const GrSurfaceDesc& desc, - const IDDesc& idDesc, - int stencilBits) { +sk_sp<GrGLRenderTarget> GrGLRenderTarget::MakeWrapped(GrGLGpu* gpu, + const GrSurfaceDesc& desc, + const IDDesc& idDesc, + int stencilBits) { GrGLStencilAttachment* sb = nullptr; if (stencilBits) { GrGLStencilAttachment::IDDesc sbDesc; @@ -80,7 +80,7 @@ GrGLRenderTarget* GrGLRenderTarget::CreateWrapped(GrGLGpu* gpu, sb = new GrGLStencilAttachment(gpu, sbDesc, desc.fWidth, desc.fHeight, desc.fSampleCnt, format); } - return (new GrGLRenderTarget(gpu, desc, idDesc, sb)); + return sk_sp<GrGLRenderTarget>(new GrGLRenderTarget(gpu, desc, idDesc, sb)); } size_t GrGLRenderTarget::onGpuMemorySize() const { diff --git a/src/gpu/gl/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h index 85e377f69a..08dd88d523 100644 --- a/src/gpu/gl/GrGLRenderTarget.h +++ b/src/gpu/gl/GrGLRenderTarget.h @@ -31,10 +31,10 @@ public: bool fIsMixedSampled; }; - static GrGLRenderTarget* CreateWrapped(GrGLGpu*, - const GrSurfaceDesc&, - const IDDesc&, - int stencilBits); + static sk_sp<GrGLRenderTarget> MakeWrapped(GrGLGpu*, + const GrSurfaceDesc&, + const IDDesc&, + int stencilBits); void setViewport(const GrGLIRect& rect) { fViewport = rect; } const GrGLIRect& getViewport() const { return fViewport; } diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp index ed753472a8..4653c5bce7 100644 --- a/src/gpu/gl/GrGLTexture.cpp +++ b/src/gpu/gl/GrGLTexture.cpp @@ -92,8 +92,8 @@ void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, texture_id.c_str()); } -GrGLTexture* GrGLTexture::CreateWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, - const IDDesc& idDesc) { - return new GrGLTexture(gpu, kWrapped, desc, idDesc); +sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, + const IDDesc& idDesc) { + return sk_sp<GrGLTexture>(new GrGLTexture(gpu, kWrapped, desc, idDesc)); } diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h index 05d26c8de8..ee027d790d 100644 --- a/src/gpu/gl/GrGLTexture.h +++ b/src/gpu/gl/GrGLTexture.h @@ -56,7 +56,7 @@ public: GrGLenum target() const { return fInfo.fTarget; } - static GrGLTexture* CreateWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); + static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); protected: // Constructor for subclasses. GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); diff --git a/src/gpu/gl/GrGLTextureRenderTarget.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp index 2ba469a9f2..9b37fbb343 100644 --- a/src/gpu/gl/GrGLTextureRenderTarget.cpp +++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp @@ -44,9 +44,10 @@ bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const { return true; } -GrGLTextureRenderTarget* GrGLTextureRenderTarget::CreateWrapped(GrGLGpu* gpu, - const GrSurfaceDesc& desc, - const GrGLTexture::IDDesc& texIDDesc, - const GrGLRenderTarget::IDDesc& rtIDDesc) { - return new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc); +sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped( + GrGLGpu* gpu, const GrSurfaceDesc& desc, + const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc) +{ + return sk_sp<GrGLTextureRenderTarget>( + new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc)); } diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h index 0826cf3a71..c5c020fef6 100644 --- a/src/gpu/gl/GrGLTextureRenderTarget.h +++ b/src/gpu/gl/GrGLTextureRenderTarget.h @@ -40,9 +40,9 @@ public: void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; - static GrGLTextureRenderTarget* CreateWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, - const GrGLTexture::IDDesc& texIDDesc, - const GrGLRenderTarget::IDDesc& rtIDDesc); + static sk_sp<GrGLTextureRenderTarget> MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, + const GrGLTexture::IDDesc& texIDDesc, + const GrGLRenderTarget::IDDesc& rtIDDesc); protected: void onAbandon() override { GrGLRenderTarget::onAbandon(); diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index b13e16282e..7d75921c23 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -756,8 +756,8 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin) { } } -GrTexture* GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, - GrWrapOwnership ownership) { +sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, + GrWrapOwnership ownership) { if (0 == desc.fTextureHandle) { return nullptr; } @@ -791,22 +791,14 @@ GrTexture* GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, // In VK, we don't have this restriction surfDesc.fOrigin = resolve_origin(desc.fOrigin); - GrVkTexture* texture = nullptr; - if (renderTarget) { - texture = GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(this, surfDesc, - ownership, info); - } else { - texture = GrVkTexture::CreateWrappedTexture(this, surfDesc, ownership, info); + if (!renderTarget) { + return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, info); } - if (!texture) { - return nullptr; - } - - return texture; + return GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, ownership, info); } -GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc, - GrWrapOwnership ownership) { +sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc, + GrWrapOwnership ownership) { const GrVkImageInfo* info = reinterpret_cast<const GrVkImageInfo*>(wrapDesc.fRenderTargetHandle); @@ -824,12 +816,10 @@ GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe desc.fOrigin = resolve_origin(wrapDesc.fOrigin); - GrVkRenderTarget* tgt = GrVkRenderTarget::CreateWrappedRenderTarget(this, desc, - ownership, - info); + sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, + ownership, info); if (tgt && wrapDesc.fStencilBits) { - if (!createStencilAttachmentForRenderTarget(tgt, desc.fWidth, desc.fHeight)) { - tgt->unref(); + if (!createStencilAttachmentForRenderTarget(tgt.get(), desc.fWidth, desc.fHeight)) { return nullptr; } } diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index 77eb24215c..b62278337b 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -50,7 +50,7 @@ public: ~GrVkGpu() override; - const GrVkInterface* vkInterface() const { return fBackendContext->fInterface; } + const GrVkInterface* vkInterface() const { return fBackendContext->fInterface.get(); } const GrVkCaps& vkCaps() const { return *fVkCaps; } VkDevice device() const { return fDevice; } @@ -182,11 +182,13 @@ private: GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted, const SkTArray<GrMipLevel>&) override { return NULL; } - GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override; + sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override; - GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, - GrWrapOwnership) override; - GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override { return NULL; } + sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, + GrWrapOwnership) override; + sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override { + return nullptr; + } GrBuffer* onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern, const void* data) override; diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp index d6895d25fc..e2f0019d9c 100644 --- a/src/gpu/vk/GrVkRenderTarget.cpp +++ b/src/gpu/vk/GrVkRenderTarget.cpp @@ -201,11 +201,11 @@ GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu, return rt; } -GrVkRenderTarget* -GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu, - const GrSurfaceDesc& desc, - GrWrapOwnership ownership, - const GrVkImageInfo* info) { +sk_sp<GrVkRenderTarget> +GrVkRenderTarget::MakeWrappedRenderTarget(GrVkGpu* gpu, + const GrSurfaceDesc& desc, + GrWrapOwnership ownership, + const GrVkImageInfo* info) { SkASSERT(info); // We can wrap a rendertarget without its allocation, as long as we don't take ownership SkASSERT(VK_NULL_HANDLE != info->fImage); @@ -214,9 +214,8 @@ GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu, GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImage::kBorrowed_Wrapped : GrVkImage::kAdopted_Wrapped; - GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc, *info, wrapped); - - return rt; + return sk_sp<GrVkRenderTarget>( + GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc, *info, wrapped)); } bool GrVkRenderTarget::completeStencilAttachment() { diff --git a/src/gpu/vk/GrVkRenderTarget.h b/src/gpu/vk/GrVkRenderTarget.h index e3ebefba5a..0855a6d020 100644 --- a/src/gpu/vk/GrVkRenderTarget.h +++ b/src/gpu/vk/GrVkRenderTarget.h @@ -34,9 +34,9 @@ public: static GrVkRenderTarget* CreateNewRenderTarget(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&, const GrVkImage::ImageDesc&); - static GrVkRenderTarget* CreateWrappedRenderTarget(GrVkGpu*, const GrSurfaceDesc&, - GrWrapOwnership, - const GrVkImageInfo*); + static sk_sp<GrVkRenderTarget> MakeWrappedRenderTarget(GrVkGpu*, const GrSurfaceDesc&, + GrWrapOwnership, + const GrVkImageInfo*); ~GrVkRenderTarget() override; diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp index bf399a8352..8c461f8308 100644 --- a/src/gpu/vk/GrVkTexture.cpp +++ b/src/gpu/vk/GrVkTexture.cpp @@ -78,10 +78,10 @@ GrVkTexture* GrVkTexture::CreateNewTexture(GrVkGpu* gpu, SkBudgeted budgeted, return new GrVkTexture(gpu, budgeted, desc, info, imageView); } -GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu, - const GrSurfaceDesc& desc, - GrWrapOwnership ownership, - const GrVkImageInfo* info) { +sk_sp<GrVkTexture> GrVkTexture::MakeWrappedTexture(GrVkGpu* gpu, + const GrSurfaceDesc& desc, + GrWrapOwnership ownership, + const GrVkImageInfo* info) { SkASSERT(info); // Wrapped textures require both image and allocation (because they can be mapped) SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc.fMemory); @@ -96,7 +96,7 @@ GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu, GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImage::kBorrowed_Wrapped : GrVkImage::kAdopted_Wrapped; - return new GrVkTexture(gpu, kWrapped, desc, *info, imageView, wrapped); + return sk_sp<GrVkTexture>(new GrVkTexture(gpu, kWrapped, desc, *info, imageView, wrapped)); } GrVkTexture::~GrVkTexture() { diff --git a/src/gpu/vk/GrVkTexture.h b/src/gpu/vk/GrVkTexture.h index 06d147584a..70db54838d 100644 --- a/src/gpu/vk/GrVkTexture.h +++ b/src/gpu/vk/GrVkTexture.h @@ -21,8 +21,8 @@ public: static GrVkTexture* CreateNewTexture(GrVkGpu*, SkBudgeted budgeted, const GrSurfaceDesc&, const GrVkImage::ImageDesc&); - static GrVkTexture* CreateWrappedTexture(GrVkGpu*, const GrSurfaceDesc&, - GrWrapOwnership, const GrVkImageInfo*); + static sk_sp<GrVkTexture> MakeWrappedTexture(GrVkGpu*, const GrSurfaceDesc&, + GrWrapOwnership, const GrVkImageInfo*); ~GrVkTexture() override; diff --git a/src/gpu/vk/GrVkTextureRenderTarget.cpp b/src/gpu/vk/GrVkTextureRenderTarget.cpp index 37b68af827..cfa63be8af 100644 --- a/src/gpu/vk/GrVkTextureRenderTarget.cpp +++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp @@ -135,11 +135,11 @@ GrVkTextureRenderTarget::CreateNewTextureRenderTarget(GrVkGpu* gpu, return trt; } -GrVkTextureRenderTarget* -GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu, - const GrSurfaceDesc& desc, - GrWrapOwnership ownership, - const GrVkImageInfo* info) { +sk_sp<GrVkTextureRenderTarget> +GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(GrVkGpu* gpu, + const GrSurfaceDesc& desc, + GrWrapOwnership ownership, + const GrVkImageInfo* info) { SkASSERT(info); // Wrapped textures require both image and allocation (because they can be mapped) SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc.fMemory); @@ -147,9 +147,7 @@ GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu, GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImage::kBorrowed_Wrapped : GrVkImage::kAdopted_Wrapped; - GrVkTextureRenderTarget* trt = Create(gpu, desc, *info, SkBudgeted::kNo, wrapped); - - return trt; + return sk_sp<GrVkTextureRenderTarget>(Create(gpu, desc, *info, SkBudgeted::kNo, wrapped)); } bool GrVkTextureRenderTarget::updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo) { diff --git a/src/gpu/vk/GrVkTextureRenderTarget.h b/src/gpu/vk/GrVkTextureRenderTarget.h index 2259511066..daa168758d 100644 --- a/src/gpu/vk/GrVkTextureRenderTarget.h +++ b/src/gpu/vk/GrVkTextureRenderTarget.h @@ -28,10 +28,10 @@ public: const GrSurfaceDesc&, const GrVkImage::ImageDesc&); - static GrVkTextureRenderTarget* CreateWrappedTextureRenderTarget(GrVkGpu*, - const GrSurfaceDesc&, - GrWrapOwnership, - const GrVkImageInfo*); + static sk_sp<GrVkTextureRenderTarget> MakeWrappedTextureRenderTarget(GrVkGpu*, + const GrSurfaceDesc&, + GrWrapOwnership, + const GrVkImageInfo*); bool updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo); diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index c9315bb14d..6af8491e73 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -23,17 +23,17 @@ #include "SkMipMap.h" #include "SkPixelRef.h" -SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrTexture* tex, +SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, sk_sp<GrTexture> tex, sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted) : INHERITED(w, h, uniqueID) - , fTexture(SkRef(tex)) + , fTexture(std::move(tex)) , fAlphaType(at) , fBudgeted(budgeted) , fColorSpace(std::move(colorSpace)) , fAddedRasterVersionToCache(false) { - SkASSERT(tex->width() == w); - SkASSERT(tex->height() == h); + SkASSERT(fTexture->width() == w); + SkASSERT(fTexture->height() == h); } SkImage_Gpu::~SkImage_Gpu() { @@ -149,9 +149,9 @@ sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const { if (!subTx) { return nullptr; } - ctx->copySurface(subTx.get(), fTexture, subset, SkIPoint::Make(0, 0)); + ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0, 0)); return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, - fAlphaType, subTx.get(), fColorSpace, fBudgeted); + fAlphaType, std::move(subTx), fColorSpace, fBudgeted); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -164,7 +164,7 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend if (desc.fWidth <= 0 || desc.fHeight <= 0) { return nullptr; } - SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership)); + sk_sp<GrTexture> tex = ctx->textureProvider()->wrapBackendTexture(desc, ownership); if (!tex) { return nullptr; } @@ -174,7 +174,7 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend const SkBudgeted budgeted = SkBudgeted::kNo; return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, - at, tex, colorSpace, budgeted); + at, std::move(tex), std::move(colorSpace), budgeted); } sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, @@ -271,7 +271,7 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect); ctx->flushSurfaceWrites(drawContext->accessRenderTarget()); return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID, - kOpaque_SkAlphaType, drawContext->asTexture().get(), + kOpaque_SkAlphaType, drawContext->asTexture(), sk_ref_sp(drawContext->getColorSpace()), budgeted); } @@ -293,12 +293,12 @@ sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace } static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) { - SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::ClampNoFilter(), - SkSourceGammaTreatment::kRespect)); + sk_sp<GrTexture> texture(maker->refTextureForParams(GrTextureParams::ClampNoFilter(), + SkSourceGammaTreatment::kRespect)); if (!texture) { return nullptr; } - return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture, + return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, std::move(texture), sk_ref_sp(maker->getColorSpace()), SkBudgeted::kNo); } @@ -345,12 +345,12 @@ sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pi if (!ctx) { return nullptr; } - SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgeted)); + sk_sp<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgeted)); if (!texture) { return nullptr; } return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNewImageUniqueID, - pixmap.alphaType(), texture, + pixmap.alphaType(), std::move(texture), sk_ref_sp(pixmap.info().colorSpace()), budgeted); } @@ -702,12 +702,12 @@ sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo& if (!ctx) { return nullptr; } - SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, mipLevelCount)); + sk_sp<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, mipLevelCount)); if (!texture) { return nullptr; } texture->texturePriv().setGammaTreatment(gammaTreatment); return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNewImageUniqueID, - info.alphaType(), texture, sk_ref_sp(info.colorSpace()), - budgeted); + info.alphaType(), std::move(texture), + sk_ref_sp(info.colorSpace()), budgeted); } diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index 02260bcca5..b0380863b5 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -23,7 +23,7 @@ public: * An "image" can be a subset/window into a larger texture, so we explicit take the * width and height. */ - SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*, sk_sp<SkColorSpace>, + SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, sk_sp<GrTexture>, sk_sp<SkColorSpace>, SkBudgeted); ~SkImage_Gpu() override; @@ -43,20 +43,20 @@ public: SkSourceGammaTreatment) const override; sk_sp<SkImage> onMakeSubset(const SkIRect&) const override; - GrTexture* peekTexture() const override { return fTexture; } + GrTexture* peekTexture() const override { return fTexture.get(); } sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const override { *uniqueID = this->uniqueID(); - return sk_ref_sp(fTexture.get()); + return fTexture; } bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint) const override; private: - SkAutoTUnref<GrTexture> fTexture; - const SkAlphaType fAlphaType; - const SkBudgeted fBudgeted; - sk_sp<SkColorSpace> fColorSpace; - mutable SkAtomic<bool> fAddedRasterVersionToCache; + sk_sp<GrTexture> fTexture; + const SkAlphaType fAlphaType; + const SkBudgeted fBudgeted; + sk_sp<SkColorSpace> fColorSpace; + mutable SkAtomic<bool> fAddedRasterVersionToCache; typedef SkImage_Base INHERITED; diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 3007313118..37e8eeb2e9 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -79,7 +79,7 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, SkCopyPixe GrRenderTarget* rt = fDevice->accessDrawContext()->accessRenderTarget(); SkASSERT(rt); GrTexture* tex = rt->asTexture(); - SkAutoTUnref<GrTexture> copy; + sk_sp<GrTexture> copy; // If the original render target is a buffer originally created by the client, then we don't // want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid // copy-on-write. @@ -91,17 +91,17 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, SkCopyPixe if (!copy) { return nullptr; } - if (!ctx->copySurface(copy, rt)) { + if (!ctx->copySurface(copy.get(), rt)) { return nullptr; } - tex = copy; + tex = copy.get(); } const SkImageInfo info = fDevice->imageInfo(); sk_sp<SkImage> image; if (tex) { image = sk_make_sp<SkImage_Gpu>(info.width(), info.height(), kNeedNewImageUniqueID, - info.alphaType(), tex, sk_ref_sp(info.colorSpace()), - budgeted); + info.alphaType(), sk_ref_sp(tex), + sk_ref_sp(info.colorSpace()), budgeted); } return image; } diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp index 7201dc10b0..33ae767ec3 100644 --- a/src/ports/SkFontMgr_win_dw.cpp +++ b/src/ports/SkFontMgr_win_dw.cpp @@ -1085,11 +1085,11 @@ SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, } #include "SkFontMgr_indirect.h" -SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { - SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); - if (impl.get() == nullptr) { +SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(sk_sp<SkRemotableFontMgr> proxy) { + sk_sp<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); + if (!impl) { return nullptr; } - return new SkFontMgr_Indirect(impl.get(), proxy); + return new SkFontMgr_Indirect(std::move(impl), std::move(proxy)); } #endif//defined(SK_BUILD_FOR_WIN32) diff --git a/src/utils/SkDeferredCanvas.h b/src/utils/SkDeferredCanvas.h index 2ac594c903..68574caa73 100644 --- a/src/utils/SkDeferredCanvas.h +++ b/src/utils/SkDeferredCanvas.h @@ -35,7 +35,6 @@ protected: SkImageInfo onImageInfo() const override; bool onGetProps(SkSurfaceProps*) const override; void onFlush() override; -// SkCanvas* canvasForDrawIter() override; void willSave() override; SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; |