aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2018-07-12 13:30:47 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-12 20:59:20 +0000
commit9ec70c6bd3dfe6338fbbae9c0447a5cbae770a75 (patch)
treefe9dcd75fcc80ce6c3d52a6d18cf8639b8aed485
parentc434ade20eba4a62c450b7ce33a89966fac9df62 (diff)
Remove SkSafeSetNull.
Update all users to sk_sp. Change-Id: I6453b9456b9a8f9e2b756381797f1382ef9e6561 Reviewed-on: https://skia-review.googlesource.com/141052 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Herb Derby <herb@google.com>
-rw-r--r--bench/SKPBench.cpp13
-rw-r--r--bench/SKPBench.h4
-rw-r--r--include/core/SkRefCnt.h7
-rw-r--r--include/gpu/GrRenderTarget.h3
-rw-r--r--src/gpu/GrDrawingManager.cpp16
-rw-r--r--src/gpu/GrDrawingManager.h4
-rw-r--r--src/gpu/GrRenderTarget.cpp10
-rw-r--r--src/gpu/GrRenderTargetPriv.h4
-rw-r--r--src/utils/win/SkWGL.h4
-rw-r--r--src/utils/win/SkWGL_win.cpp7
-rw-r--r--tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp4
11 files changed, 36 insertions, 40 deletions
diff --git a/bench/SKPBench.cpp b/bench/SKPBench.cpp
index 2612021510..764119685d 100644
--- a/bench/SKPBench.cpp
+++ b/bench/SKPBench.cpp
@@ -62,7 +62,7 @@ void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) {
int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(tileW));
int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(tileH));
- fSurfaces.setReserve(xTiles * yTiles);
+ fSurfaces.reserve(xTiles * yTiles);
fTileRects.setReserve(xTiles * yTiles);
SkImageInfo ii = canvas->imageInfo().makeWH(tileW, tileH);
@@ -71,16 +71,16 @@ void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) {
for (int x = bounds.fLeft; x < bounds.fRight; x += tileW) {
const SkIRect tileRect = SkIRect::MakeXYWH(x, y, tileW, tileH);
*fTileRects.append() = tileRect;
- *fSurfaces.push() = canvas->makeSurface(ii).release();
+ fSurfaces.emplace_back(canvas->makeSurface(ii));
// Never want the contents of a tile to include stuff the parent
// canvas clips out
SkRect clip = SkRect::Make(bounds);
clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.fTop));
- fSurfaces.top()->getCanvas()->clipRect(clip);
+ fSurfaces.back()->getCanvas()->clipRect(clip);
- fSurfaces.top()->getCanvas()->setMatrix(canvas->getTotalMatrix());
- fSurfaces.top()->getCanvas()->scale(fScale, fScale);
+ fSurfaces.back()->getCanvas()->setMatrix(canvas->getTotalMatrix());
+ fSurfaces.back()->getCanvas()->scale(fScale, fScale);
}
}
}
@@ -92,10 +92,9 @@ void SKPBench::onPerCanvasPostDraw(SkCanvas* canvas) {
sk_sp<SkImage> image(fSurfaces[i]->makeImageSnapshot());
canvas->drawImage(image,
SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTileRects[i].fTop));
- SkSafeSetNull(fSurfaces[i]);
}
- fSurfaces.rewind();
+ fSurfaces.reset();
fTileRects.rewind();
}
diff --git a/bench/SKPBench.h b/bench/SKPBench.h
index 2874bff8b0..44ebc6fd85 100644
--- a/bench/SKPBench.h
+++ b/bench/SKPBench.h
@@ -43,7 +43,7 @@ protected:
virtual void drawPicture();
const SkPicture* picture() const { return fPic.get(); }
- const SkTDArray<SkSurface*>& surfaces() const { return fSurfaces; }
+ const SkTArray<sk_sp<SkSurface>, true>& surfaces() const { return fSurfaces; }
const SkTDArray<SkIRect>& tileRects() const { return fTileRects; }
private:
@@ -54,7 +54,7 @@ private:
SkString fUniqueName;
const bool fUseMultiPictureDraw;
- SkTDArray<SkSurface*> fSurfaces; // for MultiPictureDraw
+ SkTArray<sk_sp<SkSurface>, true> fSurfaces; // for MultiPictureDraw
SkTDArray<SkIRect> fTileRects; // for MultiPictureDraw
const bool fDoLooping;
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index d919c8114c..adebd9b8a6 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -199,13 +199,6 @@ template <typename T> static inline void SkSafeUnref(T* obj) {
}
}
-template<typename T> static inline void SkSafeSetNull(T*& obj) {
- if (obj) {
- obj->unref();
- obj = nullptr;
- }
-}
-
///////////////////////////////////////////////////////////////////////////////
// This is a variant of SkRefCnt that's Not Virtual, so weighs 4 bytes instead of 8 or 16.
diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h
index 784e15f8b0..32c6225d29 100644
--- a/include/gpu/GrRenderTarget.h
+++ b/include/gpu/GrRenderTarget.h
@@ -110,6 +110,7 @@ public:
protected:
GrRenderTarget(GrGpu*, const GrSurfaceDesc&, GrStencilAttachment* = nullptr);
+ ~GrRenderTarget() override;
// override of GrResource
void onAbandon() override;
@@ -125,7 +126,7 @@ private:
friend class GrRenderTargetPriv;
int fSampleCnt;
- GrStencilAttachment* fStencilAttachment;
+ sk_sp<GrStencilAttachment> fStencilAttachment;
SkIRect fResolveRect;
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 30d0016d67..0df9b34468 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -80,9 +80,8 @@ void GrDrawingManager::cleanup() {
fOpLists.reset();
- delete fPathRendererChain;
fPathRendererChain = nullptr;
- SkSafeSetNull(fSoftwarePathRenderer);
+ fSoftwarePathRenderer = nullptr;
fOnFlushCBObjects.reset();
}
@@ -105,9 +104,8 @@ void GrDrawingManager::freeGpuResources() {
}
// a path renderer may be holding onto resources
- delete fPathRendererChain;
fPathRendererChain = nullptr;
- SkSafeSetNull(fSoftwarePathRenderer);
+ fSoftwarePathRenderer = nullptr;
}
// MDB TODO: make use of the 'proxy' parameter.
@@ -498,7 +496,7 @@ GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawP
GrPathRenderer::StencilSupport* stencilSupport) {
if (!fPathRendererChain) {
- fPathRendererChain = new GrPathRendererChain(fContext, fOptionsForPathRendererChain);
+ fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain));
}
GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport);
@@ -514,16 +512,16 @@ GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawP
GrPathRenderer* GrDrawingManager::getSoftwarePathRenderer() {
if (!fSoftwarePathRenderer) {
- fSoftwarePathRenderer =
+ fSoftwarePathRenderer.reset(
new GrSoftwarePathRenderer(fContext->contextPriv().proxyProvider(),
- fOptionsForPathRendererChain.fAllowPathMaskCaching);
+ fOptionsForPathRendererChain.fAllowPathMaskCaching));
}
- return fSoftwarePathRenderer;
+ return fSoftwarePathRenderer.get();
}
GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRenderer() {
if (!fPathRendererChain) {
- fPathRendererChain = new GrPathRendererChain(fContext, fOptionsForPathRendererChain);
+ fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain));
}
return fPathRendererChain->getCoverageCountingPathRenderer();
}
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index 91d1629348..bd2927eb36 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -125,8 +125,8 @@ private:
std::unique_ptr<GrTextContext> fTextContext;
- GrPathRendererChain* fPathRendererChain;
- GrSoftwarePathRenderer* fSoftwarePathRenderer;
+ std::unique_ptr<GrPathRendererChain> fPathRendererChain;
+ sk_sp<GrSoftwarePathRenderer> fSoftwarePathRenderer;
GrTokenTracker fTokenTracker;
bool fFlushing;
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index c39723507a..00b4d29ffc 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -29,6 +29,8 @@ GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc,
fResolveRect = SkRectPriv::MakeILargestInverted();
}
+GrRenderTarget::~GrRenderTarget() = default;
+
void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
if (kCanResolve_ResolveType == getResolveType()) {
if (rect) {
@@ -58,13 +60,13 @@ void GrRenderTarget::flagAsResolved() {
}
void GrRenderTarget::onRelease() {
- SkSafeSetNull(fStencilAttachment);
+ fStencilAttachment = nullptr;
INHERITED::onRelease();
}
void GrRenderTarget::onAbandon() {
- SkSafeSetNull(fStencilAttachment);
+ fStencilAttachment = nullptr;
INHERITED::onAbandon();
}
@@ -77,9 +79,9 @@ bool GrRenderTargetPriv::attachStencilAttachment(sk_sp<GrStencilAttachment> sten
// we're not actually adding one.
return true;
}
- fRenderTarget->fStencilAttachment = stencil.release();
+ fRenderTarget->fStencilAttachment = std::move(stencil);
if (!fRenderTarget->completeStencilAttachment()) {
- SkSafeSetNull(fRenderTarget->fStencilAttachment);
+ fRenderTarget->fStencilAttachment = nullptr;
return false;
}
return true;
diff --git a/src/gpu/GrRenderTargetPriv.h b/src/gpu/GrRenderTargetPriv.h
index 71ef809951..aa981fd535 100644
--- a/src/gpu/GrRenderTargetPriv.h
+++ b/src/gpu/GrRenderTargetPriv.h
@@ -21,7 +21,9 @@ public:
/**
* GrStencilAttachment is not part of the public API.
*/
- GrStencilAttachment* getStencilAttachment() const { return fRenderTarget->fStencilAttachment; }
+ GrStencilAttachment* getStencilAttachment() const {
+ return fRenderTarget->fStencilAttachment.get();
+ }
/**
* Attaches the GrStencilAttachment onto the render target. If stencil is a nullptr then the
diff --git a/src/utils/win/SkWGL.h b/src/utils/win/SkWGL.h
index cd19f2eeba..6aafdcdbc0 100644
--- a/src/utils/win/SkWGL.h
+++ b/src/utils/win/SkWGL.h
@@ -145,8 +145,8 @@ HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool deepColor, SkWGLConte
*/
class SkWGLPbufferContext : public SkRefCnt {
public:
- static SkWGLPbufferContext* Create(HDC parentDC, SkWGLContextRequest contextType,
- HGLRC shareContext);
+ static sk_sp<SkWGLPbufferContext> Create(HDC parentDC, SkWGLContextRequest contextType,
+ HGLRC shareContext);
virtual ~SkWGLPbufferContext();
diff --git a/src/utils/win/SkWGL_win.cpp b/src/utils/win/SkWGL_win.cpp
index 441d7a4ebb..90b683e3c0 100644
--- a/src/utils/win/SkWGL_win.cpp
+++ b/src/utils/win/SkWGL_win.cpp
@@ -443,8 +443,9 @@ HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool deepColor,
return create_gl_context(dc, extensions, contextType, shareContext);
}
-SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, SkWGLContextRequest contextType,
- HGLRC shareContext) {
+sk_sp<SkWGLPbufferContext> SkWGLPbufferContext::Create(HDC parentDC,
+ SkWGLContextRequest contextType,
+ HGLRC shareContext) {
SkWGLExtensions extensions;
if (!extensions.hasExtension(parentDC, "WGL_ARB_pixel_format") ||
!extensions.hasExtension(parentDC, "WGL_ARB_pbuffer")) {
@@ -485,7 +486,7 @@ SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, SkWGLContextReque
if (dc) {
HGLRC glrc = create_gl_context(dc, extensions, contextType, shareContext);
if (glrc) {
- return new SkWGLPbufferContext(pbuf, dc, glrc);
+ return sk_sp<SkWGLPbufferContext>(new SkWGLPbufferContext(pbuf, dc, glrc));
}
extensions.releasePbufferDC(pbuf, dc);
}
diff --git a/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp b/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp
index 669d6d0182..c09f0b3258 100644
--- a/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp
+++ b/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp
@@ -39,7 +39,7 @@ private:
HDC fDeviceContext;
HGLRC fGlRenderContext;
static ATOM gWC;
- SkWGLPbufferContext* fPbufferContext;
+ sk_sp<SkWGLPbufferContext> fPbufferContext;
};
ATOM WinGLTestContext::gWC = 0;
@@ -148,7 +148,7 @@ WinGLTestContext::~WinGLTestContext() {
}
void WinGLTestContext::destroyGLContext() {
- SkSafeSetNull(fPbufferContext);
+ fPbufferContext = nullptr;
if (fGlRenderContext) {
// This deletes the context immediately even if it is current.
wglDeleteContext(fGlRenderContext);