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 {
SkCanvas* canvas_;
CGContextRef cgContext_;
SkBitmap bitmap_;
bool useBitmap_;
bool useDeviceBits_;
};
......
......@@ -284,8 +284,11 @@ SkiaBitLocker::~SkiaBitLocker() {
void SkiaBitLocker::releaseIfNeeded() {
if (!cgContext_)
return;
if (useBitmap_) {
if (useDeviceBits_) {
bitmap_.unlockPixels();
} else {
// Find the bits that were drawn to.
SkAutoLockPixels lockedPixels(bitmap_);
const uint32_t* pixelBase
= reinterpret_cast<uint32_t*>(bitmap_.getPixels());
int rowPixels = bitmap_.rowBytesAsPixels();
......@@ -367,53 +370,55 @@ foundRight:
}
CGContextRef SkiaBitLocker::cgContext() {
SkBaseDevice* device = canvas_->getTopDevice();
DCHECK(device);
if (!device)
return 0;
releaseIfNeeded(); // This flushes any prior bitmap use
SkIRect clip_bounds;
const bool clip_is_empty = !canvas_->getClipDeviceBounds(&clip_bounds);
SkImageInfo info;
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;
const SkBitmap& deviceBits = device->accessBitmap(true);
useDeviceBits_ = deviceBits.getPixels();
if (useDeviceBits_) {
bitmap_ = deviceBits;
bitmap_.lockPixels();
} else {
useBitmap_ = true;
info = SkImageInfo::MakeN32Premul(clip_bounds.width(), clip_bounds.height());
origin.set(clip_bounds.x(), clip_bounds.y());
CHECK(bitmap_.allocPixels(info));
bitmap_.setConfig(
SkBitmap::kARGB_8888_Config, deviceBits.width(), deviceBits.height());
bitmap_.allocPixels();
bitmap_.eraseColor(0);
top_pixels = bitmap_.getPixels();
}
base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace(
CGColorSpaceCreateDeviceRGB());
cgContext_ = CGBitmapContextCreate(top_pixels, info.width(),
info.height(), 8, row_bytes, colorSpace,
cgContext_ = CGBitmapContextCreate(bitmap_.getPixels(), bitmap_.width(),
bitmap_.height(), 8, bitmap_.rowBytes(), colorSpace,
kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
// Apply device matrix.
CGAffineTransform contentsTransform = CGAffineTransformMakeScale(1, -1);
contentsTransform = CGAffineTransformTranslate(contentsTransform, 0,
-info.height());
-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 (!useBitmap_) {
if (useDeviceBits_) {
// Apply clip in device coordinates.
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.
// 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));
} else {
SkIRect r = clip_bounds;
r.offset(-origin);
CGPathAddRect(clipPath, 0, SkIRectToCGRect(r));
}
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_);
......@@ -422,7 +427,7 @@ CGContextRef SkiaBitLocker::cgContext() {
// Apply content matrix.
SkMatrix skMatrix = canvas_->getTotalMatrix();
skMatrix.postTranslate(-SkIntToScalar(origin.fX), -SkIntToScalar(origin.fY));
skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY));
CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix);
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