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

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

Issue 9129001: Adjust the CoreGraphics context for offscreen layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 cgContext_(0) { 300 cgContext_(0) {
301 } 301 }
302 302
303 SkiaBitLocker::~SkiaBitLocker() { 303 SkiaBitLocker::~SkiaBitLocker() {
304 releaseIfNeeded(); 304 releaseIfNeeded();
305 } 305 }
306 306
307 void SkiaBitLocker::releaseIfNeeded() { 307 void SkiaBitLocker::releaseIfNeeded() {
308 if (!cgContext_) 308 if (!cgContext_)
309 return; 309 return;
310 canvas_->getDevice()->accessBitmap(true).unlockPixels(); 310 canvas_->getTopDevice()->accessBitmap(true).unlockPixels();
311 CGContextRelease(cgContext_); 311 CGContextRelease(cgContext_);
312 cgContext_ = 0; 312 cgContext_ = 0;
313 } 313 }
314 314
315 CGContextRef SkiaBitLocker::cgContext() { 315 CGContextRef SkiaBitLocker::cgContext() {
316 SkDevice* device = canvas_->getDevice(); 316 SkDevice* device = canvas_->getTopDevice();
317 DCHECK(device); 317 DCHECK(device);
318 if (!device) 318 if (!device)
319 return 0; 319 return 0;
320 releaseIfNeeded(); 320 releaseIfNeeded();
321 const SkBitmap& bitmap = device->accessBitmap(true); 321 const SkBitmap& bitmap = device->accessBitmap(true);
322 bitmap.lockPixels(); 322 bitmap.lockPixels();
323 void* pixels = bitmap.getPixels(); 323 void* pixels = bitmap.getPixels();
324 cgContext_ = CGBitmapContextCreate(pixels, device->width(), 324 cgContext_ = CGBitmapContextCreate(pixels, device->width(),
325 device->height(), 8, bitmap.rowBytes(), CGColorSpaceCreateDeviceRGB(), 325 device->height(), 8, bitmap.rowBytes(), CGColorSpaceCreateDeviceRGB(),
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 SkRegion::Iterator iter(canvas_->getTotalClip());
337 const SkIPoint& pt = device->getOrigin();
337 for (; !iter.done(); iter.next()) { 338 for (; !iter.done(); iter.next()) {
338 const SkIRect& skRect = iter.rect(); 339 SkIRect skRect = iter.rect();
340 skRect.offset(-pt);
339 CGRect cgRect = SkIRectToCGRect(skRect); 341 CGRect cgRect = SkIRectToCGRect(skRect);
340 CGPathAddRect(clipPath, 0, cgRect); 342 CGPathAddRect(clipPath, 0, cgRect);
341 } 343 }
342 CGContextAddPath(cgContext_, clipPath); 344 CGContextAddPath(cgContext_, clipPath);
343 CGContextClip(cgContext_); 345 CGContextClip(cgContext_);
344 CGPathRelease(clipPath); 346 CGPathRelease(clipPath);
345 347
346 // Apply content matrix. 348 // Apply content matrix.
347 const SkMatrix& skMatrix = canvas_->getTotalMatrix(); 349 SkMatrix skMatrix = canvas_->getTotalMatrix();
350 skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY));
348 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); 351 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix);
349 CGContextConcatCTM(cgContext_, affine); 352 CGContextConcatCTM(cgContext_, affine);
350 353
351 return cgContext_; 354 return cgContext_;
352 } 355 }
353 356
354 } // namespace gfx 357 } // 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