diff options
author | caryclark@google.com <caryclark@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-11 14:50:39 +0000 |
---|---|---|
committer | caryclark@google.com <caryclark@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-11 14:50:39 +0000 |
commit | 3a761d29fc85af76d924dc6d28e5b96c3f903539 (patch) | |
tree | 083f5497b18f093f8ab7d0e141556b4ecbb1b6b8 /skia | |
parent | 5d474ff6e09b20d734a6074cbca3477bebcf76a9 (diff) | |
download | chromium_src-3a761d29fc85af76d924dc6d28e5b96c3f903539.zip chromium_src-3a761d29fc85af76d924dc6d28e5b96c3f903539.tar.gz chromium_src-3a761d29fc85af76d924dc6d28e5b96c3f903539.tar.bz2 |
Adjust the CoreGraphics context for offscreen layers.
UI elements like buttons are drawn on Mac by pointing
the CoreGraphics context at the Skia bitmap associated
with the current device. If the elements are drawn
in a transparent context, Skia creates an offscreen
layer to capture the draw, then applies the transparency.
CoreGraphics does not know that it is drawing to an
offscreen, so the clip and matrix need to be adjusted
by the offscreen's origin, which is its position on
the device.
Also, use getTopDevice() instead of getDevice() to
obtain the bitmap. Normally, they will return the same
SkDevice (and in that case, getOrigin() will return
(0,0)) but if there's a layer present, getDevice()
will return the actual device instead of the tempoary
offscreen.
BUG:108767
TEST:http://jsfiddle.net/casaschi/JWkfA/
Review URL: http://codereview.chromium.org/9129001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117217 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/ext/skia_utils_mac.mm | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/skia/ext/skia_utils_mac.mm b/skia/ext/skia_utils_mac.mm index 1ef5322..ab44d82 100644 --- a/skia/ext/skia_utils_mac.mm +++ b/skia/ext/skia_utils_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -307,13 +307,13 @@ SkiaBitLocker::~SkiaBitLocker() { void SkiaBitLocker::releaseIfNeeded() { if (!cgContext_) return; - canvas_->getDevice()->accessBitmap(true).unlockPixels(); + canvas_->getTopDevice()->accessBitmap(true).unlockPixels(); CGContextRelease(cgContext_); cgContext_ = 0; } CGContextRef SkiaBitLocker::cgContext() { - SkDevice* device = canvas_->getDevice(); + SkDevice* device = canvas_->getTopDevice(); DCHECK(device); if (!device) return 0; @@ -334,8 +334,10 @@ CGContextRef SkiaBitLocker::cgContext() { // Apply clip in device coordinates. CGMutablePathRef clipPath = CGPathCreateMutable(); SkRegion::Iterator iter(canvas_->getTotalClip()); + const SkIPoint& pt = device->getOrigin(); for (; !iter.done(); iter.next()) { - const SkIRect& skRect = iter.rect(); + SkIRect skRect = iter.rect(); + skRect.offset(-pt); CGRect cgRect = SkIRectToCGRect(skRect); CGPathAddRect(clipPath, 0, cgRect); } @@ -344,7 +346,8 @@ CGContextRef SkiaBitLocker::cgContext() { CGPathRelease(clipPath); // Apply content matrix. - const SkMatrix& skMatrix = canvas_->getTotalMatrix(); + SkMatrix skMatrix = canvas_->getTotalMatrix(); + skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY)); CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); CGContextConcatCTM(cgContext_, affine); |