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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "content/browser/renderer_host/backing_store_mac.h" | 7 #include "content/browser/renderer_host/backing_store_mac.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // scroll. Thus, we only have to worry about pixels which will end up inside | 173 // scroll. Thus, we only have to worry about pixels which will end up inside |
174 // the clipping rectangle. (Note that the clipping rectangle is not | 174 // the clipping rectangle. (Note that the clipping rectangle is not |
175 // translated by the scroll.) | 175 // translated by the scroll.) |
176 | 176 |
177 // We assume |clip_rect| is contained within the backing store. | 177 // We assume |clip_rect| is contained within the backing store. |
178 DCHECK(clip_rect.bottom() <= size().height()); | 178 DCHECK(clip_rect.bottom() <= size().height()); |
179 DCHECK(clip_rect.right() <= size().width()); | 179 DCHECK(clip_rect.right() <= size().width()); |
180 | 180 |
181 if ((dx || dy) && abs(dx) < size().width() && abs(dy) < size().height()) { | 181 if ((dx || dy) && abs(dx) < size().width() && abs(dy) < size().height()) { |
182 if (cg_layer()) { | 182 if (cg_layer()) { |
183 // Whether this version of OS X has broken CGLayers. See | 183 CGContextRef layer = CGLayerGetContext(cg_layer()); |
184 // http://crbug.com/45553 , comments 5 and 6. | |
185 bool needs_layer_workaround = base::mac::IsOSLeopardOrEarlier(); | |
186 | |
187 base::mac::ScopedCFTypeRef<CGLayerRef> new_layer; | |
188 CGContextRef layer; | |
189 | |
190 if (needs_layer_workaround) { | |
191 new_layer.reset(CreateCGLayer()); | |
192 // If the current view is in a window, the replacement must be too. | |
193 DCHECK(new_layer); | |
194 | |
195 layer = CGLayerGetContext(new_layer); | |
196 CGContextDrawLayerAtPoint(layer, CGPointMake(0, 0), cg_layer()); | |
197 } else { | |
198 layer = CGLayerGetContext(cg_layer()); | |
199 } | |
200 | |
201 CGContextSaveGState(layer); | 184 CGContextSaveGState(layer); |
202 CGContextClipToRect(layer, | 185 CGContextClipToRect(layer, |
203 CGRectMake(clip_rect.x(), | 186 CGRectMake(clip_rect.x(), |
204 size().height() - clip_rect.bottom(), | 187 size().height() - clip_rect.bottom(), |
205 clip_rect.width(), | 188 clip_rect.width(), |
206 clip_rect.height())); | 189 clip_rect.height())); |
207 CGContextDrawLayerAtPoint(layer, CGPointMake(dx, -dy), cg_layer()); | 190 CGContextDrawLayerAtPoint(layer, CGPointMake(dx, -dy), cg_layer()); |
208 CGContextRestoreGState(layer); | 191 CGContextRestoreGState(layer); |
209 | |
210 if (needs_layer_workaround) | |
211 cg_layer_.swap(new_layer); | |
212 } else { | 192 } else { |
213 // We don't have a layer, so scroll the contents of the CGBitmapContext. | 193 // We don't have a layer, so scroll the contents of the CGBitmapContext. |
214 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image( | 194 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image( |
215 CGBitmapContextCreateImage(cg_bitmap_)); | 195 CGBitmapContextCreateImage(cg_bitmap_)); |
216 CGContextSaveGState(cg_bitmap_); | 196 CGContextSaveGState(cg_bitmap_); |
217 CGContextClipToRect(cg_bitmap_, | 197 CGContextClipToRect(cg_bitmap_, |
218 CGRectMake(clip_rect.x(), | 198 CGRectMake(clip_rect.x(), |
219 size().height() - clip_rect.bottom(), | 199 size().height() - clip_rect.bottom(), |
220 clip_rect.width(), | 200 clip_rect.width(), |
221 clip_rect.height())); | 201 clip_rect.height())); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 pixel_size.width(), | 256 pixel_size.width(), |
277 pixel_size.height(), | 257 pixel_size.height(), |
278 8, pixel_size.width() * 4, | 258 8, pixel_size.width() * 4, |
279 base::mac::GetSystemColorSpace(), | 259 base::mac::GetSystemColorSpace(), |
280 kCGImageAlphaPremultipliedFirst | | 260 kCGImageAlphaPremultipliedFirst | |
281 kCGBitmapByteOrder32Host); | 261 kCGBitmapByteOrder32Host); |
282 DCHECK(context); | 262 DCHECK(context); |
283 | 263 |
284 return context; | 264 return context; |
285 } | 265 } |
OLD | NEW |