summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-20 05:23:08 +0000
committerreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-20 05:23:08 +0000
commit60cbaaa10f673e8e85b1a7515d2353785538b136 (patch)
treed5a3cfafc91cfbf8f4271dfb5f43ae45477f2777 /skia
parenta63006eafa81edfeb4ba66da61a5517b54aea914 (diff)
downloadchromium_src-60cbaaa10f673e8e85b1a7515d2353785538b136.zip
chromium_src-60cbaaa10f673e8e85b1a7515d2353785538b136.tar.gz
chromium_src-60cbaaa10f673e8e85b1a7515d2353785538b136.tar.bz2
Stop using (deprecated) getTotalClip
patch from issue 342553006 BUG= android failures unrelated to this CL NOTRY=True Review URL: https://codereview.chromium.org/344793003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278613 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/skia_utils_mac.h1
-rw-r--r--skia/ext/skia_utils_mac.mm69
2 files changed, 29 insertions, 41 deletions
diff --git a/skia/ext/skia_utils_mac.h b/skia/ext/skia_utils_mac.h
index fd000f3..6a0efde 100644
--- a/skia/ext/skia_utils_mac.h
+++ b/skia/ext/skia_utils_mac.h
@@ -117,6 +117,7 @@ class SK_API SkiaBitLocker {
SkCanvas* canvas_;
CGContextRef cgContext_;
SkBitmap bitmap_;
+ SkIPoint bitmapOffset_;
bool useDeviceBits_;
};
diff --git a/skia/ext/skia_utils_mac.mm b/skia/ext/skia_utils_mac.mm
index f67d3c1..4f7ddd9 100644
--- a/skia/ext/skia_utils_mac.mm
+++ b/skia/ext/skia_utils_mac.mm
@@ -356,7 +356,8 @@ foundRight:
return;
canvas_->save();
canvas_->concat(inverse);
- canvas_->drawBitmap(subset, bounds.fLeft, bounds.fTop);
+ canvas_->drawBitmap(subset, bounds.x() + bitmapOffset_.x(),
+ bounds.y() + bitmapOffset_.y());
canvas_->restore();
}
CGContextRelease(cgContext_);
@@ -364,18 +365,35 @@ foundRight:
}
CGContextRef SkiaBitLocker::cgContext() {
+ SkIRect clip_bounds;
+ if (!canvas_->getClipDeviceBounds(&clip_bounds))
+ return 0; // the clip is empty, nothing to draw
+
SkBaseDevice* device = canvas_->getTopDevice();
DCHECK(device);
if (!device)
return 0;
+
releaseIfNeeded(); // This flushes any prior bitmap use
+
+ // remember the top/left, in case we need to compose this later
+ bitmapOffset_.set(clip_bounds.x(), clip_bounds.y());
+
+ // Now make clip_bounds be relative to the current layer/device
+ clip_bounds.offset(-device->getOrigin());
+
const SkBitmap& deviceBits = device->accessBitmap(true);
- useDeviceBits_ = deviceBits.getPixels();
+
+ // Only draw directly if we have pixels, and we're only rect-clipped.
+ // If not, we allocate an offscreen and draw into that, relying on the
+ // compositing step to apply skia's clip.
+ useDeviceBits_ = deviceBits.getPixels() && canvas_->isClipRect();
if (useDeviceBits_) {
- bitmap_ = deviceBits;
+ if (!deviceBits.extractSubset(&bitmap_, clip_bounds))
+ return 0;
bitmap_.lockPixels();
} else {
- if (!bitmap_.allocN32Pixels(deviceBits.width(), deviceBits.height()))
+ if (!bitmap_.allocN32Pixels(clip_bounds.width(), clip_bounds.height()))
return 0;
bitmap_.eraseColor(0);
}
@@ -385,44 +403,13 @@ CGContextRef SkiaBitLocker::cgContext() {
bitmap_.height(), 8, bitmap_.rowBytes(), colorSpace,
kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
- // Apply device matrix.
- CGAffineTransform contentsTransform = CGAffineTransformMakeScale(1, -1);
- contentsTransform = CGAffineTransformTranslate(contentsTransform, 0,
- -device->height());
- CGContextConcatCTM(cgContext_, contentsTransform);
-
- const SkIPoint& pt = device->getOrigin();
- // Skip applying the clip when not writing directly to device.
- // They're applied in the offscreen case when the bitmap is drawn.
- if (useDeviceBits_) {
- // Apply clip in device coordinates.
- CGMutablePathRef clipPath = CGPathCreateMutable();
- const SkRegion& clipRgn = canvas_->getTotalClip();
- if (clipRgn.isEmpty()) {
- // CoreGraphics does not consider a newly created path to be empty.
- // Explicitly set it to empty so the subsequent drawing is clipped out.
- // It would be better to make the CGContext hidden if there was a CG
- // call that does that.
- CGPathAddRect(clipPath, 0, CGRectMake(0, 0, 0, 0));
- }
- SkRegion::Iterator iter(clipRgn);
- const SkIPoint& pt = device->getOrigin();
- for (; !iter.done(); iter.next()) {
- SkIRect skRect = iter.rect();
- skRect.offset(-pt);
- CGRect cgRect = SkIRectToCGRect(skRect);
- CGPathAddRect(clipPath, 0, cgRect);
- }
- CGContextAddPath(cgContext_, clipPath);
- CGContextClip(cgContext_);
- CGPathRelease(clipPath);
- }
+ SkMatrix matrix = canvas_->getTotalMatrix();
+ matrix.postTranslate(-SkIntToScalar(bitmapOffset_.x()),
+ -SkIntToScalar(bitmapOffset_.y()));
+ matrix.postScale(1, -1);
+ matrix.postTranslate(0, SkIntToScalar(bitmap_.height()));
- // Apply content matrix.
- SkMatrix skMatrix = canvas_->getTotalMatrix();
- skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY));
- CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix);
- CGContextConcatCTM(cgContext_, affine);
+ CGContextConcatCTM(cgContext_, SkMatrixToCGAffineTransform(matrix));
return cgContext_;
}