aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2016-01-08 06:32:31 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-08 06:32:31 -0800
commit06dd0a8222cc97236a2d20d563e27995983e6e0c (patch)
tree114c59d6550e55ed7ff5dc77c8bec30a2b8639ae /src
parent7c554222ddd03d3817ab197a0bd92badc6f1f7c9 (diff)
Fix unref order in SkGpuDevice
GrContext should be unrefed after GrDrawContext. TBR=bsalomon@google.com BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1569833004 Review URL: https://codereview.chromium.org/1569833004
Diffstat (limited to 'src')
-rw-r--r--src/gpu/SkGpuDevice.cpp15
-rw-r--r--src/gpu/SkGpuDevice.h13
2 files changed, 11 insertions, 17 deletions
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 89273be9a3..cd678af880 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -10,7 +10,6 @@
#include "GrBlurUtils.h"
#include "GrContext.h"
#include "SkDraw.h"
-#include "GrDrawContext.h"
#include "GrGpu.h"
#include "GrGpuResourcePriv.h"
#include "GrImageIDTextureAdjuster.h"
@@ -171,13 +170,11 @@ SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height,
const SkSurfaceProps* props, unsigned flags)
: INHERITED(SkSurfacePropsCopyOrDefault(props))
-{
- fContext = SkRef(rt->getContext());
+ , fContext(SkRef(rt->getContext()))
+ , fRenderTarget(SkRef(rt)) {
fNeedClear = SkToBool(flags & kNeedClear_Flag);
fOpaque = SkToBool(flags & kIsOpaque_Flag);
- fRenderTarget = SkRef(rt);
-
SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height);
SkPixelRef* pr = new SkGrPixelRef(info, rt);
@@ -226,11 +223,6 @@ GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
return texture->asRenderTarget();
}
-SkGpuDevice::~SkGpuDevice() {
- fRenderTarget->unref();
- fContext->unref();
-}
-
///////////////////////////////////////////////////////////////////////////////
bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
@@ -346,8 +338,7 @@ void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) {
SkASSERT(fRenderTarget != newRT);
- fRenderTarget->unref();
- fRenderTarget = newRT.detach();
+ fRenderTarget.reset(newRT.detach());
#ifdef SK_DEBUG
SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlphaType :
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index a35e92bc25..19bef21038 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -15,6 +15,7 @@
#include "SkPicture.h"
#include "SkRegion.h"
#include "SkSurface.h"
+#include "GrDrawContext.h"
#include "GrContext.h"
#include "GrSurfacePriv.h"
@@ -53,7 +54,7 @@ public:
static SkGpuDevice* Create(GrContext*, SkSurface::Budgeted, const SkImageInfo&,
int sampleCount, const SkSurfaceProps*, InitContents);
- virtual ~SkGpuDevice();
+ ~SkGpuDevice() override {}
SkGpuDevice* cloneDevice(const SkSurfaceProps& props) {
SkBaseDevice* dev = this->onCreateDevice(CreateInfo(this->imageInfo(), kPossible_TileUsage,
@@ -153,12 +154,14 @@ protected:
const SkMatrix*, const SkPaint*) override;
private:
- GrContext* fContext;
+ // We want these unreffed in DrawContext, RenderTarget, GrContext order.
+ SkAutoTUnref<GrContext> fContext;
+ SkAutoTUnref<GrRenderTarget> fRenderTarget;
+ SkAutoTUnref<GrDrawContext> fDrawContext;
+
SkAutoTUnref<const SkClipStack> fClipStack;
SkIPoint fClipOrigin;
- GrClip fClip;
- SkAutoTUnref<GrDrawContext> fDrawContext;
- GrRenderTarget* fRenderTarget;
+ GrClip fClip;;
// remove when our clients don't rely on accessBitmap()
SkBitmap fLegacyBitmap;
bool fNeedClear;