diff options
author | reed <reed@google.com> | 2015-02-20 10:38:13 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-20 18:39:07 +0000 |
commit | 788518622de2a96d8ed52fd4df99b3a470ce0121 (patch) | |
tree | bf206b96e741abd4416d0d7a9f5d5f4b3a2935a4 | |
parent | 66e9039ed2d73cd7499fd84bad0ba909cbd9a61f (diff) | |
download | chromium_src-788518622de2a96d8ed52fd4df99b3a470ce0121.zip chromium_src-788518622de2a96d8ed52fd4df99b3a470ce0121.tar.gz chromium_src-788518622de2a96d8ed52fd4df99b3a470ce0121.tar.bz2 |
Trim away unused or private Mac functions
patch from issue 937933002 at patchset 1 (http://crrev.com/937933002#ps1)
BUG=
Review URL: https://codereview.chromium.org/942843002
Cr-Commit-Position: refs/heads/master@{#317357}
-rw-r--r-- | skia/ext/bitmap_platform_device_mac.cc | 72 | ||||
-rw-r--r-- | skia/ext/platform_device.h | 17 | ||||
-rw-r--r-- | skia/ext/platform_device_mac.cc | 122 |
3 files changed, 72 insertions, 139 deletions
diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc index ff7c2ad..9c7966d 100644 --- a/skia/ext/bitmap_platform_device_mac.cc +++ b/skia/ext/bitmap_platform_device_mac.cc @@ -71,6 +71,78 @@ void BitmapPlatformDevice::SetMatrixClip( config_dirty_ = true; } +// Loads the specified Skia transform into the device context +static void LoadTransformToCGContext(CGContextRef context, + const SkMatrix& matrix) { + // 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. + + // 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. + SkASSERT(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(); + 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 = + gfx::SkMatrixToCGAffineTransform(transformed_matrix); + + // Load final transform into context. + CGContextConcatCTM(context, cg_matrix); +} + +// Loads a SkRegion into the CG context. +static void 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, gfx::SkRectToCGRect(rect)); + } else if (region.isRect()) { + // CoreGraphics applies the current transform to clip rects, which is + // unwanted. Inverse-transform the rect before sending it to CG. This only + // works for translations and scaling, but not for rotations (but the + // viewport is never rotated anyway). + SkMatrix t; + bool did_invert = transformation.invert(&t); + if (!did_invert) + t.reset(); + // Do the transformation. + SkRect rect; + rect.set(region.getBounds()); + t.mapRect(&rect); + SkIRect irect; + rect.round(&irect); + CGContextClipToRect(context, gfx::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. + SkASSERT(false); + // LoadPathToDC(context, path); + // hrgn = PathToRegion(context); + } +} + void BitmapPlatformDevice::LoadConfig() { if (!config_dirty_ || !bitmap_context_) return; // Nothing to do. diff --git a/skia/ext/platform_device.h b/skia/ext/platform_device.h index 8486102..c903c87 100644 --- a/skia/ext/platform_device.h +++ b/skia/ext/platform_device.h @@ -131,19 +131,6 @@ class SK_API PlatformDevice { // have to be created twice. If src_rect is null, then the entirety of the // source device will be copied. virtual void DrawToHDC(HDC, int x, int y, const RECT* src_rect); - -#elif defined(OS_MACOSX) - // Loads a SkPath into the CG context. The path can there after be used for - // clipping or as a stroke. - static void LoadPathToCGContext(CGContextRef context, const SkPath& path); - - // Initializes the default settings and colors in a device context. - static void InitializeCGContext(CGContextRef context); - - // Loads a SkRegion into the CG context. - static void LoadClippingRegionToCGContext(CGContextRef context, - const SkRegion& region, - const SkMatrix& transformation); #endif protected: @@ -161,10 +148,6 @@ class SK_API PlatformDevice { // Transforms SkPath's paths into a series of cubic path. static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath); -#elif defined(OS_MACOSX) - // Loads the specified Skia transform into the device context - static void LoadTransformToCGContext(CGContextRef context, - const SkMatrix& matrix); #endif }; diff --git a/skia/ext/platform_device_mac.cc b/skia/ext/platform_device_mac.cc index f66372b..065b767 100644 --- a/skia/ext/platform_device_mac.cc +++ b/skia/ext/platform_device_mac.cc @@ -30,126 +30,4 @@ void PlatformDevice::EndPlatformPaint() { // Flushing will be done in onAccessBitmap. } -// Set up the CGContextRef for peaceful coexistence with Skia -void PlatformDevice::InitializeCGContext(CGContextRef context) { - // CG defaults to the same settings as Skia -} - -// static -void PlatformDevice::LoadPathToCGContext(CGContextRef context, - const SkPath& path) { - // instead of a persistent attribute of the context, CG specifies the fill - // type per call, so we just have to load up the geometry. - CGContextBeginPath(context); - - SkPoint points[4] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} }; - SkPath::Iter iter(path, false); - for (SkPath::Verb verb = iter.next(points); verb != SkPath::kDone_Verb; - verb = iter.next(points)) { - switch (verb) { - case SkPath::kMove_Verb: { // iter.next returns 1 point - CGContextMoveToPoint(context, points[0].fX, points[0].fY); - break; - } - case SkPath::kLine_Verb: { // iter.next returns 2 points - CGContextAddLineToPoint(context, points[1].fX, points[1].fY); - break; - } - case SkPath::kQuad_Verb: { // iter.next returns 3 points - CGContextAddQuadCurveToPoint(context, points[1].fX, points[1].fY, - points[2].fX, points[2].fY); - break; - } - case SkPath::kCubic_Verb: { // iter.next returns 4 points - CGContextAddCurveToPoint(context, points[1].fX, points[1].fY, - points[2].fX, points[2].fY, - points[3].fX, points[3].fY); - break; - } - case SkPath::kClose_Verb: { // iter.next returns 1 point (the last point) - break; - } - case SkPath::kDone_Verb: // iter.next returns 0 points - default: { - SkASSERT(false); - break; - } - } - } - CGContextClosePath(context); -} - -// static -void PlatformDevice::LoadTransformToCGContext(CGContextRef context, - const SkMatrix& matrix) { - // 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. - - // 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. - SkASSERT(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 = gfx::SkMatrixToCGAffineTransform( - transformed_matrix); - - // Load final transform into context. - CGContextConcatCTM(context, cg_matrix); -} - -// static -void PlatformDevice::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, gfx::SkRectToCGRect(rect)); - } else if (region.isRect()) { - // CoreGraphics applies the current transform to clip rects, which is - // unwanted. Inverse-transform the rect before sending it to CG. This only - // works for translations and scaling, but not for rotations (but the - // viewport is never rotated anyway). - SkMatrix t; - bool did_invert = transformation.invert(&t); - if (!did_invert) - t.reset(); - // Do the transformation. - SkRect rect; - rect.set(region.getBounds()); - t.mapRect(&rect); - SkIRect irect; - rect.round(&irect); - CGContextClipToRect(context, gfx::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. - SkASSERT(false); - // LoadPathToDC(context, path); - // hrgn = PathToRegion(context); - } -} - } // namespace skia |