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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 bool* scheduled_completion_callback) { | 94 bool* scheduled_completion_callback) { |
95 *scheduled_completion_callback = false; | 95 *scheduled_completion_callback = false; |
96 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); | 96 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); |
97 | 97 |
98 TransportDIB* dib = process->GetTransportDIB(bitmap); | 98 TransportDIB* dib = process->GetTransportDIB(bitmap); |
99 if (!dib) | 99 if (!dib) |
100 return; | 100 return; |
101 | 101 |
102 gfx::Size pixel_size = gfx::ToFlooredSize( | 102 gfx::Size pixel_size = gfx::ToFlooredSize( |
103 size().Scale(device_scale_factor_)); | 103 size().Scale(device_scale_factor_)); |
104 gfx::RectF scaled_bitmap_rect = bitmap_rect; | 104 gfx::Rect pixel_bitmap_rect = ToFlooredRect( |
105 scaled_bitmap_rect.Scale(scale_factor); | 105 gfx::Scale(bitmap_rect, scale_factor)); |
106 gfx::Rect pixel_bitmap_rect = ToFlooredRect(scaled_bitmap_rect); | |
107 | 106 |
108 size_t bitmap_byte_count = | 107 size_t bitmap_byte_count = |
109 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4; | 108 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4; |
110 DCHECK_GE(dib->size(), bitmap_byte_count); | 109 DCHECK_GE(dib->size(), bitmap_byte_count); |
111 | 110 |
112 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( | 111 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( |
113 CGDataProviderCreateWithData(NULL, dib->memory(), | 112 CGDataProviderCreateWithData(NULL, dib->memory(), |
114 bitmap_byte_count, NULL)); | 113 bitmap_byte_count, NULL)); |
115 | 114 |
116 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image( | 115 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image( |
117 CGImageCreate(pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), | 116 CGImageCreate(pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), |
118 8, 32, 4 * pixel_bitmap_rect.width(), | 117 8, 32, 4 * pixel_bitmap_rect.width(), |
119 base::mac::GetSystemColorSpace(), | 118 base::mac::GetSystemColorSpace(), |
120 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, | 119 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, |
121 data_provider, NULL, false, kCGRenderingIntentDefault)); | 120 data_provider, NULL, false, kCGRenderingIntentDefault)); |
122 | 121 |
123 for (size_t i = 0; i < copy_rects.size(); i++) { | 122 for (size_t i = 0; i < copy_rects.size(); i++) { |
124 const gfx::Rect& copy_rect = copy_rects[i]; | 123 const gfx::Rect& copy_rect = copy_rects[i]; |
125 gfx::RectF scaled_copy_rect = copy_rect; | 124 gfx::Rect pixel_copy_rect = ToFlooredRect( |
126 scaled_copy_rect.Scale(scale_factor); | 125 gfx::Scale(copy_rect, scale_factor)); |
127 gfx::Rect pixel_copy_rect = ToFlooredRect(scaled_copy_rect); | |
128 | 126 |
129 // Only the subpixels given by copy_rect have pixels to copy. | 127 // Only the subpixels given by copy_rect have pixels to copy. |
130 base::mac::ScopedCFTypeRef<CGImageRef> image( | 128 base::mac::ScopedCFTypeRef<CGImageRef> image( |
131 CGImageCreateWithImageInRect(bitmap_image, CGRectMake( | 129 CGImageCreateWithImageInRect(bitmap_image, CGRectMake( |
132 pixel_copy_rect.x() - pixel_bitmap_rect.x(), | 130 pixel_copy_rect.x() - pixel_bitmap_rect.x(), |
133 pixel_copy_rect.y() - pixel_bitmap_rect.y(), | 131 pixel_copy_rect.y() - pixel_bitmap_rect.y(), |
134 pixel_copy_rect.width(), | 132 pixel_copy_rect.width(), |
135 pixel_copy_rect.height()))); | 133 pixel_copy_rect.height()))); |
136 | 134 |
137 if (!cg_layer()) { | 135 if (!cg_layer()) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 8, pixel_size.width() * 4, | 278 8, pixel_size.width() * 4, |
281 base::mac::GetSystemColorSpace(), | 279 base::mac::GetSystemColorSpace(), |
282 kCGImageAlphaPremultipliedFirst | | 280 kCGImageAlphaPremultipliedFirst | |
283 kCGBitmapByteOrder32Host); | 281 kCGBitmapByteOrder32Host); |
284 DCHECK(context); | 282 DCHECK(context); |
285 | 283 |
286 return context; | 284 return context; |
287 } | 285 } |
288 | 286 |
289 } // namespace content | 287 } // namespace content |
OLD | NEW |