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 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 cg_layer_.swap(new_layer); | 64 cg_layer_.swap(new_layer); |
65 if (!cg_layer_) { | 65 if (!cg_layer_) { |
66 // The view isn't in a window yet. Use a CGBitmapContext for now. | 66 // The view isn't in a window yet. Use a CGBitmapContext for now. |
67 cg_bitmap_.reset(CreateCGBitmapContext()); | 67 cg_bitmap_.reset(CreateCGBitmapContext()); |
68 CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_); | 68 CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 size_t BackingStoreMac::MemorySize() { | 72 size_t BackingStoreMac::MemorySize() { |
73 return gfx::ToFlooredSize(size().Scale(device_scale_factor_)).GetArea() * 4; | 73 return gfx::ToFlooredSize( |
| 74 gfx::ScaleSize(size(), device_scale_factor_)).GetArea() * 4; |
74 } | 75 } |
75 | 76 |
76 void BackingStoreMac::PaintToBackingStore( | 77 void BackingStoreMac::PaintToBackingStore( |
77 RenderProcessHost* process, | 78 RenderProcessHost* process, |
78 TransportDIB::Id bitmap, | 79 TransportDIB::Id bitmap, |
79 const gfx::Rect& bitmap_rect, | 80 const gfx::Rect& bitmap_rect, |
80 const std::vector<gfx::Rect>& copy_rects, | 81 const std::vector<gfx::Rect>& copy_rects, |
81 float scale_factor, | 82 float scale_factor, |
82 const base::Closure& completion_callback, | 83 const base::Closure& completion_callback, |
83 bool* scheduled_completion_callback) { | 84 bool* scheduled_completion_callback) { |
84 *scheduled_completion_callback = false; | 85 *scheduled_completion_callback = false; |
85 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); | 86 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); |
86 | 87 |
87 TransportDIB* dib = process->GetTransportDIB(bitmap); | 88 TransportDIB* dib = process->GetTransportDIB(bitmap); |
88 if (!dib) | 89 if (!dib) |
89 return; | 90 return; |
90 | 91 |
91 gfx::Size pixel_size = gfx::ToFlooredSize( | 92 gfx::Size pixel_size = gfx::ToFlooredSize( |
92 size().Scale(device_scale_factor_)); | 93 gfx::ScaleSize(size(), device_scale_factor_)); |
93 gfx::Rect pixel_bitmap_rect = ToFlooredRectDeprecated( | 94 gfx::Rect pixel_bitmap_rect = ToFlooredRectDeprecated( |
94 gfx::ScaleRect(bitmap_rect, scale_factor)); | 95 gfx::ScaleRect(bitmap_rect, scale_factor)); |
95 | 96 |
96 size_t bitmap_byte_count = | 97 size_t bitmap_byte_count = |
97 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4; | 98 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4; |
98 DCHECK_GE(dib->size(), bitmap_byte_count); | 99 DCHECK_GE(dib->size(), bitmap_byte_count); |
99 | 100 |
100 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( | 101 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( |
101 CGDataProviderCreateWithData(NULL, dib->memory(), | 102 CGDataProviderCreateWithData(NULL, dib->memory(), |
102 bitmap_byte_count, NULL)); | 103 bitmap_byte_count, NULL)); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 242 } |
242 | 243 |
243 NSGraphicsContext* ns_context = [window graphicsContext]; | 244 NSGraphicsContext* ns_context = [window graphicsContext]; |
244 DCHECK(ns_context); | 245 DCHECK(ns_context); |
245 | 246 |
246 CGContextRef cg_context = static_cast<CGContextRef>( | 247 CGContextRef cg_context = static_cast<CGContextRef>( |
247 [ns_context graphicsPort]); | 248 [ns_context graphicsPort]); |
248 DCHECK(cg_context); | 249 DCHECK(cg_context); |
249 | 250 |
250 // Note: This takes the backingScaleFactor of cg_context into account. The | 251 // Note: This takes the backingScaleFactor of cg_context into account. The |
251 // bitmap backing |layer| with be size().Scale(2) in HiDPI mode automatically. | 252 // bitmap backing |layer| will be size() * 2 in HiDPI mode automatically. |
252 CGLayerRef layer = CGLayerCreateWithContext(cg_context, | 253 CGLayerRef layer = CGLayerCreateWithContext(cg_context, |
253 size().ToCGSize(), | 254 size().ToCGSize(), |
254 NULL); | 255 NULL); |
255 DCHECK(layer); | 256 DCHECK(layer); |
256 | 257 |
257 return layer; | 258 return layer; |
258 } | 259 } |
259 | 260 |
260 CGContextRef BackingStoreMac::CreateCGBitmapContext() { | 261 CGContextRef BackingStoreMac::CreateCGBitmapContext() { |
261 gfx::Size pixel_size = gfx::ToFlooredSize(size().Scale(device_scale_factor_)); | 262 gfx::Size pixel_size = gfx::ToFlooredSize( |
| 263 gfx::ScaleSize(size(), device_scale_factor_)); |
262 // A CGBitmapContext serves as a stand-in for the layer before the view is | 264 // A CGBitmapContext serves as a stand-in for the layer before the view is |
263 // in a containing window. | 265 // in a containing window. |
264 CGContextRef context = CGBitmapContextCreate(NULL, | 266 CGContextRef context = CGBitmapContextCreate(NULL, |
265 pixel_size.width(), | 267 pixel_size.width(), |
266 pixel_size.height(), | 268 pixel_size.height(), |
267 8, pixel_size.width() * 4, | 269 8, pixel_size.width() * 4, |
268 base::mac::GetSystemColorSpace(), | 270 base::mac::GetSystemColorSpace(), |
269 kCGImageAlphaPremultipliedFirst | | 271 kCGImageAlphaPremultipliedFirst | |
270 kCGBitmapByteOrder32Host); | 272 kCGBitmapByteOrder32Host); |
271 DCHECK(context); | 273 DCHECK(context); |
272 | 274 |
273 return context; | 275 return context; |
274 } | 276 } |
275 | 277 |
276 } // namespace content | 278 } // namespace content |
OLD | NEW |