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

Side by Side Diff: base/gfx/bitmap_platform_device_mac.cc

Issue 5644: Add platform_canvas_unittest.cc (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 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 | « base/base.xcodeproj/project.pbxproj ('k') | base/gfx/platform_canvas_unittest.cc » ('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) 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 <time.h> 5 #include <time.h>
6 6
7 #include "SkMatrix.h" 7 #include "SkMatrix.h"
8 #include "SkRegion.h" 8 #include "SkRegion.h"
9 #include "SkUtils.h" 9 #include "SkUtils.h"
10 10
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 124
125 void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::LoadConfig() { 125 void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::LoadConfig() {
126 if (!config_dirty_ || !bitmap_context_) 126 if (!config_dirty_ || !bitmap_context_)
127 return; // Nothing to do. 127 return; // Nothing to do.
128 config_dirty_ = false; 128 config_dirty_ = false;
129 129
130 // Transform. 130 // Transform.
131 SkMatrix t(transform_); 131 SkMatrix t(transform_);
132 LoadTransformToCGContext(bitmap_context_, t); 132 LoadTransformToCGContext(bitmap_context_, t);
133
134 t.setTranslateX(-t.getTranslateX()); 133 t.setTranslateX(-t.getTranslateX());
135 t.setTranslateY(-t.getTranslateY()); 134 t.setTranslateY(-t.getTranslateY());
136 LoadClippingRegionToCGContext(bitmap_context_, clip_region_, t); 135 LoadClippingRegionToCGContext(bitmap_context_, clip_region_, t);
137 } 136 }
138 137
139 138
140 // We use this static factory function instead of the regular constructor so 139 // We use this static factory function instead of the regular constructor so
141 // that we can create the pixel data before calling the constructor. This is 140 // that we can create the pixel data before calling the constructor. This is
142 // required so that we can call the base class' constructor with the pixel 141 // required so that we can call the base class' constructor with the pixel
143 // data. 142 // data.
144 BitmapPlatformDeviceMac* BitmapPlatformDeviceMac::Create(CGContextRef context, 143 BitmapPlatformDeviceMac* BitmapPlatformDeviceMac::Create(CGContextRef context,
145 int width, 144 int width,
146 int height, 145 int height,
147 bool is_opaque) { 146 bool is_opaque) {
148 // TODO(playmobil): remove debug code.
149 //printf("BitmapPlatformDeviceMac::Create(%d,%d)\n", width, height);
150 // each pixel is 4 bytes (RGBA):
151 void* data = malloc(height * width * 4); 147 void* data = malloc(height * width * 4);
152 if (!data) return NULL; 148 if (!data) return NULL;
153 149
154 SkBitmap bitmap; 150 SkBitmap bitmap;
155 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 151 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
156 bitmap.setPixels(data); 152 bitmap.setPixels(data);
153
154 // Note: The Windows implementation clears the Bitmap later on.
155 // This bares mentioning since removal of this line makes the
Amanda Walker 2008/10/01 21:32:01 "bares" should be "bears" :-)
156 // unit tests only fail periodically (or when MallocPreScribble is set).
157 bitmap.eraseARGB(0, 0, 0, 0);
158
157 bitmap.setIsOpaque(is_opaque); 159 bitmap.setIsOpaque(is_opaque);
158 160
159 if (is_opaque) { 161 if (is_opaque) {
160 #ifndef NDEBUG 162 #ifndef NDEBUG
161 // To aid in finding bugs, we set the background color to something 163 // To aid in finding bugs, we set the background color to something
162 // obviously wrong so it will be noticable when it is not cleared 164 // obviously wrong so it will be noticable when it is not cleared
163 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green 165 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
164 #endif 166 #endif
165 } 167 }
166 168
167 CGColorSpaceRef color_space = 169 CGColorSpaceRef color_space =
168 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 170 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
169 // allocate a bitmap context with 4 components per pixel (RGBA): 171 // allocate a bitmap context with 4 components per pixel (RGBA):
170 CGContextRef bitmap_context = 172 CGContextRef bitmap_context =
171 CGBitmapContextCreate(data, width, height, 8, width*4, 173 CGBitmapContextCreate(data, width, height, 8, width*4,
172 color_space, kCGImageAlphaPremultipliedLast); 174 color_space, kCGImageAlphaPremultipliedLast);
173 // change the coordinate system to match WebCore's 175
176 // Change the coordinate system to match WebCore's
174 CGContextTranslateCTM(bitmap_context, 0, height); 177 CGContextTranslateCTM(bitmap_context, 0, height);
175 CGContextScaleCTM(bitmap_context, 1.0, -1.0); 178 CGContextScaleCTM(bitmap_context, 1.0, -1.0);
176 CGColorSpaceRelease(color_space); 179 CGColorSpaceRelease(color_space);
177 180
178 // The device object will take ownership of the graphics context. 181 // The device object will take ownership of the graphics context.
179 return new BitmapPlatformDeviceMac( 182 return new BitmapPlatformDeviceMac(
180 new BitmapPlatformDeviceMacData(bitmap_context), bitmap); 183 new BitmapPlatformDeviceMacData(bitmap_context), bitmap);
181 } 184 }
182 185
183 // The device will own the bitmap, which corresponds to also owning the pixel 186 // The device will own the bitmap, which corresponds to also owning the pixel
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x; 280 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x;
278 for (int j = 0; j < width; j++) { 281 for (int j = 0; j < width; j++) {
279 adjustor(data + offset + j); 282 adjustor(data + offset + j);
280 } 283 }
281 } 284 }
282 } 285 }
283 } 286 }
284 287
285 } // namespace gfx 288 } // namespace gfx
286 289
OLDNEW
« no previous file with comments | « base/base.xcodeproj/project.pbxproj ('k') | base/gfx/platform_canvas_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698