Chromium Code Reviews| 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 skia::ScopedPlatformPaint spp(canvas); | 30 SkPixmap pixmap; |
| 29 CGImageRef image = | 31 bool peek = canvas->peekPixels(&pixmap); |
|
f(malita)
2017/01/04 14:31:36
DCHECK(peek)?
reed1
2017/01/04 14:48:22
Done.
| |
| 30 CGBitmapContextCreateImage(spp.GetNativeDrawingContext()); | 32 SkBitmap bitmap; |
| 33 bitmap.installPixels(pixmap); | |
| 34 CGImageRef image = SkCreateCGImageRefWithColorspace( | |
| 35 bitmap, base::mac::GetSystemColorSpace()); | |
| 31 CGRect dest_rect = NSRectToCGRect(rectangle_); | 36 CGRect dest_rect = NSRectToCGRect(rectangle_); |
| 32 | 37 |
| 33 CGContextRef destination_context = | 38 CGContextRef destination_context = |
| 34 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | 39 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; |
| 35 CGContextSaveGState(destination_context); | 40 CGContextSaveGState(destination_context); |
| 36 CGContextSetBlendMode( | 41 CGContextSetBlendMode( |
| 37 destination_context, | 42 destination_context, |
| 38 composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy); | 43 composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy); |
| 39 | 44 |
| 40 if ([[NSGraphicsContext currentContext] isFlipped]) { | 45 if ([[NSGraphicsContext currentContext] isFlipped]) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 66 | 71 |
| 67 // Need to translate so that the dirty region appears at the origin of the | 72 // Need to translate so that the dirty region appears at the origin of the |
| 68 // surface. | 73 // surface. |
| 69 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), | 74 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), |
| 70 -SkDoubleToScalar(NSMinY(rectangle_))); | 75 -SkDoubleToScalar(NSMinY(rectangle_))); |
| 71 } | 76 } |
| 72 | 77 |
| 73 } // namespace skia | 78 } // namespace skia |
| 74 | 79 |
| 75 | 80 |
| OLD | NEW |