Commit 2960adfd authored by vangelis@chromium.org's avatar vangelis@chromium.org

Revert 269568 "use accessTopLayer instead of (DEPRECATED) getTop..."

> use accessTopLayer instead of (DEPRECATED) getTopDevice
> 
> NOTRY=True
> 
> the win_chromium_rel failure must be a flake, since my CL only edits mac-only files.
> 
> the mac gpu failure is unrelated to this CL
> 
> Review URL: https://codereview.chromium.org/248113005

TBR=reed@google.com

Review URL: https://codereview.chromium.org/275813005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269964 0039d316-1c4b-4281-b951-d872f2087c98
parent 627f32ed
...@@ -117,7 +117,7 @@ class SK_API SkiaBitLocker { ...@@ -117,7 +117,7 @@ class SK_API SkiaBitLocker {
SkCanvas* canvas_; SkCanvas* canvas_;
CGContextRef cgContext_; CGContextRef cgContext_;
SkBitmap bitmap_; SkBitmap bitmap_;
bool useBitmap_; bool useDeviceBits_;
}; };
......
...@@ -284,8 +284,11 @@ SkiaBitLocker::~SkiaBitLocker() { ...@@ -284,8 +284,11 @@ SkiaBitLocker::~SkiaBitLocker() {
void SkiaBitLocker::releaseIfNeeded() { void SkiaBitLocker::releaseIfNeeded() {
if (!cgContext_) if (!cgContext_)
return; return;
if (useBitmap_) { if (useDeviceBits_) {
bitmap_.unlockPixels();
} else {
// Find the bits that were drawn to. // Find the bits that were drawn to.
SkAutoLockPixels lockedPixels(bitmap_);
const uint32_t* pixelBase const uint32_t* pixelBase
= reinterpret_cast<uint32_t*>(bitmap_.getPixels()); = reinterpret_cast<uint32_t*>(bitmap_.getPixels());
int rowPixels = bitmap_.rowBytesAsPixels(); int rowPixels = bitmap_.rowBytesAsPixels();
...@@ -367,53 +370,55 @@ foundRight: ...@@ -367,53 +370,55 @@ foundRight:
} }
CGContextRef SkiaBitLocker::cgContext() { CGContextRef SkiaBitLocker::cgContext() {
SkBaseDevice* device = canvas_->getTopDevice();
DCHECK(device);
if (!device)
return 0;
releaseIfNeeded(); // This flushes any prior bitmap use releaseIfNeeded(); // This flushes any prior bitmap use
const SkBitmap& deviceBits = device->accessBitmap(true);
SkIRect clip_bounds; useDeviceBits_ = deviceBits.getPixels();
const bool clip_is_empty = !canvas_->getClipDeviceBounds(&clip_bounds); if (useDeviceBits_) {
bitmap_ = deviceBits;
SkImageInfo info; bitmap_.lockPixels();
size_t row_bytes;
SkIPoint origin;
void* top_pixels = canvas_->accessTopLayerPixels(&info, &row_bytes, &origin);
if (top_pixels && (clip_is_empty || canvas_->isClipRect())) {
useBitmap_ = false;
} else { } else {
useBitmap_ = true; bitmap_.setConfig(
info = SkImageInfo::MakeN32Premul(clip_bounds.width(), clip_bounds.height()); SkBitmap::kARGB_8888_Config, deviceBits.width(), deviceBits.height());
origin.set(clip_bounds.x(), clip_bounds.y()); bitmap_.allocPixels();
CHECK(bitmap_.allocPixels(info));
bitmap_.eraseColor(0); bitmap_.eraseColor(0);
top_pixels = bitmap_.getPixels();
} }
base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace(
CGColorSpaceCreateDeviceRGB()); CGColorSpaceCreateDeviceRGB());
cgContext_ = CGBitmapContextCreate(top_pixels, info.width(), cgContext_ = CGBitmapContextCreate(bitmap_.getPixels(), bitmap_.width(),
info.height(), 8, row_bytes, colorSpace, bitmap_.height(), 8, bitmap_.rowBytes(), colorSpace,
kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst); kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
// Apply device matrix. // Apply device matrix.
CGAffineTransform contentsTransform = CGAffineTransformMakeScale(1, -1); CGAffineTransform contentsTransform = CGAffineTransformMakeScale(1, -1);
contentsTransform = CGAffineTransformTranslate(contentsTransform, 0, contentsTransform = CGAffineTransformTranslate(contentsTransform, 0,
-info.height()); -device->height());
CGContextConcatCTM(cgContext_, contentsTransform); CGContextConcatCTM(cgContext_, contentsTransform);
const SkIPoint& pt = device->getOrigin();
// Skip applying the clip when not writing directly to device. // Skip applying the clip when not writing directly to device.
// They're applied in the offscreen case when the bitmap is drawn. // They're applied in the offscreen case when the bitmap is drawn.
if (!useBitmap_) { if (useDeviceBits_) {
// Apply clip in device coordinates. // Apply clip in device coordinates.
CGMutablePathRef clipPath = CGPathCreateMutable(); CGMutablePathRef clipPath = CGPathCreateMutable();
if (clip_is_empty) { const SkRegion& clipRgn = canvas_->getTotalClip();
if (clipRgn.isEmpty()) {
// CoreGraphics does not consider a newly created path to be empty. // CoreGraphics does not consider a newly created path to be empty.
// Explicitly set it to empty so the subsequent drawing is clipped out. // 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 // It would be better to make the CGContext hidden if there was a CG
// call that does that. // call that does that.
CGPathAddRect(clipPath, 0, CGRectMake(0, 0, 0, 0)); CGPathAddRect(clipPath, 0, CGRectMake(0, 0, 0, 0));
} else { }
SkIRect r = clip_bounds; SkRegion::Iterator iter(clipRgn);
r.offset(-origin); const SkIPoint& pt = device->getOrigin();
CGPathAddRect(clipPath, 0, SkIRectToCGRect(r)); for (; !iter.done(); iter.next()) {
SkIRect skRect = iter.rect();
skRect.offset(-pt);
CGRect cgRect = SkIRectToCGRect(skRect);
CGPathAddRect(clipPath, 0, cgRect);
} }
CGContextAddPath(cgContext_, clipPath); CGContextAddPath(cgContext_, clipPath);
CGContextClip(cgContext_); CGContextClip(cgContext_);
...@@ -422,7 +427,7 @@ CGContextRef SkiaBitLocker::cgContext() { ...@@ -422,7 +427,7 @@ CGContextRef SkiaBitLocker::cgContext() {
// Apply content matrix. // Apply content matrix.
SkMatrix skMatrix = canvas_->getTotalMatrix(); SkMatrix skMatrix = canvas_->getTotalMatrix();
skMatrix.postTranslate(-SkIntToScalar(origin.fX), -SkIntToScalar(origin.fY)); skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY));
CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix);
CGContextConcatCTM(cgContext_, affine); CGContextConcatCTM(cgContext_, affine);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment