diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-29 23:40:02 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-29 23:40:02 +0000 |
commit | 6e9d0ce099bde00d35abc8a8deef0ad728efda7e (patch) | |
tree | 5e3423bd964bad498d275d79303fdf9fc12c3a39 /base/gfx/platform_device_mac.cc | |
parent | 7be5131b5e012054c7a162a95f3b3cc0793c5e34 (diff) | |
download | chromium_src-6e9d0ce099bde00d35abc8a8deef0ad728efda7e.zip chromium_src-6e9d0ce099bde00d35abc8a8deef0ad728efda7e.tar.gz chromium_src-6e9d0ce099bde00d35abc8a8deef0ad728efda7e.tar.bz2 |
Sync Mac canvas implementation with Windows version, still a work in progress,
not all unit tests pass yet.
Review URL: http://codereview.chromium.org/4339
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2702 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/gfx/platform_device_mac.cc')
-rwxr-xr-x | base/gfx/platform_device_mac.cc | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/base/gfx/platform_device_mac.cc b/base/gfx/platform_device_mac.cc index 9185dae..ab0b188 100755 --- a/base/gfx/platform_device_mac.cc +++ b/base/gfx/platform_device_mac.cc @@ -97,10 +97,73 @@ void PlatformDeviceMac::LoadPathToCGContext(CGContextRef context, // static void PlatformDeviceMac::LoadTransformToCGContext(CGContextRef context, const SkMatrix& matrix) { - // TOOD: CoreGraphics can concatenate transforms, but not reset the current - // ont. Either find a workaround or remove this function if it turns out + // 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. + + // 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); + + // 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); } +// static +void PlatformDeviceMac::LoadClippingRegionToCGContext( + CGContextRef context, + const SkRegion& region, + const SkMatrix& transformation) { + if (region.isEmpty()) { + // region can be empty, in which case everything will be clipped. + SkRect rect; + rect.setEmpty(); + CGContextClipToRect(context, SkRectToCGRect(rect)); + } else if (region.isRect()) { + // Do the transformation. + SkRect rect; + rect.set(region.getBounds()); + 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. + SkPath path; + region.getBoundaryPath(&path); + // Clip. Note that windows clipping regions are not affected by the + // transform so apply it manually. + path.transform(transformation); + // TODO(playmobil): Implement. + NOTREACHED(); + // LoadPathToDC(context, path); + // hrgn = PathToRegion(context); + } +} + } // namespace gfx |