Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 1569833004: Fix unref order in SkGpuDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "GrBlurUtils.h" 10 #include "GrBlurUtils.h"
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "SkDraw.h" 12 #include "SkDraw.h"
13 #include "GrDrawContext.h"
14 #include "GrGpu.h" 13 #include "GrGpu.h"
15 #include "GrGpuResourcePriv.h" 14 #include "GrGpuResourcePriv.h"
16 #include "GrImageIDTextureAdjuster.h" 15 #include "GrImageIDTextureAdjuster.h"
17 #include "GrLayerHoister.h" 16 #include "GrLayerHoister.h"
18 #include "GrRecordReplaceDraw.h" 17 #include "GrRecordReplaceDraw.h"
19 #include "GrStrokeInfo.h" 18 #include "GrStrokeInfo.h"
20 #include "GrTracing.h" 19 #include "GrTracing.h"
21 #include "SkCanvasPriv.h" 20 #include "SkCanvasPriv.h"
22 #include "SkErrorInternals.h" 21 #include "SkErrorInternals.h"
23 #include "SkGlyphCache.h" 22 #include "SkGlyphCache.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (nullptr == rt) { 163 if (nullptr == rt) {
165 return nullptr; 164 return nullptr;
166 } 165 }
167 166
168 return new SkGpuDevice(rt, info.width(), info.height(), props, flags); 167 return new SkGpuDevice(rt, info.width(), info.height(), props, flags);
169 } 168 }
170 169
171 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, 170 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height,
172 const SkSurfaceProps* props, unsigned flags) 171 const SkSurfaceProps* props, unsigned flags)
173 : INHERITED(SkSurfacePropsCopyOrDefault(props)) 172 : INHERITED(SkSurfacePropsCopyOrDefault(props))
174 { 173 , fContext(SkRef(rt->getContext()))
175 fContext = SkRef(rt->getContext()); 174 , fRenderTarget(SkRef(rt)) {
176 fNeedClear = SkToBool(flags & kNeedClear_Flag); 175 fNeedClear = SkToBool(flags & kNeedClear_Flag);
177 fOpaque = SkToBool(flags & kIsOpaque_Flag); 176 fOpaque = SkToBool(flags & kIsOpaque_Flag);
178 177
179 fRenderTarget = SkRef(rt);
180
181 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; 178 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
182 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); 179 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height);
183 SkPixelRef* pr = new SkGrPixelRef(info, rt); 180 SkPixelRef* pr = new SkGrPixelRef(info, rt);
184 fLegacyBitmap.setInfo(info); 181 fLegacyBitmap.setInfo(info);
185 fLegacyBitmap.setPixelRef(pr)->unref(); 182 fLegacyBitmap.setPixelRef(pr)->unref();
186 183
187 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); 184 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps()));
188 } 185 }
189 186
190 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B udgeted budgeted, 187 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B udgeted budgeted,
(...skipping 28 matching lines...) Expand all
219 desc.fSampleCnt = sampleCount; 216 desc.fSampleCnt = sampleCount;
220 GrTexture* texture = context->textureProvider()->createTexture( 217 GrTexture* texture = context->textureProvider()->createTexture(
221 desc, SkToBool(budgeted), nullptr, 0); 218 desc, SkToBool(budgeted), nullptr, 0);
222 if (nullptr == texture) { 219 if (nullptr == texture) {
223 return nullptr; 220 return nullptr;
224 } 221 }
225 SkASSERT(nullptr != texture->asRenderTarget()); 222 SkASSERT(nullptr != texture->asRenderTarget());
226 return texture->asRenderTarget(); 223 return texture->asRenderTarget();
227 } 224 }
228 225
229 SkGpuDevice::~SkGpuDevice() {
230 fRenderTarget->unref();
231 fContext->unref();
232 }
233
234 /////////////////////////////////////////////////////////////////////////////// 226 ///////////////////////////////////////////////////////////////////////////////
235 227
236 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes, 228 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes,
237 int x, int y) { 229 int x, int y) {
238 DO_DEFERRED_CLEAR(); 230 DO_DEFERRED_CLEAR();
239 231
240 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p ixels 232 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p ixels
241 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo); 233 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo);
242 if (kUnknown_GrPixelConfig == config) { 234 if (kUnknown_GrPixelConfig == config) {
243 return false; 235 return false;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 331
340 if (shouldRetainContent) { 332 if (shouldRetainContent) {
341 if (fRenderTarget->wasDestroyed()) { 333 if (fRenderTarget->wasDestroyed()) {
342 return; 334 return;
343 } 335 }
344 this->context()->copySurface(newRT, fRenderTarget); 336 this->context()->copySurface(newRT, fRenderTarget);
345 } 337 }
346 338
347 SkASSERT(fRenderTarget != newRT); 339 SkASSERT(fRenderTarget != newRT);
348 340
349 fRenderTarget->unref(); 341 fRenderTarget.reset(newRT.detach());
350 fRenderTarget = newRT.detach();
351 342
352 #ifdef SK_DEBUG 343 #ifdef SK_DEBUG
353 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp haType : 344 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp haType :
354 kPremul_SkAlp haType); 345 kPremul_SkAlp haType);
355 SkASSERT(info == fLegacyBitmap.info()); 346 SkASSERT(info == fLegacyBitmap.info());
356 #endif 347 #endif
357 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); 348 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget);
358 fLegacyBitmap.setPixelRef(pr)->unref(); 349 fLegacyBitmap.setPixelRef(pr)->unref();
359 350
360 fDrawContext.reset(this->context()->drawContext(fRenderTarget, &this->surfac eProps())); 351 fDrawContext.reset(this->context()->drawContext(fRenderTarget, &this->surfac eProps()));
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1860 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1870 } 1861 }
1871 1862
1872 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1863 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1873 // We always return a transient cache, so it is freed after each 1864 // We always return a transient cache, so it is freed after each
1874 // filter traversal. 1865 // filter traversal.
1875 return SkGpuDevice::NewImageFilterCache(); 1866 return SkGpuDevice::NewImageFilterCache();
1876 } 1867 }
1877 1868
1878 #endif 1869 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698