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

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 style issues. Created 8 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 | Annotate | Revision Log
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 108
109 // We use this static factory function instead of the regular constructor so 109 // We use this static factory function instead of the regular constructor so
110 // that we can create the pixel data before calling the constructor. This is 110 // that we can create the pixel data before calling the constructor. This is
111 // required so that we can call the base class' constructor with the pixel 111 // required so that we can call the base class' constructor with the pixel
112 // data. 112 // data.
113 BitmapPlatformDevice* BitmapPlatformDevice::Create(CGContextRef context, 113 BitmapPlatformDevice* BitmapPlatformDevice::Create(CGContextRef context,
114 int width, 114 int width,
115 int height, 115 int height,
116 bool is_opaque) { 116 int flags) {
117 SkBitmap bitmap; 117 SkBitmap bitmap;
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 128
129 // Note: The Windows implementation clears the Bitmap later on. 129 // Note: The Windows implementation clears the Bitmap later on.
130 // This bears mentioning since removal of this line makes the 130 // This bears mentioning since removal of this line makes the
131 // unit tests only fail periodically (or when MallocPreScribble is set). 131 // unit tests only fail periodically (or when MallocPreScribble is set).
132 bitmap.eraseARGB(0, 0, 0, 0); 132 if (flags & FLAGS_INITIALIZED)
133 bitmap.eraseARGB(0, 0, 0, 0);
133 } 134 }
134 135
135 bitmap.setIsOpaque(is_opaque); 136 bitmap.setIsOpaque(flags & FLAGS_OPAQUE);
136 137
137 // If we were given data, then don't clobber it! 138 // If we were given data, then don't clobber it!
138 #ifndef NDEBUG 139 #ifndef NDEBUG
139 if (!context && is_opaque) { 140 if (!context && (flags & FLAGS_OPAQUE)) {
140 // To aid in finding bugs, we set the background color to something 141 // 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 142 // obviously wrong so it will be noticable when it is not cleared
142 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green 143 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
143 } 144 }
144 #endif 145 #endif
145 146
146 if (!context) { 147 if (!context) {
147 context = CGContextForData(data, width, height); 148 context = CGContextForData(data, width, height);
148 if (!context) 149 if (!context)
149 return NULL; 150 return NULL;
150 } else 151 } else
151 CGContextRetain(context); 152 CGContextRetain(context);
152 153
153 BitmapPlatformDevice* rv = new BitmapPlatformDevice( 154 BitmapPlatformDevice* rv = new BitmapPlatformDevice(
154 new BitmapPlatformDeviceData(context), bitmap); 155 new BitmapPlatformDeviceData(context), bitmap);
155 156
156 // The device object took ownership of the graphics context with its own 157 // The device object took ownership of the graphics context with its own
157 // CGContextRetain call. 158 // CGContextRetain call.
158 CGContextRelease(context); 159 CGContextRelease(context);
159 160
160 return rv; 161 return rv;
161 } 162 }
162 163
163 BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data, 164 BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data,
164 int width, 165 int width,
165 int height, 166 int height,
166 bool is_opaque) { 167 int flags) {
167 CGContextRef context = NULL; 168 CGContextRef context = NULL;
168 if (data) 169 if (data)
169 context = CGContextForData(data, width, height); 170 context = CGContextForData(data, width, height);
170 171
171 BitmapPlatformDevice* rv = Create(context, width, height, is_opaque); 172 BitmapPlatformDevice* rv = Create(context, width, height, flags);
172 173
173 // The device object took ownership of the graphics context with its own 174 // The device object took ownership of the graphics context with its own
174 // CGContextRetain call. 175 // CGContextRetain call.
175 if (context) 176 if (context)
176 CGContextRelease(context); 177 CGContextRelease(context);
177 178
178 return rv; 179 return rv;
179 } 180 }
180 181
181 // The device will own the bitmap, which corresponds to also owning the pixel 182 // The device will own the bitmap, which corresponds to also owning the pixel
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 236
236 const SkBitmap& BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { 237 const SkBitmap& BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) {
237 // Not needed in CoreGraphics 238 // Not needed in CoreGraphics
238 return *bitmap; 239 return *bitmap;
239 } 240 }
240 241
241 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( 242 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice(
242 SkBitmap::Config config, int width, int height, bool isOpaque, 243 SkBitmap::Config config, int width, int height, bool isOpaque,
243 Usage /*usage*/) { 244 Usage /*usage*/) {
244 SkASSERT(config == SkBitmap::kARGB_8888_Config); 245 SkASSERT(config == SkBitmap::kARGB_8888_Config);
245 return BitmapPlatformDevice::Create(NULL, width, height, isOpaque); 246 return BitmapPlatformDevice::Create(NULL, width, height,
247 GetDefaultFlags(isOpaque));
246 } 248 }
247 249
248 } // namespace skia 250 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698