| 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 "ui/gfx/canvas_paint_mac.h" | 5 #include "ui/gfx/canvas_paint_mac.h" |
| 6 #include "ui/gfx/geometry/size.h" | 6 #include "ui/gfx/geometry/size.h" |
| 7 | 7 |
| 8 namespace gfx { | 8 namespace gfx { |
| 9 | 9 |
| 10 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect) | 10 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect) |
| 11 : rectangle_(dirtyRect), | 11 : rectangle_(dirtyRect), |
| 12 composite_alpha_(false) { | 12 composite_alpha_(false) { |
| 13 Init(true); | 13 Init(true); |
| 14 } | 14 } |
| 15 | 15 |
| 16 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect, bool opaque) | 16 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect, bool opaque) |
| 17 : rectangle_(dirtyRect), | 17 : rectangle_(dirtyRect), |
| 18 composite_alpha_(false) { | 18 composite_alpha_(false) { |
| 19 Init(opaque); | 19 Init(opaque); |
| 20 } | 20 } |
| 21 | 21 |
| 22 CanvasSkiaPaint::~CanvasSkiaPaint() { | 22 CanvasSkiaPaint::~CanvasSkiaPaint() { |
| 23 if (!is_empty()) { | 23 if (!is_empty()) { |
| 24 SkCanvas* canvas = sk_canvas(); | 24 SkCanvas* canvas = sk_canvas(); |
| 25 canvas->restoreToCount(1); | 25 canvas->restoreToCount(1); |
| 26 | 26 |
| 27 // Blit the dirty rect to the current context. | 27 // Blit the dirty rect to the current context. |
| 28 skia::ScopedPlatformPaint spp(canvas); |
| 28 CGImageRef image = | 29 CGImageRef image = |
| 29 CGBitmapContextCreateImage(skia::GetBitmapContext(*canvas)); | 30 CGBitmapContextCreateImage(spp.GetNativeDrawingContext()); |
| 30 CGRect dest_rect = NSRectToCGRect(rectangle_); | 31 CGRect dest_rect = NSRectToCGRect(rectangle_); |
| 31 | 32 |
| 32 CGContextRef destination_context = | 33 CGContextRef destination_context = |
| 33 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | 34 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; |
| 34 CGContextSaveGState(destination_context); | 35 CGContextSaveGState(destination_context); |
| 35 CGContextSetBlendMode( | 36 CGContextSetBlendMode( |
| 36 destination_context, | 37 destination_context, |
| 37 composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy); | 38 composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy); |
| 38 | 39 |
| 39 if ([[NSGraphicsContext currentContext] isFlipped]) { | 40 if ([[NSGraphicsContext currentContext] isFlipped]) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 65 | 66 |
| 66 // Need to translate so that the dirty region appears at the origin of the | 67 // Need to translate so that the dirty region appears at the origin of the |
| 67 // surface. | 68 // surface. |
| 68 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), | 69 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), |
| 69 -SkDoubleToScalar(NSMinY(rectangle_))); | 70 -SkDoubleToScalar(NSMinY(rectangle_))); |
| 70 } | 71 } |
| 71 | 72 |
| 72 } // namespace skia | 73 } // namespace skia |
| 73 | 74 |
| 74 | 75 |
| OLD | NEW |