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

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

Issue 9416017: Optionally clear PlatformCanvas instances. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Address comments. Created 8 years, 9 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 | « skia/ext/bitmap_platform_device_mac.h ('k') | skia/ext/bitmap_platform_device_win.h » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #import <ApplicationServices/ApplicationServices.h> 7 #import <ApplicationServices/ApplicationServices.h>
8 #include <time.h> 8 #include <time.h>
9 9
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 118 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
119 if (bitmap.allocPixels() != true) 119 if (bitmap.allocPixels() != true)
120 return NULL; 120 return NULL;
121 121
122 void* data = NULL; 122 void* data = NULL;
123 if (context) { 123 if (context) {
124 data = CGBitmapContextGetData(context); 124 data = CGBitmapContextGetData(context);
125 bitmap.setPixels(data); 125 bitmap.setPixels(data);
126 } else { 126 } else {
127 data = bitmap.getPixels(); 127 data = bitmap.getPixels();
128
129 // Note: The Windows implementation clears the Bitmap later on.
130 // This bears mentioning since removal of this line makes the
131 // unit tests only fail periodically (or when MallocPreScribble is set).
132 bitmap.eraseARGB(0, 0, 0, 0);
133 } 128 }
134 129
135 bitmap.setIsOpaque(is_opaque); 130 bitmap.setIsOpaque(is_opaque);
136 131
137 // If we were given data, then don't clobber it! 132 // If we were given data, then don't clobber it!
138 #ifndef NDEBUG 133 #ifndef NDEBUG
139 if (!context && is_opaque) { 134 if (!context && is_opaque) {
140 // To aid in finding bugs, we set the background color to something 135 // To aid in finding bugs, we set the background color to something
141 // obviously wrong so it will be noticable when it is not cleared 136 // obviously wrong so it will be noticable when it is not cleared
142 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green 137 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
(...skipping 10 matching lines...) Expand all
153 BitmapPlatformDevice* rv = new BitmapPlatformDevice( 148 BitmapPlatformDevice* rv = new BitmapPlatformDevice(
154 new BitmapPlatformDeviceData(context), bitmap); 149 new BitmapPlatformDeviceData(context), bitmap);
155 150
156 // The device object took ownership of the graphics context with its own 151 // The device object took ownership of the graphics context with its own
157 // CGContextRetain call. 152 // CGContextRetain call.
158 CGContextRelease(context); 153 CGContextRelease(context);
159 154
160 return rv; 155 return rv;
161 } 156 }
162 157
158 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width,
159 int height,
160 bool is_opaque) {
161 BitmapPlatformDevice* device = Create(NULL, width, height, is_opaque);
162 if (!is_opaque)
163 device->accessBitmap(true).eraseARGB(0, 0, 0, 0);
164 return device;
165 }
166
163 BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data, 167 BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data,
164 int width, 168 int width,
165 int height, 169 int height,
166 bool is_opaque) { 170 bool is_opaque) {
167 CGContextRef context = NULL; 171 CGContextRef context = NULL;
168 if (data) 172 if (data)
169 context = CGContextForData(data, width, height); 173 context = CGContextForData(data, width, height);
170 174
171 BitmapPlatformDevice* rv = Create(context, width, height, is_opaque); 175 BitmapPlatformDevice* rv = Create(context, width, height, is_opaque);
172 176
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 239
236 const SkBitmap& BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { 240 const SkBitmap& BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) {
237 // Not needed in CoreGraphics 241 // Not needed in CoreGraphics
238 return *bitmap; 242 return *bitmap;
239 } 243 }
240 244
241 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( 245 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice(
242 SkBitmap::Config config, int width, int height, bool isOpaque, 246 SkBitmap::Config config, int width, int height, bool isOpaque,
243 Usage /*usage*/) { 247 Usage /*usage*/) {
244 SkASSERT(config == SkBitmap::kARGB_8888_Config); 248 SkASSERT(config == SkBitmap::kARGB_8888_Config);
245 return BitmapPlatformDevice::Create(NULL, width, height, isOpaque); 249 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height,
250 isOpaque);
251 return bitmap_device;
246 } 252 }
247 253
248 } // namespace skia 254 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/bitmap_platform_device_mac.h ('k') | skia/ext/bitmap_platform_device_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698