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 bool success = canvas->peekPixels(&pixmap); | 31 bool success = canvas->peekPixels(&pixmap); |
32 DCHECK(success); | 32 DCHECK(success); |
33 SkBitmap bitmap; | 33 SkBitmap bitmap; |
34 success = bitmap.installPixels(pixmap); | 34 success = bitmap.installPixels(pixmap); |
35 DCHECK(success); | 35 DCHECK(success); |
36 CGImageRef image = SkCreateCGImageRefWithColorspace( | 36 CGImageRef image = SkCreateCGImageRefWithColorspace( |
(...skipping 23 matching lines...) Expand all Loading... | |
60 | 60 |
61 void CanvasSkiaPaint::Init(bool opaque) { | 61 void CanvasSkiaPaint::Init(bool opaque) { |
62 CGContextRef destination_context = | 62 CGContextRef destination_context = |
63 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | 63 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; |
64 CGRect scaled_unit_rect = CGContextConvertRectToDeviceSpace( | 64 CGRect scaled_unit_rect = CGContextConvertRectToDeviceSpace( |
65 destination_context, CGRectMake(0, 0, 1, 1)); | 65 destination_context, CGRectMake(0, 0, 1, 1)); |
66 // Assume that the x scale and the y scale are the same. | 66 // Assume that the x scale and the y scale are the same. |
67 CGFloat scale = scaled_unit_rect.size.width; | 67 CGFloat scale = scaled_unit_rect.size.width; |
68 | 68 |
69 gfx::Size size(NSWidth(rectangle_), NSHeight(rectangle_)); | 69 gfx::Size size(NSWidth(rectangle_), NSHeight(rectangle_)); |
70 RecreateBackingCanvas(size, scale, opaque); | 70 RecreateBackingCanvas(size, scale, opaque); |
danakj
2017/01/25 19:10:07
This is going to have to make a passthru PaintCanv
enne (OOO)
2017/01/25 21:07:16
Why is that? gfx::Canvas creates a PaintSurface wh
danakj
2017/01/25 22:11:41
Cuz the destructor does peekPixels on the canvas.
danakj
2017/01/25 22:12:28
Or more precisely, I don't think PaintCanvas shoul
| |
71 SkCanvas* canvas = sk_canvas(); | 71 cc::PaintCanvas* canvas = sk_canvas(); |
72 canvas->clear(SkColorSetARGB(0, 0, 0, 0)); | 72 canvas->clear(SkColorSetARGB(0, 0, 0, 0)); |
73 | 73 |
74 // 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 |
75 // surface. | 75 // surface. |
76 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), | 76 canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)), |
77 -SkDoubleToScalar(NSMinY(rectangle_))); | 77 -SkDoubleToScalar(NSMinY(rectangle_))); |
78 } | 78 } |
79 | 79 |
80 } // namespace skia | 80 } // namespace skia |
81 | 81 |
82 | 82 |
OLD | NEW |