Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/browser/renderer_host/backing_store_mac.mm

Issue 2771010: Mac: Faster scrolling on 10.6. (Closed)
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/backing_store_mac.h" 7 #include "chrome/browser/renderer_host/backing_store_mac.h"
8 8
9 #include "app/surface/transport_dib.h" 9 #include "app/surface/transport_dib.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/mac_util.h" 11 #include "base/mac_util.h"
12 #include "base/sys_info.h"
12 #include "chrome/browser/renderer_host/render_process_host.h" 13 #include "chrome/browser/renderer_host/render_process_host.h"
13 #include "chrome/browser/renderer_host/render_widget_host.h" 14 #include "chrome/browser/renderer_host/render_widget_host.h"
14 #include "chrome/browser/renderer_host/render_widget_host_view.h" 15 #include "chrome/browser/renderer_host/render_widget_host_view.h"
15 #include "skia/ext/platform_canvas.h" 16 #include "skia/ext/platform_canvas.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
17 #include "third_party/skia/include/core/SkCanvas.h" 18 #include "third_party/skia/include/core/SkCanvas.h"
18 19
19 // Mac Backing Stores: 20 // Mac Backing Stores:
20 // 21 //
21 // Since backing stores are only ever written to or drawn into windows, we keep 22 // Since backing stores are only ever written to or drawn into windows, we keep
22 // our backing store in a CGLayer that can get cached in GPU memory. This 23 // our backing store in a CGLayer that can get cached in GPU memory. This
23 // allows acclerated drawing into the layer and lets scrolling and such happen 24 // allows acclerated drawing into the layer and lets scrolling and such happen
24 // all or mostly on the GPU, which is good for performance. 25 // all or mostly on the GPU, which is good for performance.
25 26
27 namespace {
28
29 // Returns if this version of OS X has broken CGLayers, see
Mark Mentovai 2010/06/10 20:05:51 “Returns if” implies that this function doesn’t re
Nico 2010/06/10 20:10:30 Done.
30 // http://crbug.com/45553 , comments 5 and 6.
31 bool NeedsLayerWorkaround() {
32 int32 os_major, os_minor, os_bugfix;
33 base::SysInfo::OperatingSystemVersionNumbers(
34 &os_major, &os_minor, &os_bugfix);
35 return os_major == 10 && os_minor == 5;
Mark Mentovai 2010/06/10 20:05:51 For paranoia’s sake: return os_major < 10 || (o
Nico 2010/06/10 20:10:30 Uh, no :-)
rohitrao (ping after 24h) 2010/06/10 20:55:08 Why not? The specificity of checking for 10.5 sca
Nico 2010/06/10 21:08:04 'cause Chrome won't run on 10.4 (or OS 9 for that
36 }
37
38 } // namespace
39
26 BackingStoreMac::BackingStoreMac(RenderWidgetHost* widget, 40 BackingStoreMac::BackingStoreMac(RenderWidgetHost* widget,
27 const gfx::Size& size) 41 const gfx::Size& size)
28 : BackingStore(widget, size) { 42 : BackingStore(widget, size) {
29 cg_layer_.reset(CreateCGLayer()); 43 cg_layer_.reset(CreateCGLayer());
30 if (!cg_layer_) { 44 if (!cg_layer_) {
31 // The view isn't in a window yet. Use a CGBitmapContext for now. 45 // The view isn't in a window yet. Use a CGBitmapContext for now.
32 cg_bitmap_.reset(CreateCGBitmapContext()); 46 cg_bitmap_.reset(CreateCGBitmapContext());
33 } 47 }
34 } 48 }
35 49
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // scroll. Thus, we only have to worry about pixels which will end up inside 151 // scroll. Thus, we only have to worry about pixels which will end up inside
138 // the clipping rectangle. (Note that the clipping rectangle is not 152 // the clipping rectangle. (Note that the clipping rectangle is not
139 // translated by the scroll.) 153 // translated by the scroll.)
140 154
141 // We assume |clip_rect| is contained within the backing store. 155 // We assume |clip_rect| is contained within the backing store.
142 DCHECK(clip_rect.bottom() <= size().height()); 156 DCHECK(clip_rect.bottom() <= size().height());
143 DCHECK(clip_rect.right() <= size().width()); 157 DCHECK(clip_rect.right() <= size().width());
144 158
145 if ((dx || dy) && abs(dx) < size().width() && abs(dy) < size().height()) { 159 if ((dx || dy) && abs(dx) < size().width() && abs(dy) < size().height()) {
146 if (cg_layer()) { 160 if (cg_layer()) {
147 scoped_cftyperef<CGLayerRef> new_layer(CreateCGLayer()); 161 // See http://crbug.com/45553 , comments 5 and 6.
162 static bool needs_layer_workaround = NeedsLayerWorkaround();
148 163
149 // If the current view is in a window, the replacement must be too. 164 scoped_cftyperef<CGLayerRef> new_layer;
150 DCHECK(new_layer); 165 CGContextRef layer;
151 166
152 CGContextRef layer = CGLayerGetContext(new_layer); 167 if (needs_layer_workaround) {
153 CGContextDrawLayerAtPoint(layer, CGPointMake(0, 0), cg_layer()); 168 new_layer.reset(CreateCGLayer());
169 // If the current view is in a window, the replacement must be too.
170 DCHECK(new_layer);
171
172 layer = CGLayerGetContext(new_layer);
173 CGContextDrawLayerAtPoint(layer, CGPointMake(0, 0), cg_layer());
174 } else {
175 layer = CGLayerGetContext(cg_layer());
176 }
177
154 CGContextSaveGState(layer); 178 CGContextSaveGState(layer);
155 CGContextClipToRect(layer, 179 CGContextClipToRect(layer,
156 CGRectMake(clip_rect.x(), 180 CGRectMake(clip_rect.x(),
157 size().height() - clip_rect.bottom(), 181 size().height() - clip_rect.bottom(),
158 clip_rect.width(), 182 clip_rect.width(),
159 clip_rect.height())); 183 clip_rect.height()));
160 CGContextDrawLayerAtPoint(layer, CGPointMake(dx, -dy), cg_layer()); 184 CGContextDrawLayerAtPoint(layer, CGPointMake(dx, -dy), cg_layer());
161 CGContextRestoreGState(layer); 185 CGContextRestoreGState(layer);
162 cg_layer_.swap(new_layer); 186
187 if (needs_layer_workaround)
188 cg_layer_.swap(new_layer);
163 } else { 189 } else {
164 // We don't have a layer, so scroll the contents of the CGBitmapContext. 190 // We don't have a layer, so scroll the contents of the CGBitmapContext.
165 scoped_cftyperef<CGContextRef> new_bitmap(CreateCGBitmapContext());
166 scoped_cftyperef<CGImageRef> bitmap_image( 191 scoped_cftyperef<CGImageRef> bitmap_image(
167 CGBitmapContextCreateImage(cg_bitmap_)); 192 CGBitmapContextCreateImage(cg_bitmap_));
168 CGContextDrawImage(new_bitmap, 193 CGContextSaveGState(cg_bitmap_);
169 CGRectMake(0, 0, size().width(), size().height()), 194 CGContextClipToRect(cg_bitmap_,
170 bitmap_image);
171 CGContextSaveGState(new_bitmap);
172 CGContextClipToRect(new_bitmap,
173 CGRectMake(clip_rect.x(), 195 CGRectMake(clip_rect.x(),
174 size().height() - clip_rect.bottom(), 196 size().height() - clip_rect.bottom(),
175 clip_rect.width(), 197 clip_rect.width(),
176 clip_rect.height())); 198 clip_rect.height()));
177 CGContextDrawImage(new_bitmap, 199 CGContextDrawImage(cg_bitmap_,
178 CGRectMake(dx, -dy, size().width(), size().height()), 200 CGRectMake(dx, -dy, size().width(), size().height()),
179 bitmap_image); 201 bitmap_image);
180 CGContextRestoreGState(new_bitmap); 202 CGContextRestoreGState(cg_bitmap_);
181 cg_bitmap_.swap(new_bitmap);
182 } 203 }
183 } 204 }
184 } 205 }
185 206
186 CGLayerRef BackingStoreMac::CreateCGLayer() { 207 CGLayerRef BackingStoreMac::CreateCGLayer() {
187 // The CGLayer should be optimized for drawing into the containing window, 208 // The CGLayer should be optimized for drawing into the containing window,
188 // so extract a CGContext corresponding to the window to be passed to 209 // so extract a CGContext corresponding to the window to be passed to
189 // CGLayerCreateWithContext. 210 // CGLayerCreateWithContext.
190 NSWindow* window = [render_widget_host()->view()->GetNativeView() window]; 211 NSWindow* window = [render_widget_host()->view()->GetNativeView() window];
191 if ([window windowNumber] <= 0) { 212 if ([window windowNumber] <= 0) {
(...skipping 23 matching lines...) Expand all
215 CGContextRef context = CGBitmapContextCreate(NULL, 236 CGContextRef context = CGBitmapContextCreate(NULL,
216 size().width(), size().height(), 237 size().width(), size().height(),
217 8, size().width() * 4, 238 8, size().width() * 4,
218 mac_util::GetSystemColorSpace(), 239 mac_util::GetSystemColorSpace(),
219 kCGImageAlphaPremultipliedFirst | 240 kCGImageAlphaPremultipliedFirst |
220 kCGBitmapByteOrder32Host); 241 kCGBitmapByteOrder32Host);
221 DCHECK(context); 242 DCHECK(context);
222 243
223 return context; 244 return context;
224 } 245 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698