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

Side by Side Diff: skia/ext/skia_utils_mac.mm

Issue 9104010: Set CG clip to empty explicitly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "skia/ext/skia_utils_mac.h" 5 #include "skia/ext/skia_utils_mac.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst); 326 kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
327 327
328 // Apply device matrix. 328 // Apply device matrix.
329 CGAffineTransform contentsTransform = CGAffineTransformMakeScale(1, -1); 329 CGAffineTransform contentsTransform = CGAffineTransformMakeScale(1, -1);
330 contentsTransform = CGAffineTransformTranslate(contentsTransform, 0, 330 contentsTransform = CGAffineTransformTranslate(contentsTransform, 0,
331 -device->height()); 331 -device->height());
332 CGContextConcatCTM(cgContext_, contentsTransform); 332 CGContextConcatCTM(cgContext_, contentsTransform);
333 333
334 // Apply clip in device coordinates. 334 // Apply clip in device coordinates.
335 CGMutablePathRef clipPath = CGPathCreateMutable(); 335 CGMutablePathRef clipPath = CGPathCreateMutable();
336 SkRegion::Iterator iter(canvas_->getTotalClip()); 336 const SkRegion& clipRgn = canvas_->getTotalClip();
337 if (clipRgn.isEmpty()) {
338 /* CoreGraphics does not consider a newly created path to be empty.
Stephen White 2012/01/31 19:44:45 Nit: the rest of this file uses // for multiline
339 Explicitly set it to empty so the subsequent drawing is clipped out.
340 It would be better to make the CGContext hidden if there was a CG call
341 that does that.
342 */
343 CGPathAddRect(clipPath, 0, CGRectMake(0, 0, 0, 0));
344 }
345 SkRegion::Iterator iter(clipRgn);
337 const SkIPoint& pt = device->getOrigin(); 346 const SkIPoint& pt = device->getOrigin();
338 for (; !iter.done(); iter.next()) { 347 for (; !iter.done(); iter.next()) {
339 SkIRect skRect = iter.rect(); 348 SkIRect skRect = iter.rect();
340 skRect.offset(-pt); 349 skRect.offset(-pt);
341 CGRect cgRect = SkIRectToCGRect(skRect); 350 CGRect cgRect = SkIRectToCGRect(skRect);
342 CGPathAddRect(clipPath, 0, cgRect); 351 CGPathAddRect(clipPath, 0, cgRect);
343 } 352 }
344 CGContextAddPath(cgContext_, clipPath); 353 CGContextAddPath(cgContext_, clipPath);
345 CGContextClip(cgContext_); 354 CGContextClip(cgContext_);
346 CGPathRelease(clipPath); 355 CGPathRelease(clipPath);
347 356
348 // Apply content matrix. 357 // Apply content matrix.
349 SkMatrix skMatrix = canvas_->getTotalMatrix(); 358 SkMatrix skMatrix = canvas_->getTotalMatrix();
350 skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY)); 359 skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY));
351 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); 360 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix);
352 CGContextConcatCTM(cgContext_, affine); 361 CGContextConcatCTM(cgContext_, affine);
353 362
354 return cgContext_; 363 return cgContext_;
355 } 364 }
356 365
357 } // namespace gfx 366 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698