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

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

Issue 11235017: Revert to old rect conversion behavior (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebasing 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/renderer/browser_plugin/browser_plugin_backing_store.cc » ('j') | 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) 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::RectF scaled_bitmap_rect = bitmap_rect; 93 gfx::RectF scaled_bitmap_rect = bitmap_rect;
105 scaled_bitmap_rect.Scale(scale_factor); 94 scaled_bitmap_rect.Scale(scale_factor);
106 gfx::Rect pixel_bitmap_rect = ToFlooredRect(scaled_bitmap_rect); 95 gfx::Rect pixel_bitmap_rect = ToFlooredRectDeprecated(scaled_bitmap_rect);
107 96
108 size_t bitmap_byte_count = 97 size_t bitmap_byte_count =
109 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4; 98 pixel_bitmap_rect.width() * pixel_bitmap_rect.height() * 4;
110 DCHECK_GE(dib->size(), bitmap_byte_count); 99 DCHECK_GE(dib->size(), bitmap_byte_count);
111 100
112 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider( 101 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider(
113 CGDataProviderCreateWithData(NULL, dib->memory(), 102 CGDataProviderCreateWithData(NULL, dib->memory(),
114 bitmap_byte_count, NULL)); 103 bitmap_byte_count, NULL));
115 104
116 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image( 105 base::mac::ScopedCFTypeRef<CGImageRef> bitmap_image(
117 CGImageCreate(pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), 106 CGImageCreate(pixel_bitmap_rect.width(), pixel_bitmap_rect.height(),
118 8, 32, 4 * pixel_bitmap_rect.width(), 107 8, 32, 4 * pixel_bitmap_rect.width(),
119 base::mac::GetSystemColorSpace(), 108 base::mac::GetSystemColorSpace(),
120 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, 109 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
121 data_provider, NULL, false, kCGRenderingIntentDefault)); 110 data_provider, NULL, false, kCGRenderingIntentDefault));
122 111
123 for (size_t i = 0; i < copy_rects.size(); i++) { 112 for (size_t i = 0; i < copy_rects.size(); i++) {
124 const gfx::Rect& copy_rect = copy_rects[i]; 113 const gfx::Rect& copy_rect = copy_rects[i];
125 gfx::RectF scaled_copy_rect = copy_rect; 114 gfx::RectF scaled_copy_rect = copy_rect;
126 scaled_copy_rect.Scale(scale_factor); 115 scaled_copy_rect.Scale(scale_factor);
127 gfx::Rect pixel_copy_rect = ToFlooredRect(scaled_copy_rect); 116 gfx::Rect pixel_copy_rect = ToFlooredRectDeprecated(scaled_copy_rect);
128 117
129 // Only the subpixels given by copy_rect have pixels to copy. 118 // Only the subpixels given by copy_rect have pixels to copy.
130 base::mac::ScopedCFTypeRef<CGImageRef> image( 119 base::mac::ScopedCFTypeRef<CGImageRef> image(
131 CGImageCreateWithImageInRect(bitmap_image, CGRectMake( 120 CGImageCreateWithImageInRect(bitmap_image, CGRectMake(
132 pixel_copy_rect.x() - pixel_bitmap_rect.x(), 121 pixel_copy_rect.x() - pixel_bitmap_rect.x(),
133 pixel_copy_rect.y() - pixel_bitmap_rect.y(), 122 pixel_copy_rect.y() - pixel_bitmap_rect.y(),
134 pixel_copy_rect.width(), 123 pixel_copy_rect.width(),
135 pixel_copy_rect.height()))); 124 pixel_copy_rect.height())));
136 125
137 if (!cg_layer()) { 126 if (!cg_layer()) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 8, pixel_size.width() * 4, 269 8, pixel_size.width() * 4,
281 base::mac::GetSystemColorSpace(), 270 base::mac::GetSystemColorSpace(),
282 kCGImageAlphaPremultipliedFirst | 271 kCGImageAlphaPremultipliedFirst |
283 kCGBitmapByteOrder32Host); 272 kCGBitmapByteOrder32Host);
284 DCHECK(context); 273 DCHECK(context);
285 274
286 return context; 275 return context;
287 } 276 }
288 277
289 } // namespace content 278 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/browser_plugin/browser_plugin_backing_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698