| 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 SkCanvas* canvas = sk_canvas(); | 26 cc::PaintCanvas* canvas = sk_canvas(); |
| 27 canvas->restoreToCount(1); | 27 canvas->restoreToCount(1); |
| 28 | 28 |
| 29 // Blit the dirty rect to the current context. | 29 // Blit the dirty rect to the current context. |
| 30 SkPixmap pixmap; | 30 SkPixmap pixmap; |
| 31 // TODO(enne): make this class record directly into a bitmap and |
| 32 // remove this peekPixels call. |
| 31 bool success = canvas->peekPixels(&pixmap); | 33 bool success = canvas->peekPixels(&pixmap); |
| 32 DCHECK(success); | 34 DCHECK(success); |
| 33 SkBitmap bitmap; | 35 SkBitmap bitmap; |
| 34 success = bitmap.installPixels(pixmap); | 36 success = bitmap.installPixels(pixmap); |
| 35 DCHECK(success); | 37 DCHECK(success); |
| 36 CGImageRef image = SkCreateCGImageRefWithColorspace( | 38 CGImageRef image = SkCreateCGImageRefWithColorspace( |
| 37 bitmap, base::mac::GetSystemColorSpace()); | 39 bitmap, base::mac::GetSystemColorSpace()); |
| 38 CGRect dest_rect = NSRectToCGRect(rectangle_); | 40 CGRect dest_rect = NSRectToCGRect(rectangle_); |
| 39 | 41 |
| 40 CGContextRef destination_context = | 42 CGContextRef destination_context = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 61 void CanvasSkiaPaint::Init(bool opaque) { | 63 void CanvasSkiaPaint::Init(bool opaque) { |
| 62 CGContextRef destination_context = | 64 CGContextRef destination_context = |
| 63 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | 65 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; |
| 64 CGRect scaled_unit_rect = CGContextConvertRectToDeviceSpace( | 66 CGRect scaled_unit_rect = CGContextConvertRectToDeviceSpace( |
| 65 destination_context, CGRectMake(0, 0, 1, 1)); | 67 destination_context, CGRectMake(0, 0, 1, 1)); |
| 66 // Assume that the x scale and the y scale are the same. | 68 // Assume that the x scale and the y scale are the same. |
| 67 CGFloat scale = scaled_unit_rect.size.width; | 69 CGFloat scale = scaled_unit_rect.size.width; |
| 68 | 70 |
| 69 gfx::Size size(NSWidth(rectangle_), NSHeight(rectangle_)); | 71 gfx::Size size(NSWidth(rectangle_), NSHeight(rectangle_)); |
| 70 RecreateBackingCanvas(size, scale, opaque); | 72 RecreateBackingCanvas(size, scale, opaque); |
| 71 SkCanvas* canvas = sk_canvas(); | 73 cc::PaintCanvas* canvas = sk_canvas(); |
| 72 canvas->clear(SkColorSetARGB(0, 0, 0, 0)); | 74 canvas->clear(SkColorSetARGB(0, 0, 0, 0)); |
| 73 | 75 |
| 74 // Need to translate so that the dirty region appears at the origin of the | 76 // Need to translate so that the dirty region appears at the origin of the |
| 75 // surface. | 77 // surface. |
| 76 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), | 78 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), |
| 77 -SkDoubleToScalar(NSMinY(rectangle_))); | 79 -SkDoubleToScalar(NSMinY(rectangle_))); |
| 78 } | 80 } |
| 79 | 81 |
| 80 } // namespace skia | 82 } // namespace skia |
| 81 | 83 |
| 82 | 84 |
| OLD | NEW |