| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/mac/mac_util.h" |
| 6 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
| 5 #include "ui/gfx/canvas_paint_mac.h" | 7 #include "ui/gfx/canvas_paint_mac.h" |
| 6 #include "ui/gfx/geometry/size.h" | 8 #include "ui/gfx/geometry/size.h" |
| 7 | 9 |
| 8 namespace gfx { | 10 namespace gfx { |
| 9 | 11 |
| 10 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect) | 12 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect) |
| 11 : rectangle_(dirtyRect), | 13 : rectangle_(dirtyRect), |
| 12 composite_alpha_(false) { | 14 composite_alpha_(false) { |
| 13 Init(true); | 15 Init(true); |
| 14 } | 16 } |
| 15 | 17 |
| 16 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect, bool opaque) | 18 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect, bool opaque) |
| 17 : rectangle_(dirtyRect), | 19 : rectangle_(dirtyRect), |
| 18 composite_alpha_(false) { | 20 composite_alpha_(false) { |
| 19 Init(opaque); | 21 Init(opaque); |
| 20 } | 22 } |
| 21 | 23 |
| 22 CanvasSkiaPaint::~CanvasSkiaPaint() { | 24 CanvasSkiaPaint::~CanvasSkiaPaint() { |
| 23 if (!is_empty()) { | 25 if (!is_empty()) { |
| 24 SkCanvas* canvas = sk_canvas(); | 26 SkCanvas* canvas = sk_canvas(); |
| 25 canvas->restoreToCount(1); | 27 canvas->restoreToCount(1); |
| 26 | 28 |
| 27 // Blit the dirty rect to the current context. | 29 // Blit the dirty rect to the current context. |
| 28 CGImageRef image = | 30 SkPixmap pixmap; |
| 29 CGBitmapContextCreateImage(skia::GetNativeDrawingContext(canvas)); | 31 bool success = canvas->peekPixels(&pixmap); |
| 32 DCHECK(success); |
| 33 SkBitmap bitmap; |
| 34 success = bitmap.installPixels(pixmap); |
| 35 DCHECK(success); |
| 36 CGImageRef image = SkCreateCGImageRefWithColorspace( |
| 37 bitmap, base::mac::GetSystemColorSpace()); |
| 30 CGRect dest_rect = NSRectToCGRect(rectangle_); | 38 CGRect dest_rect = NSRectToCGRect(rectangle_); |
| 31 | 39 |
| 32 CGContextRef destination_context = | 40 CGContextRef destination_context = |
| 33 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | 41 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; |
| 34 CGContextSaveGState(destination_context); | 42 CGContextSaveGState(destination_context); |
| 35 CGContextSetBlendMode( | 43 CGContextSetBlendMode( |
| 36 destination_context, | 44 destination_context, |
| 37 composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy); | 45 composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy); |
| 38 | 46 |
| 39 if ([[NSGraphicsContext currentContext] isFlipped]) { | 47 if ([[NSGraphicsContext currentContext] isFlipped]) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 65 | 73 |
| 66 // Need to translate so that the dirty region appears at the origin of the | 74 // Need to translate so that the dirty region appears at the origin of the |
| 67 // surface. | 75 // surface. |
| 68 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), | 76 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), |
| 69 -SkDoubleToScalar(NSMinY(rectangle_))); | 77 -SkDoubleToScalar(NSMinY(rectangle_))); |
| 70 } | 78 } |
| 71 | 79 |
| 72 } // namespace skia | 80 } // namespace skia |
| 73 | 81 |
| 74 | 82 |
| OLD | NEW |