OLD | NEW |
1 | 1 |
2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #ifndef SKIA_EXT_CANVAS_PAINT_MAC_H_ | 6 #ifndef SKIA_EXT_CANVAS_PAINT_MAC_H_ |
7 #define SKIA_EXT_CANVAS_PAINT_MAC_H_ | 7 #define SKIA_EXT_CANVAS_PAINT_MAC_H_ |
8 #pragma once | 8 #pragma once |
9 | 9 |
10 #include "skia/ext/canvas_paint_common.h" | 10 #include "skia/ext/canvas_paint_common.h" |
11 #include "skia/ext/platform_canvas.h" | 11 #include "skia/ext/platform_canvas.h" |
12 | 12 |
13 #import <Cocoa/Cocoa.h> | 13 #import <Cocoa/Cocoa.h> |
14 | 14 |
15 namespace skia { | 15 namespace skia { |
16 | 16 |
17 // A class designed to translate skia painting into a region to the current | 17 // A class designed to translate skia painting into a region to the current |
18 // graphics context. On construction, it will set up a context for painting | 18 // graphics context. On construction, it will set up a context for painting |
19 // into, and on destruction, it will commit it to the current context. | 19 // into, and on destruction, it will commit it to the current context. |
| 20 // Note: The created context is always inialized to (0, 0, 0, 0). |
20 template <class T> | 21 template <class T> |
21 class CanvasPaintT : public T { | 22 class CanvasPaintT : public T { |
22 public: | 23 public: |
23 // This constructor assumes the result is opaque. | 24 // This constructor assumes the result is opaque. |
24 explicit CanvasPaintT(NSRect dirtyRect) | 25 explicit CanvasPaintT(NSRect dirtyRect) |
25 : context_(NULL), | 26 : context_(NULL), |
26 rectangle_(dirtyRect), | 27 rectangle_(dirtyRect), |
27 composite_alpha_(false) { | 28 composite_alpha_(false) { |
28 init(true); | 29 init(true); |
29 } | 30 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 83 |
83 private: | 84 private: |
84 void init(bool opaque) { | 85 void init(bool opaque) { |
85 PlatformCanvas* canvas = GetPlatformCanvas(this); | 86 PlatformCanvas* canvas = GetPlatformCanvas(this); |
86 if (!canvas->initialize(rectangle_.size.width, | 87 if (!canvas->initialize(rectangle_.size.width, |
87 rectangle_.size.height, | 88 rectangle_.size.height, |
88 opaque, NULL)) { | 89 opaque, NULL)) { |
89 // Cause a deliberate crash; | 90 // Cause a deliberate crash; |
90 *(volatile char*) 0 = 0; | 91 *(volatile char*) 0 = 0; |
91 } | 92 } |
| 93 canvas->clear(SkColorSetARGB(0, 0, 0, 0)); |
92 | 94 |
93 // Need to translate so that the dirty region appears at the origin of the | 95 // Need to translate so that the dirty region appears at the origin of the |
94 // surface. | 96 // surface. |
95 canvas->translate(-SkDoubleToScalar(rectangle_.origin.x), | 97 canvas->translate(-SkDoubleToScalar(rectangle_.origin.x), |
96 -SkDoubleToScalar(rectangle_.origin.y)); | 98 -SkDoubleToScalar(rectangle_.origin.y)); |
97 | 99 |
98 context_ = GetBitmapContext(GetTopDevice(*canvas)); | 100 context_ = GetBitmapContext(GetTopDevice(*canvas)); |
99 } | 101 } |
100 | 102 |
101 CGContext* context_; | 103 CGContext* context_; |
102 NSRect rectangle_; | 104 NSRect rectangle_; |
103 // See description above setter. | 105 // See description above setter. |
104 bool composite_alpha_; | 106 bool composite_alpha_; |
105 | 107 |
106 // Disallow copy and assign. | 108 // Disallow copy and assign. |
107 CanvasPaintT(const CanvasPaintT&); | 109 CanvasPaintT(const CanvasPaintT&); |
108 CanvasPaintT& operator=(const CanvasPaintT&); | 110 CanvasPaintT& operator=(const CanvasPaintT&); |
109 }; | 111 }; |
110 | 112 |
111 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; | 113 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; |
112 | 114 |
113 } // namespace skia | 115 } // namespace skia |
114 | 116 |
115 | 117 |
116 #endif // SKIA_EXT_CANVAS_PAINT_MAC_H_ | 118 #endif // SKIA_EXT_CANVAS_PAINT_MAC_H_ |
OLD | NEW |