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" | 5 #include "base/mac/mac_util.h" |
6 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 6 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
7 #include "ui/gfx/canvas_paint_mac.h" | 7 #include "ui/gfx/canvas_paint_mac.h" |
8 #include "ui/gfx/geometry/size.h" | 8 #include "ui/gfx/geometry/size.h" |
9 | 9 |
10 namespace gfx { | 10 namespace gfx { |
11 | 11 |
12 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect) | 12 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect) |
13 : rectangle_(dirtyRect), | 13 : rectangle_(dirtyRect), |
14 composite_alpha_(false) { | 14 composite_alpha_(false) { |
15 Init(true); | 15 Init(true); |
16 } | 16 } |
17 | 17 |
18 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect, bool opaque) | 18 CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect, bool opaque) |
19 : rectangle_(dirtyRect), | 19 : rectangle_(dirtyRect), |
20 composite_alpha_(false) { | 20 composite_alpha_(false) { |
21 Init(opaque); | 21 Init(opaque); |
22 } | 22 } |
23 | 23 |
24 CanvasSkiaPaint::~CanvasSkiaPaint() { | 24 CanvasSkiaPaint::~CanvasSkiaPaint() { |
25 if (!is_empty()) { | 25 if (!is_empty()) { |
26 cc::PaintCanvas* canvas = sk_canvas(); | 26 sk_canvas()->restoreToCount(1); |
27 canvas->restoreToCount(1); | |
28 | 27 |
29 // Blit the dirty rect to the current context. | 28 // Blit the dirty rect to the current context. |
30 SkPixmap pixmap; | |
31 // TODO(enne): make this class record directly into a bitmap and | |
32 // remove this peekPixels call. | |
33 bool success = canvas->peekPixels(&pixmap); | |
34 DCHECK(success); | |
35 SkBitmap bitmap; | |
36 success = bitmap.installPixels(pixmap); | |
37 DCHECK(success); | |
38 CGImageRef image = SkCreateCGImageRefWithColorspace( | 29 CGImageRef image = SkCreateCGImageRefWithColorspace( |
39 bitmap, base::mac::GetSystemColorSpace()); | 30 GetBitmap(), base::mac::GetSystemColorSpace()); |
40 CGRect dest_rect = NSRectToCGRect(rectangle_); | 31 CGRect dest_rect = NSRectToCGRect(rectangle_); |
41 | 32 |
42 CGContextRef destination_context = | 33 CGContextRef destination_context = |
43 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | 34 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; |
44 CGContextSaveGState(destination_context); | 35 CGContextSaveGState(destination_context); |
45 CGContextSetBlendMode( | 36 CGContextSetBlendMode( |
46 destination_context, | 37 destination_context, |
47 composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy); | 38 composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy); |
48 | 39 |
49 if ([[NSGraphicsContext currentContext] isFlipped]) { | 40 if ([[NSGraphicsContext currentContext] isFlipped]) { |
(...skipping 25 matching lines...) Expand all Loading... |
75 | 66 |
76 // 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 |
77 // surface. | 68 // surface. |
78 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), | 69 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), |
79 -SkDoubleToScalar(NSMinY(rectangle_))); | 70 -SkDoubleToScalar(NSMinY(rectangle_))); |
80 } | 71 } |
81 | 72 |
82 } // namespace skia | 73 } // namespace skia |
83 | 74 |
84 | 75 |
OLD | NEW |