diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-01 21:40:28 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-01 21:40:28 +0000 |
commit | dc4f63c80cb90efe594131030aad6776e5945fcc (patch) | |
tree | 28c988d870db5b25535b333eb7676f6584329bea | |
parent | a2914d54e7d8f460cfd98b1ba02d0aa86bacbd45 (diff) | |
download | chromium_src-dc4f63c80cb90efe594131030aad6776e5945fcc.zip chromium_src-dc4f63c80cb90efe594131030aad6776e5945fcc.tar.gz chromium_src-dc4f63c80cb90efe594131030aad6776e5945fcc.tar.bz2 |
Add platform_canvas_unittest.cc
Also fixes issue 2977.
Review URL: http://codereview.chromium.org/5644
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2777 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.xcodeproj/project.pbxproj | 2 | ||||
-rwxr-xr-x | base/gfx/bitmap_platform_device_mac.cc | 13 | ||||
-rw-r--r-- | base/gfx/platform_canvas_unittest.cc | 6 | ||||
-rwxr-xr-x | base/gfx/platform_device_mac.cc | 56 | ||||
-rw-r--r-- | base/gfx/skia_utils_mac.cc | 16 | ||||
-rw-r--r-- | base/gfx/skia_utils_mac.h | 4 |
6 files changed, 58 insertions, 39 deletions
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj index b8db42e..51ace0b 100644 --- a/base/base.xcodeproj/project.pbxproj +++ b/base/base.xcodeproj/project.pbxproj @@ -162,6 +162,7 @@ ABF4B9BE0DC2BD1500A6E319 /* sha512.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825403700D92D2840006B936 /* sha512.cc */; }; ABF4B9C30DC2BD6C00A6E319 /* values.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825403880D92D2CF0006B936 /* values.cc */; }; ABFBD3E60DC793C600E164CB /* md5.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825403290D92D2090006B936 /* md5.cc */; }; + B5EF235C0E89ABF500E1E114 /* platform_canvas_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABE1BA0C0E756EC4009041DA /* platform_canvas_unittest.cc */; }; BA0F69870E79D7980079A8A1 /* thread_local_storage_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA0F69860E79D7980079A8A1 /* thread_local_storage_unittest.cc */; }; BA5CC5840E788093004EDD45 /* shared_memory_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA5CC5830E788093004EDD45 /* shared_memory_unittest.cc */; }; BA739A020E5E3242009842A7 /* tracked_objects_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA739A000E5E3242009842A7 /* tracked_objects_unittest.cc */; }; @@ -1432,6 +1433,7 @@ 7B78D3950E54FE0100609465 /* observer_list_unittest.cc in Sources */, 7B78D3960E54FE0100609465 /* path_service_unittest.cc in Sources */, 7B78D3970E54FE0100609465 /* pickle_unittest.cc in Sources */, + B5EF235C0E89ABF500E1E114 /* platform_canvas_unittest.cc in Sources */, A5CB82980E5C74E300FD6825 /* platform_test_mac.mm in Sources */, 7B8505D50E5B441000730B43 /* png_codec_unittest.cc in Sources */, 7B78D3980E54FE0100609465 /* pr_time_unittest.cc in Sources */, diff --git a/base/gfx/bitmap_platform_device_mac.cc b/base/gfx/bitmap_platform_device_mac.cc index 40b58cf..570b07e 100755 --- a/base/gfx/bitmap_platform_device_mac.cc +++ b/base/gfx/bitmap_platform_device_mac.cc @@ -130,7 +130,6 @@ void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::LoadConfig() { // Transform. SkMatrix t(transform_); LoadTransformToCGContext(bitmap_context_, t); - t.setTranslateX(-t.getTranslateX()); t.setTranslateY(-t.getTranslateY()); LoadClippingRegionToCGContext(bitmap_context_, clip_region_, t); @@ -145,15 +144,18 @@ BitmapPlatformDeviceMac* BitmapPlatformDeviceMac::Create(CGContextRef context, int width, int height, bool is_opaque) { - // TODO(playmobil): remove debug code. - //printf("BitmapPlatformDeviceMac::Create(%d,%d)\n", width, height); - // each pixel is 4 bytes (RGBA): void* data = malloc(height * width * 4); if (!data) return NULL; SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); bitmap.setPixels(data); + + // Note: The Windows implementation clears the Bitmap later on. + // This bears mentioning since removal of this line makes the + // unit tests only fail periodically (or when MallocPreScribble is set). + bitmap.eraseARGB(0, 0, 0, 0); + bitmap.setIsOpaque(is_opaque); if (is_opaque) { @@ -170,7 +172,8 @@ BitmapPlatformDeviceMac* BitmapPlatformDeviceMac::Create(CGContextRef context, CGContextRef bitmap_context = CGBitmapContextCreate(data, width, height, 8, width*4, color_space, kCGImageAlphaPremultipliedLast); - // change the coordinate system to match WebCore's + + // Change the coordinate system to match WebCore's CGContextTranslateCTM(bitmap_context, 0, height); CGContextScaleCTM(bitmap_context, 1.0, -1.0); CGColorSpaceRelease(color_space); diff --git a/base/gfx/platform_canvas_unittest.cc b/base/gfx/platform_canvas_unittest.cc index 81e5c75..8e227ad 100644 --- a/base/gfx/platform_canvas_unittest.cc +++ b/base/gfx/platform_canvas_unittest.cc @@ -78,8 +78,10 @@ void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { CGContextRef context = canvas.beginPlatformPaint(); CGRect inner_rc = CGRectMake(x, y, w, h); - CGFloat black[] = { 0.0, 0.0, 0.0, 1.0 }; // RGBA opaque black - CGContextSetFillColor(context, black); + // RGBA opaque black + CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0); + CGContextSetFillColorWithColor(context, black); + CGColorRelease(black); CGContextFillRect(context, inner_rc); canvas.endPlatformPaint(); diff --git a/base/gfx/platform_device_mac.cc b/base/gfx/platform_device_mac.cc index ab0b188..93909f1 100755 --- a/base/gfx/platform_device_mac.cc +++ b/base/gfx/platform_device_mac.cc @@ -97,37 +97,32 @@ void PlatformDeviceMac::LoadPathToCGContext(CGContextRef context, // static void PlatformDeviceMac::LoadTransformToCGContext(CGContextRef context, const SkMatrix& matrix) { - // TODO: CoreGraphics can concatenate transforms, but not reset the current - // one. Either find a workaround or remove this function if it turns out - // to be unneeded on the Mac. - // For now, just load the translation. + // CoreGraphics can concatenate transforms, but not reset the current one. + // So in order to get the required behavior here, we need to first make + // the current transformation matrix identity and only then load the new one. - // First reset the Transforms. - // TODO(playmobil): no need to call CGContextTranslateCTM() twice - // just add up the numbers and call through. - CGAffineTransform orig_transform = CGContextGetCTM(context); - CGContextTranslateCTM(context, - -orig_transform.tx, - orig_transform.ty); // y axis is flipped. - - // TODO(playmobil): remove debug code. - // CGAffineTransform temp_transform = CGContextGetCTM(context); + // Reset matrix to identity. + CGAffineTransform orig_cg_matrix = CGContextGetCTM(context); + CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(orig_cg_matrix); + CGContextConcatCTM(context, orig_cg_matrix_inv); + + // assert that we have indeed returned to the identity Matrix. + DCHECK(CGAffineTransformIsIdentity(CGContextGetCTM(context))); + + // Convert xform to CG-land. + // Our coordinate system is flipped to match WebKit's so we need to modify + // the xform to match that. + SkMatrix transformed_matrix = matrix; + SkScalar sy = matrix.getScaleY() * (SkScalar)-1; + transformed_matrix.setScaleY(sy); + size_t height = CGBitmapContextGetHeight(context); + SkScalar ty = -matrix.getTranslateY(); // y axis is flipped. + transformed_matrix.setTranslateY(ty + (SkScalar)height); + + CGAffineTransform cg_matrix = SkMatrixToCGAffineTransform(transformed_matrix); - // Now set the new transform. - int tx = matrix.getTranslateX(); - int ty = -matrix.getTranslateY(); - int height = CGBitmapContextGetHeight(context); - CGContextTranslateCTM(context, - tx, - -(ty+height)); - CGAffineTransform new_transform = CGContextGetCTM(context); -// TODO(playmobil): remove debug code. -// printf("tx_matrix (%lf,%lf)->(%lf,%lf)->(%lf,%lf) (%d, %d) height=%d\n", orig_transform.tx, -// orig_transform.ty, -// foo_transform.tx, -// foo_transform.ty, -// new_transform.tx, -// new_transform.ty, tx, ty, height); + // Load final transform into context. + CGContextConcatCTM(context, cg_matrix); } // static @@ -147,9 +142,6 @@ void PlatformDeviceMac::LoadClippingRegionToCGContext( transformation.mapRect(&rect); SkIRect irect; rect.round(&irect); -// TODO(playmobil): remove debug code. -// printf("Clipping to (%d,%d) (%d,%d)\n", irect.fLeft, irect.fTop, -// irect.fRight, irect.fBottom); CGContextClipToRect(context, SkIRectToCGRect(irect)); } else { // It is complex. diff --git a/base/gfx/skia_utils_mac.cc b/base/gfx/skia_utils_mac.cc index d9ccb3f..b5962c3 100644 --- a/base/gfx/skia_utils_mac.cc +++ b/base/gfx/skia_utils_mac.cc @@ -5,10 +5,26 @@ #include "base/gfx/skia_utils_mac.h" #include "base/logging.h" +#include "SkMatrix.h" #include "SkRect.h" namespace gfx { +CGAffineTransform SkMatrixToCGAffineTransform(const SkMatrix& matrix) { + // CGAffineTransforms don't support perspective transforms, so make sure + // we don't get those. + DCHECK(matrix[SkMatrix::kMPersp0] == 0.0f); + DCHECK(matrix[SkMatrix::kMPersp1] == 0.0f); + DCHECK(matrix[SkMatrix::kMPersp2] == 1.0f); + + return CGAffineTransformMake(matrix[SkMatrix::kMScaleX], + matrix[SkMatrix::kMSkewY], + matrix[SkMatrix::kMSkewX], + matrix[SkMatrix::kMScaleY], + matrix[SkMatrix::kMTransX], + matrix[SkMatrix::kMTransY]); +} + SkIRect CGRectToSkIRect(const CGRect& rect) { SkIRect sk_rect = { SkScalarRound(rect.origin.x), diff --git a/base/gfx/skia_utils_mac.h b/base/gfx/skia_utils_mac.h index c1419c2..a99905f 100644 --- a/base/gfx/skia_utils_mac.h +++ b/base/gfx/skia_utils_mac.h @@ -9,6 +9,7 @@ #include "SkColor.h" #include <CoreGraphics/CGColor.h> +struct SkMatrix; struct SkIRect; struct SkPoint; struct SkRect; @@ -26,6 +27,9 @@ inline const CGPoint& SkPointToCGPoint(const SkPoint& point) { inline const SkPoint& CGPointToSkPoint(const CGPoint& point) { return reinterpret_cast<const SkPoint&>(point); } + +// Matrix converters. +CGAffineTransform SkMatrixToCGAffineTransform(const SkMatrix& matrix); // Rectangle converters. SkRect CGRectToSkRect(const CGRect& rect); |