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 <cmath> | 9 #include <cmath> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #include "content/browser/renderer_host/render_process_host_impl.h" | 14 #include "content/browser/renderer_host/render_process_host_impl.h" |
15 #include "content/browser/renderer_host/render_widget_host_impl.h" | 15 #include "content/browser/renderer_host/render_widget_host_impl.h" |
16 #include "content/public/browser/render_widget_host_view.h" | 16 #include "content/public/browser/render_widget_host_view.h" |
17 #include "skia/ext/platform_canvas.h" | 17 #include "skia/ext/platform_canvas.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
20 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 21 #include "ui/gfx/rect_conversions.h" |
21 #include "ui/gfx/size_conversions.h" | 22 #include "ui/gfx/size_conversions.h" |
22 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" | 23 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" |
23 #include "ui/surface/transport_dib.h" | 24 #include "ui/surface/transport_dib.h" |
24 | 25 |
25 namespace { | |
26 | |
27 // Returns a Rect obtained by flooring the values of the given RectF. | |
28 gfx::Rect ToFlooredRect(const gfx::RectF& rect) { | |
29 return gfx::Rect(static_cast<int>(std::floor(rect.x())), | |
30 static_cast<int>(std::floor(rect.y())), | |
31 static_cast<int>(std::floor(rect.width())), | |
32 static_cast<int>(std::floor(rect.height()))); | |
33 } | |
34 | |
35 } // namespace | |
36 | |
37 namespace content { | 26 namespace content { |
38 | 27 |
39 // Mac Backing Stores: | 28 // Mac Backing Stores: |
40 // | 29 // |
41 // Since backing stores are only ever written to or drawn into windows, we keep | 30 // Since backing stores are only ever written to or drawn into windows, we keep |
42 // our backing store in a CGLayer that can get cached in GPU memory. This | 31 // our backing store in a CGLayer that can get cached in GPU memory. This |
43 // allows acclerated drawing into the layer and lets scrolling and such happen | 32 // allows acclerated drawing into the layer and lets scrolling and such happen |
44 // all or mostly on the GPU, which is good for performance. | 33 // all or mostly on the GPU, which is good for performance. |
45 | 34 |
46 BackingStoreMac::BackingStoreMac(RenderWidgetHost* widget, | 35 BackingStoreMac::BackingStoreMac(RenderWidgetHost* widget, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 *scheduled_completion_callback = false; | 84 *scheduled_completion_callback = false; |
96 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); | 85 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); |
97 | 86 |
98 TransportDIB* dib = process->GetTransportDIB(bitmap); | 87 TransportDIB* dib = process->GetTransportDIB(bitmap); |
99 if (!dib) | 88 if (!dib) |
100 return; | 89 return; |
101 | 90 |
102 gfx::Size pixel_size = gfx::ToFlooredSize( | 91 gfx::Size pixel_size = gfx::ToFlooredSize( |
103 size().Scale(device_scale_factor_)); | 92 size().Scale(device_scale_factor_)); |
104 gfx::Rect pixel_bitmap_rect = | 93 gfx::Rect pixel_bitmap_rect = |
105 ToFlooredRect(bitmap_rect.Scale(scale_factor)); | 94 ToFlooredRectDeprecated(bitmap_rect.Scale(scale_factor)); |
106 | 95 |
107 size_t bitmap_byte_count = | 96 size_t bitmap_byte_count = |
108 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4; | 97 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4; |
109 DCHECK_GE(dib->size(), bitmap_byte_count); | 98 DCHECK_GE(dib->size(), bitmap_byte_count); |
110 | 99 |
111 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( | 100 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( |
112 CGDataProviderCreateWithData(NULL, dib->memory(), | 101 CGDataProviderCreateWithData(NULL, dib->memory(), |
113 bitmap_byte_count, NULL)); | 102 bitmap_byte_count, NULL)); |
114 | 103 |
115 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image( | 104 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image( |
116 CGImageCreate(pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), | 105 CGImageCreate(pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), |
117 8, 32, 4 * pixel_bitmap_rect.width(), | 106 8, 32, 4 * pixel_bitmap_rect.width(), |
118 base::mac::GetSystemColorSpace(), | 107 base::mac::GetSystemColorSpace(), |
119 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, | 108 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, |
120 data_provider, NULL, false, kCGRenderingIntentDefault)); | 109 data_provider, NULL, false, kCGRenderingIntentDefault)); |
121 | 110 |
122 for (size_t i = 0; i < copy_rects.size(); i++) { | 111 for (size_t i = 0; i < copy_rects.size(); i++) { |
123 const gfx::Rect& copy_rect = copy_rects[i]; | 112 const gfx::Rect& copy_rect = copy_rects[i]; |
124 gfx::Rect pixel_copy_rect = | 113 gfx::Rect pixel_copy_rect = |
125 ToFlooredRect(copy_rect.Scale(scale_factor)); | 114 ToFlooredRectDeprecated(copy_rect.Scale(scale_factor)); |
126 | 115 |
127 // Only the subpixels given by copy_rect have pixels to copy. | 116 // Only the subpixels given by copy_rect have pixels to copy. |
128 base::mac::ScopedCFTypeRef<CGImageRef> image( | 117 base::mac::ScopedCFTypeRef<CGImageRef> image( |
129 CGImageCreateWithImageInRect(bitmap_image, CGRectMake( | 118 CGImageCreateWithImageInRect(bitmap_image, CGRectMake( |
130 pixel_copy_rect.x() - pixel_bitmap_rect.x(), | 119 pixel_copy_rect.x() - pixel_bitmap_rect.x(), |
131 pixel_copy_rect.y() - pixel_bitmap_rect.y(), | 120 pixel_copy_rect.y() - pixel_bitmap_rect.y(), |
132 pixel_copy_rect.width(), | 121 pixel_copy_rect.width(), |
133 pixel_copy_rect.height()))); | 122 pixel_copy_rect.height()))); |
134 | 123 |
135 if (!cg_layer()) { | 124 if (!cg_layer()) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 8, pixel_size.width() * 4, | 267 8, pixel_size.width() * 4, |
279 base::mac::GetSystemColorSpace(), | 268 base::mac::GetSystemColorSpace(), |
280 kCGImageAlphaPremultipliedFirst | | 269 kCGImageAlphaPremultipliedFirst | |
281 kCGBitmapByteOrder32Host); | 270 kCGBitmapByteOrder32Host); |
282 DCHECK(context); | 271 DCHECK(context); |
283 | 272 |
284 return context; | 273 return context; |
285 } | 274 } |
286 | 275 |
287 } // namespace content | 276 } // namespace content |
OLD | NEW |