OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "base/sys_info.h" | |
13 #include "content/browser/renderer_host/render_process_host.h" | 12 #include "content/browser/renderer_host/render_process_host.h" |
14 #include "content/browser/renderer_host/render_widget_host.h" | 13 #include "content/browser/renderer_host/render_widget_host.h" |
15 #include "content/browser/renderer_host/render_widget_host_view.h" | 14 #include "content/browser/renderer_host/render_widget_host_view.h" |
16 #include "skia/ext/platform_canvas.h" | 15 #include "skia/ext/platform_canvas.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
18 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
19 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
20 #include "ui/gfx/surface/transport_dib.h" | 19 #include "ui/gfx/surface/transport_dib.h" |
21 | 20 |
22 // Mac Backing Stores: | 21 // Mac Backing Stores: |
23 // | 22 // |
24 // Since backing stores are only ever written to or drawn into windows, we keep | 23 // Since backing stores are only ever written to or drawn into windows, we keep |
25 // our backing store in a CGLayer that can get cached in GPU memory. This | 24 // our backing store in a CGLayer that can get cached in GPU memory. This |
26 // allows acclerated drawing into the layer and lets scrolling and such happen | 25 // allows acclerated drawing into the layer and lets scrolling and such happen |
27 // all or mostly on the GPU, which is good for performance. | 26 // all or mostly on the GPU, which is good for performance. |
28 | 27 |
29 namespace { | |
30 | |
31 // Returns whether this version of OS X has broken CGLayers, see | |
32 // http://crbug.com/45553 , comments 5 and 6. | |
33 bool NeedsLayerWorkaround() { | |
34 int32 os_major, os_minor, os_bugfix; | |
35 base::SysInfo::OperatingSystemVersionNumbers( | |
36 &os_major, &os_minor, &os_bugfix); | |
37 return os_major == 10 && os_minor == 5; | |
38 } | |
39 | |
40 } // namespace | |
41 | |
42 BackingStoreMac::BackingStoreMac(RenderWidgetHost* widget, | 28 BackingStoreMac::BackingStoreMac(RenderWidgetHost* widget, |
43 const gfx::Size& size) | 29 const gfx::Size& size) |
44 : BackingStore(widget, size) { | 30 : BackingStore(widget, size) { |
45 cg_layer_.reset(CreateCGLayer()); | 31 cg_layer_.reset(CreateCGLayer()); |
46 if (!cg_layer_) { | 32 if (!cg_layer_) { |
47 // The view isn't in a window yet. Use a CGBitmapContext for now. | 33 // The view isn't in a window yet. Use a CGBitmapContext for now. |
48 cg_bitmap_.reset(CreateCGBitmapContext()); | 34 cg_bitmap_.reset(CreateCGBitmapContext()); |
49 } | 35 } |
50 } | 36 } |
51 | 37 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // scroll. Thus, we only have to worry about pixels which will end up inside | 134 // scroll. Thus, we only have to worry about pixels which will end up inside |
149 // the clipping rectangle. (Note that the clipping rectangle is not | 135 // the clipping rectangle. (Note that the clipping rectangle is not |
150 // translated by the scroll.) | 136 // translated by the scroll.) |
151 | 137 |
152 // We assume |clip_rect| is contained within the backing store. | 138 // We assume |clip_rect| is contained within the backing store. |
153 DCHECK(clip_rect.bottom() <= size().height()); | 139 DCHECK(clip_rect.bottom() <= size().height()); |
154 DCHECK(clip_rect.right() <= size().width()); | 140 DCHECK(clip_rect.right() <= size().width()); |
155 | 141 |
156 if ((dx || dy) && abs(dx) < size().width() && abs(dy) < size().height()) { | 142 if ((dx || dy) && abs(dx) < size().width() && abs(dy) < size().height()) { |
157 if (cg_layer()) { | 143 if (cg_layer()) { |
158 // See http://crbug.com/45553 , comments 5 and 6. | 144 // Whether this version of OS X has broken CGLayers. See |
159 static bool needs_layer_workaround = NeedsLayerWorkaround(); | 145 // http://crbug.com/45553 , comments 5 and 6. |
| 146 bool needs_layer_workaround = base::mac::IsOSLeopardOrEarlier(); |
160 | 147 |
161 base::mac::ScopedCFTypeRef<CGLayerRef> new_layer; | 148 base::mac::ScopedCFTypeRef<CGLayerRef> new_layer; |
162 CGContextRef layer; | 149 CGContextRef layer; |
163 | 150 |
164 if (needs_layer_workaround) { | 151 if (needs_layer_workaround) { |
165 new_layer.reset(CreateCGLayer()); | 152 new_layer.reset(CreateCGLayer()); |
166 // If the current view is in a window, the replacement must be too. | 153 // If the current view is in a window, the replacement must be too. |
167 DCHECK(new_layer); | 154 DCHECK(new_layer); |
168 | 155 |
169 layer = CGLayerGetContext(new_layer); | 156 layer = CGLayerGetContext(new_layer); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 CGContextRef context = CGBitmapContextCreate(NULL, | 220 CGContextRef context = CGBitmapContextCreate(NULL, |
234 size().width(), size().height(), | 221 size().width(), size().height(), |
235 8, size().width() * 4, | 222 8, size().width() * 4, |
236 base::mac::GetSystemColorSpace(), | 223 base::mac::GetSystemColorSpace(), |
237 kCGImageAlphaPremultipliedFirst | | 224 kCGImageAlphaPremultipliedFirst | |
238 kCGBitmapByteOrder32Host); | 225 kCGBitmapByteOrder32Host); |
239 DCHECK(context); | 226 DCHECK(context); |
240 | 227 |
241 return context; | 228 return context; |
242 } | 229 } |
OLD | NEW |