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

Side by Side Diff: skia/ext/bitmap_platform_device_mac.cc

Issue 126159: Stop leaking CGBitmapContextRefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | Annotate | Revision Log
« 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 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "skia/ext/bitmap_platform_device_mac.h" 5 #include "skia/ext/bitmap_platform_device_mac.h"
6 6
7 #include <time.h> 7 #include <time.h>
8 8
9 #include "base/ref_counted.h" 9 #include "base/ref_counted.h"
10 #include "skia/ext/skia_utils_mac.h" 10 #include "skia/ext/skia_utils_mac.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 #ifndef NDEBUG 202 #ifndef NDEBUG
203 if (is_opaque) { 203 if (is_opaque) {
204 // To aid in finding bugs, we set the background color to something 204 // To aid in finding bugs, we set the background color to something
205 // obviously wrong so it will be noticable when it is not cleared 205 // obviously wrong so it will be noticable when it is not cleared
206 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green 206 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
207 } 207 }
208 #endif 208 #endif
209 209
210 if (!context) 210 if (!context)
211 context = CGContextForData(data, width, height); 211 context = CGContextForData(data, width, height);
212 else
213 CGContextRetain(context);
212 214
213 // The device object will take ownership of the graphics context. 215 BitmapPlatformDevice* rv = new BitmapPlatformDevice(
214 return new BitmapPlatformDevice(
215 new BitmapPlatformDeviceData(context), bitmap); 216 new BitmapPlatformDeviceData(context), bitmap);
217
218 // The device object took ownership of the graphics context with its own
219 // CGContextRetain call.
220 CGContextRelease(context);
221
222 return rv;
216 } 223 }
217 224
218 BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data, 225 BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data,
219 int width, 226 int width,
220 int height, 227 int height,
221 bool is_opaque) { 228 bool is_opaque) {
222 CGContextRef context = NULL; 229 CGContextRef context = NULL;
223 if (data) 230 if (data)
224 context = CGContextForData(data, width, height); 231 context = CGContextForData(data, width, height);
225 232
226 return Create(context, width, height, is_opaque); 233 BitmapPlatformDevice* rv = Create(context, width, height, is_opaque);
234
235 // The device object took ownership of the graphics context with its own
236 // CGContextRetain call.
237 if (context)
238 CGContextRelease(context);
239
240 return rv;
227 } 241 }
228 242
229 // The device will own the bitmap, which corresponds to also owning the pixel 243 // The device will own the bitmap, which corresponds to also owning the pixel
230 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. 244 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
231 BitmapPlatformDevice::BitmapPlatformDevice( 245 BitmapPlatformDevice::BitmapPlatformDevice(
232 BitmapPlatformDeviceData* data, const SkBitmap& bitmap) 246 BitmapPlatformDeviceData* data, const SkBitmap& bitmap)
233 : PlatformDevice(bitmap), 247 : PlatformDevice(bitmap),
234 data_(data) { 248 data_(data) {
235 } 249 }
236 250
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 for (int i = 0; i < height; i++) { 339 for (int i = 0; i < height; i++) {
326 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x; 340 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x;
327 for (int j = 0; j < width; j++) { 341 for (int j = 0; j < width; j++) {
328 adjustor(data + offset + j); 342 adjustor(data + offset + j);
329 } 343 }
330 } 344 }
331 } 345 }
332 } 346 }
333 347
334 } // namespace skia 348 } // namespace skia
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