OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "skia/ext/bitmap_platform_device_mac.h" | 5 #include "skia/ext/bitmap_platform_device_mac.h" |
6 | 6 |
7 #include <time.h> | 7 #include <time.h> |
8 | 8 |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "skia/ext/skia_utils_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 SkASSERT(bitmap_context_); | 107 SkASSERT(bitmap_context_); |
108 // Initialize the clip region to the entire bitmap. | 108 // Initialize the clip region to the entire bitmap. |
109 | 109 |
110 SkIRect rect; | 110 SkIRect rect; |
111 rect.set(0, 0, | 111 rect.set(0, 0, |
112 CGBitmapContextGetWidth(bitmap_context_), | 112 CGBitmapContextGetWidth(bitmap_context_), |
113 CGBitmapContextGetHeight(bitmap_context_)); | 113 CGBitmapContextGetHeight(bitmap_context_)); |
114 clip_region_ = SkRegion(rect); | 114 clip_region_ = SkRegion(rect); |
115 transform_.reset(); | 115 transform_.reset(); |
116 CGContextRetain(bitmap_context_); | 116 CGContextRetain(bitmap_context_); |
| 117 // We must save the state once so that we can use the restore/save trick |
| 118 // in LoadConfig(). |
| 119 CGContextSaveGState(bitmap_context_); |
117 } | 120 } |
118 | 121 |
119 void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::SetMatrixClip( | 122 void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::SetMatrixClip( |
120 const SkMatrix& transform, | 123 const SkMatrix& transform, |
121 const SkRegion& region) { | 124 const SkRegion& region) { |
122 transform_ = transform; | 125 transform_ = transform; |
123 clip_region_ = region; | 126 clip_region_ = region; |
124 config_dirty_ = true; | 127 config_dirty_ = true; |
125 } | 128 } |
126 | 129 |
127 void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::LoadConfig() { | 130 void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::LoadConfig() { |
128 if (!config_dirty_ || !bitmap_context_) | 131 if (!config_dirty_ || !bitmap_context_) |
129 return; // Nothing to do. | 132 return; // Nothing to do. |
130 config_dirty_ = false; | 133 config_dirty_ = false; |
131 | 134 |
132 // Transform. | 135 // Transform. |
133 SkMatrix t(transform_); | 136 SkMatrix t(transform_); |
| 137 |
| 138 // We must restore and then save the state of the graphics context since the |
| 139 // calls to Load the clipping region to the context are strictly cummulative, |
| 140 // i.e., you can't replace a clip rect, other than with a save/restore. |
| 141 // But this implies that no other changes to the state are done elsewhere. |
| 142 // If we ever get to need to change this, then we must replace the clip rect |
| 143 // calls in LoadClippingRegionToCGContext() with an image mask instead. |
| 144 CGContextRestoreGState(bitmap_context_); |
| 145 CGContextSaveGState(bitmap_context_); |
134 LoadTransformToCGContext(bitmap_context_, t); | 146 LoadTransformToCGContext(bitmap_context_, t); |
135 t.setTranslateX(-t.getTranslateX()); | 147 t.setTranslateX(-t.getTranslateX()); |
136 t.setTranslateY(-t.getTranslateY()); | 148 t.setTranslateY(-t.getTranslateY()); |
137 LoadClippingRegionToCGContext(bitmap_context_, clip_region_, t); | 149 LoadClippingRegionToCGContext(bitmap_context_, clip_region_, t); |
138 } | 150 } |
139 | 151 |
140 | 152 |
141 // We use this static factory function instead of the regular constructor so | 153 // We use this static factory function instead of the regular constructor so |
142 // that we can create the pixel data before calling the constructor. This is | 154 // that we can create the pixel data before calling the constructor. This is |
143 // required so that we can call the base class' constructor with the pixel | 155 // required so that we can call the base class' constructor with the pixel |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 for (int i = 0; i < height; i++) { | 300 for (int i = 0; i < height; i++) { |
289 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x; | 301 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x; |
290 for (int j = 0; j < width; j++) { | 302 for (int j = 0; j < width; j++) { |
291 adjustor(data + offset + j); | 303 adjustor(data + offset + j); |
292 } | 304 } |
293 } | 305 } |
294 } | 306 } |
295 } | 307 } |
296 | 308 |
297 } // namespace skia | 309 } // namespace skia |
OLD | NEW |