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

Side by Side Diff: src/core/SkSpecialSurface.cpp

Issue 1666373002: Fix memory leak in SkSpecialSurface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 4 years, 10 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 | « no previous file | 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 2016 Google Inc. 2 * Copyright 2016 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkSpecialImage.h" 9 #include "SkSpecialImage.h"
10 #include "SkSpecialSurface.h" 10 #include "SkSpecialSurface.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 SkASSERT(fSubset.height() > 0); 47 SkASSERT(fSubset.height() > 0);
48 } 48 }
49 49
50 SkCanvas* SkSpecialSurface::getCanvas() { 50 SkCanvas* SkSpecialSurface::getCanvas() {
51 return as_SB(this)->onGetCanvas(); 51 return as_SB(this)->onGetCanvas();
52 } 52 }
53 53
54 SkSpecialImage* SkSpecialSurface::newImageSnapshot() { 54 SkSpecialImage* SkSpecialSurface::newImageSnapshot() {
55 SkSpecialImage* image = as_SB(this)->onNewImageSnapshot(); 55 SkSpecialImage* image = as_SB(this)->onNewImageSnapshot();
56 as_SB(this)->reset(); 56 as_SB(this)->reset();
57 return SkSafeRef(image); // the caller will call unref() to balance this 57 return image; // the caller gets the creation ref
58 } 58 }
59 59
60 /////////////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////////////
61 #include "SkMallocPixelRef.h" 61 #include "SkMallocPixelRef.h"
62 62
63 class SkSpecialSurface_Raster : public SkSpecialSurface_Base { 63 class SkSpecialSurface_Raster : public SkSpecialSurface_Base {
64 public: 64 public:
65 SkSpecialSurface_Raster(SkPixelRef* pr, const SkIRect& subset, const SkSurfa ceProps* props) 65 SkSpecialSurface_Raster(SkPixelRef* pr, const SkIRect& subset, const SkSurfa ceProps* props)
66 : INHERITED(subset, props) { 66 : INHERITED(subset, props) {
67 const SkImageInfo& info = pr->info(); 67 const SkImageInfo& info = pr->info();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 #if SK_SUPPORT_GPU 104 #if SK_SUPPORT_GPU
105 /////////////////////////////////////////////////////////////////////////////// 105 ///////////////////////////////////////////////////////////////////////////////
106 #include "GrContext.h" 106 #include "GrContext.h"
107 #include "SkGpuDevice.h" 107 #include "SkGpuDevice.h"
108 108
109 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { 109 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base {
110 public: 110 public:
111 SkSpecialSurface_Gpu(GrTexture* texture, const SkIRect& subset, const SkSurf aceProps* props) 111 SkSpecialSurface_Gpu(GrTexture* texture, const SkIRect& subset, const SkSurf aceProps* props)
112 : INHERITED(subset, props) 112 : INHERITED(subset, props)
113 , fTexture(texture) { 113 , fTexture(SkRef(texture)) {
114 114
115 SkASSERT(fTexture->asRenderTarget()); 115 SkASSERT(fTexture->asRenderTarget());
116 116
117 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT arget(), props, 117 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT arget(), props,
118 SkGpuDevice::kUnini t_InitContents)); 118 SkGpuDevice::kUnini t_InitContents));
119 if (!device) { 119 if (!device) {
120 return; 120 return;
121 } 121 }
122 122
123 fCanvas.reset(new SkCanvas(device)); 123 fCanvas.reset(new SkCanvas(device));
(...skipping 20 matching lines...) Expand all
144 return new SkSpecialSurface_Gpu(texture, subset, props); 144 return new SkSpecialSurface_Gpu(texture, subset, props);
145 } 145 }
146 146
147 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context, 147 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context,
148 const GrSurfaceDesc& desc, 148 const GrSurfaceDesc& desc,
149 const SkSurfaceProps* props) { 149 const SkSurfaceProps* props) {
150 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { 150 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
151 return nullptr; 151 return nullptr;
152 } 152 }
153 153
154 GrTexture* temp = context->textureProvider()->createApproxTexture(desc); 154 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture (desc));
155 if (!temp) { 155 if (!temp) {
156 return nullptr; 156 return nullptr;
157 } 157 }
158 158
159 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 159 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
160 160
161 return new SkSpecialSurface_Gpu(temp, subset, props); 161 return new SkSpecialSurface_Gpu(temp, subset, props);
162 } 162 }
163 163
164 #else 164 #else
165 165
166 SkSpecialSurface* SkSpecialSurface::NewFromTexture(const SkIRect& subset, GrText ure*, 166 SkSpecialSurface* SkSpecialSurface::NewFromTexture(const SkIRect& subset, GrText ure*,
167 const SkSurfaceProps*) { 167 const SkSurfaceProps*) {
168 return nullptr; 168 return nullptr;
169 } 169 }
170 170
171 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context, 171 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context,
172 const GrSurfaceDesc& desc, 172 const GrSurfaceDesc& desc,
173 const SkSurfaceProps* props) { 173 const SkSurfaceProps* props) {
174 return nullptr; 174 return nullptr;
175 } 175 }
176 176
177 #endif 177 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698