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

Unified Diff: skia/ext/platform_device_mac.cc

Issue 951673002: Revert "Pull chromium at 2c3ffb2355a27c32f45e508ef861416b820c823b" (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « skia/ext/platform_device.h ('k') | skia/ext/skia_utils_ios_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/platform_device_mac.cc
diff --git a/skia/ext/platform_device_mac.cc b/skia/ext/platform_device_mac.cc
index 065b7670556380c54872f7ebea5f0192b712d73a..f66372bfe7778903eb0ab6d774a2a745b6f981c7 100644
--- a/skia/ext/platform_device_mac.cc
+++ b/skia/ext/platform_device_mac.cc
@@ -30,4 +30,126 @@ 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
« no previous file with comments | « skia/ext/platform_device.h ('k') | skia/ext/skia_utils_ios_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698