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

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

Issue 11110004: Make gfx::Rect class operations consistently mutate the class they are called on. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: cc/ fixes Created 8 years, 1 month 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
OLDNEW
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
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::Rect pixel_bitmap_rect = 104 gfx::RectF scaled_bitmap_rect = bitmap_rect;
105 ToFlooredRect(bitmap_rect.Scale(scale_factor)); 105 scaled_bitmap_rect.Scale(scale_factor);
106 gfx::Rect pixel_bitmap_rect = ToFlooredRect(scaled_bitmap_rect);
106 107
107 size_t bitmap_byte_count = 108 size_t bitmap_byte_count =
108 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4; 109 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4;
109 DCHECK_GE(dib->size(), bitmap_byte_count); 110 DCHECK_GE(dib->size(), bitmap_byte_count);
110 111
111 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( 112 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider(
112 CGDataProviderCreateWithData(NULL, dib->memory(), 113 CGDataProviderCreateWithData(NULL, dib->memory(),
113 bitmap_byte_count, NULL)); 114 bitmap_byte_count, NULL));
114 115
115 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image( 116 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image(
116 CGImageCreate(pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), 117 CGImageCreate(pixel_bitmap_rect.width(), pixel_bitmap_rect.height(),
117 8, 32, 4 * pixel_bitmap_rect.width(), 118 8, 32, 4 * pixel_bitmap_rect.width(),
118 base::mac::GetSystemColorSpace(), 119 base::mac::GetSystemColorSpace(),
119 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, 120 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
120 data_provider, NULL, false, kCGRenderingIntentDefault)); 121 data_provider, NULL, false, kCGRenderingIntentDefault));
121 122
122 for (size_t i = 0; i < copy_rects.size(); i++) { 123 for (size_t i = 0; i < copy_rects.size(); i++) {
123 const gfx::Rect& copy_rect = copy_rects[i]; 124 const gfx::Rect& copy_rect = copy_rects[i];
124 gfx::Rect pixel_copy_rect = 125 gfx::RectF scaled_copy_rect = copy_rect;
125 ToFlooredRect(copy_rect.Scale(scale_factor)); 126 scaled_copy_rect.Scale(scale_factor);
127 gfx::Rect pixel_copy_rect = ToFlooredRect(scaled_copy_rect);
126 128
127 // Only the subpixels given by copy_rect have pixels to copy. 129 // Only the subpixels given by copy_rect have pixels to copy.
128 base::mac::ScopedCFTypeRef<CGImageRef> image( 130 base::mac::ScopedCFTypeRef<CGImageRef> image(
129 CGImageCreateWithImageInRect(bitmap_image, CGRectMake( 131 CGImageCreateWithImageInRect(bitmap_image, CGRectMake(
130 pixel_copy_rect.x() - pixel_bitmap_rect.x(), 132 pixel_copy_rect.x() - pixel_bitmap_rect.x(),
131 pixel_copy_rect.y() - pixel_bitmap_rect.y(), 133 pixel_copy_rect.y() - pixel_bitmap_rect.y(),
132 pixel_copy_rect.width(), 134 pixel_copy_rect.width(),
133 pixel_copy_rect.height()))); 135 pixel_copy_rect.height())));
134 136
135 if (!cg_layer()) { 137 if (!cg_layer()) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 8, pixel_size.width() * 4, 280 8, pixel_size.width() * 4,
279 base::mac::GetSystemColorSpace(), 281 base::mac::GetSystemColorSpace(),
280 kCGImageAlphaPremultipliedFirst | 282 kCGImageAlphaPremultipliedFirst |
281 kCGBitmapByteOrder32Host); 283 kCGBitmapByteOrder32Host);
282 DCHECK(context); 284 DCHECK(context);
283 285
284 return context; 286 return context;
285 } 287 }
286 288
287 } // namespace content 289 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/backing_store_aura.cc ('k') | content/browser/renderer_host/backing_store_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698