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

Side by Side Diff: content/browser/renderer_host/backing_store_aura.cc

Issue 11081007: Remove implicit flooring Scale() method from Point and Size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git try -b win_rel,mac_rel,linux_rel,linux_aura Created 8 years, 2 months 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
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 #include "content/browser/renderer_host/backing_store_aura.h" 5 #include "content/browser/renderer_host/backing_store_aura.h"
6 6
7 #include "content/browser/renderer_host/dip_util.h" 7 #include "content/browser/renderer_host/dip_util.h"
8 #include "content/browser/renderer_host/render_process_host_impl.h" 8 #include "content/browser/renderer_host/render_process_host_impl.h"
9 #include "content/public/browser/render_widget_host.h" 9 #include "content/public/browser/render_widget_host.h"
10 #include "skia/ext/platform_canvas.h" 10 #include "skia/ext/platform_canvas.h"
11 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/image/image_skia.h" 13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/gfx/rect.h" 14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/rect_conversions.h" 15 #include "ui/gfx/rect_conversions.h"
16 #include "ui/gfx/size_conversions.h"
16 17
17 namespace content { 18 namespace content {
18 19
19 // Assume that somewhere along the line, someone will do width * height * 4 20 // Assume that somewhere along the line, someone will do width * height * 4
20 // with signed numbers. If the maximum value is 2**31, then 2**31 / 4 = 21 // with signed numbers. If the maximum value is 2**31, then 2**31 / 4 =
21 // 2**29 and floor(sqrt(2**29)) = 23170. 22 // 2**29 and floor(sqrt(2**29)) = 23170.
22 23
23 // Max height and width for layers 24 // Max height and width for layers
24 static const int kMaxVideoLayerSize = 23170; 25 static const int kMaxVideoLayerSize = 23170;
25 26
26 BackingStoreAura::BackingStoreAura(RenderWidgetHost* widget, 27 BackingStoreAura::BackingStoreAura(RenderWidgetHost* widget,
27 const gfx::Size& size) 28 const gfx::Size& size)
28 : BackingStore(widget, size) { 29 : BackingStore(widget, size) {
29 device_scale_factor_ = 30 device_scale_factor_ =
30 ui::GetScaleFactorScale(GetScaleFactorForView(widget->GetView())); 31 ui::GetScaleFactorScale(GetScaleFactorForView(widget->GetView()));
31 gfx::Size pixel_size = size.Scale(device_scale_factor_); 32 gfx::Size pixel_size = gfx::ToFlooredSize(size.Scale(device_scale_factor_));
32 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, 33 bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
33 pixel_size.width(), pixel_size.height()); 34 pixel_size.width(), pixel_size.height());
34 bitmap_.allocPixels(); 35 bitmap_.allocPixels();
35 canvas_.reset(new SkCanvas(bitmap_)); 36 canvas_.reset(new SkCanvas(bitmap_));
36 } 37 }
37 38
38 BackingStoreAura::~BackingStoreAura() { 39 BackingStoreAura::~BackingStoreAura() {
39 } 40 }
40 41
41 void BackingStoreAura::SkiaShowRect(const gfx::Point& point, 42 void BackingStoreAura::SkiaShowRect(const gfx::Point& point,
42 gfx::Canvas* canvas) { 43 gfx::Canvas* canvas) {
43 gfx::ImageSkia image = gfx::ImageSkia(gfx::ImageSkiaRep(bitmap_, 44 gfx::ImageSkia image = gfx::ImageSkia(gfx::ImageSkiaRep(bitmap_,
44 ui::GetScaleFactorFromScale(device_scale_factor_))); 45 ui::GetScaleFactorFromScale(device_scale_factor_)));
45 canvas->DrawImageInt(image, point.x(), point.y()); 46 canvas->DrawImageInt(image, point.x(), point.y());
46 } 47 }
47 48
48 void BackingStoreAura::ScaleFactorChanged(float device_scale_factor) { 49 void BackingStoreAura::ScaleFactorChanged(float device_scale_factor) {
49 if (device_scale_factor == device_scale_factor_) 50 if (device_scale_factor == device_scale_factor_)
50 return; 51 return;
51 52
52 gfx::Size old_pixel_size = size().Scale(device_scale_factor_); 53 gfx::Size old_pixel_size = gfx::ToFlooredSize(
54 size().Scale(device_scale_factor_));
53 device_scale_factor_ = device_scale_factor; 55 device_scale_factor_ = device_scale_factor;
54 56
55 gfx::Size pixel_size = size().Scale(device_scale_factor_); 57 gfx::Size pixel_size = gfx::ToFlooredSize(size().Scale(device_scale_factor_));
56 SkBitmap new_bitmap; 58 SkBitmap new_bitmap;
57 new_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 59 new_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
58 pixel_size.width(), pixel_size.height()); 60 pixel_size.width(), pixel_size.height());
59 new_bitmap.allocPixels(); 61 new_bitmap.allocPixels();
60 scoped_ptr<SkCanvas> new_canvas(new SkCanvas(new_bitmap)); 62 scoped_ptr<SkCanvas> new_canvas(new SkCanvas(new_bitmap));
61 63
62 // Copy old contents; a low-res flash is better than a black flash. 64 // Copy old contents; a low-res flash is better than a black flash.
63 SkPaint copy_paint; 65 SkPaint copy_paint;
64 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); 66 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode);
65 SkIRect src_rect = SkIRect::MakeWH(old_pixel_size.width(), 67 SkIRect src_rect = SkIRect::MakeWH(old_pixel_size.width(),
66 old_pixel_size.height()); 68 old_pixel_size.height());
67 SkRect dst_rect = SkRect::MakeWH(pixel_size.width(), pixel_size.height()); 69 SkRect dst_rect = SkRect::MakeWH(pixel_size.width(), pixel_size.height());
68 new_canvas.get()->drawBitmapRect(bitmap_, &src_rect, dst_rect, &copy_paint); 70 new_canvas.get()->drawBitmapRect(bitmap_, &src_rect, dst_rect, &copy_paint);
69 71
70 canvas_.swap(new_canvas); 72 canvas_.swap(new_canvas);
71 bitmap_ = new_bitmap; 73 bitmap_ = new_bitmap;
72 } 74 }
73 75
74 size_t BackingStoreAura::MemorySize() { 76 size_t BackingStoreAura::MemorySize() {
75 // NOTE: The computation may be different when the canvas is a subrectangle of 77 // NOTE: The computation may be different when the canvas is a subrectangle of
76 // a larger bitmap. 78 // a larger bitmap.
77 return size().Scale(device_scale_factor_).GetArea() * 4; 79 return gfx::ToFlooredSize(size().Scale(device_scale_factor_)).GetArea() * 4;
78 } 80 }
79 81
80 void BackingStoreAura::PaintToBackingStore( 82 void BackingStoreAura::PaintToBackingStore(
81 RenderProcessHost* process, 83 RenderProcessHost* process,
82 TransportDIB::Id bitmap, 84 TransportDIB::Id bitmap,
83 const gfx::Rect& bitmap_rect, 85 const gfx::Rect& bitmap_rect,
84 const std::vector<gfx::Rect>& copy_rects, 86 const std::vector<gfx::Rect>& copy_rects,
85 float scale_factor, 87 float scale_factor,
86 const base::Closure& completion_callback, 88 const base::Closure& completion_callback,
87 bool* scheduled_completion_callback) { 89 bool* scheduled_completion_callback) {
88 *scheduled_completion_callback = false; 90 *scheduled_completion_callback = false;
89 if (bitmap_rect.IsEmpty()) 91 if (bitmap_rect.IsEmpty())
90 return; 92 return;
91 93
92 gfx::Rect pixel_bitmap_rect = 94 gfx::Rect pixel_bitmap_rect =
93 gfx::ToEnclosingRect(bitmap_rect.Scale(scale_factor)); 95 gfx::ToEnclosedRect(bitmap_rect.Scale(scale_factor));
94 96
95 const int width = pixel_bitmap_rect.width(); 97 const int width = pixel_bitmap_rect.width();
96 const int height = pixel_bitmap_rect.height(); 98 const int height = pixel_bitmap_rect.height();
97 99
98 if (width <= 0 || width > kMaxVideoLayerSize || 100 if (width <= 0 || width > kMaxVideoLayerSize ||
99 height <= 0 || height > kMaxVideoLayerSize) 101 height <= 0 || height > kMaxVideoLayerSize)
100 return; 102 return;
101 103
102 TransportDIB* dib = process->GetTransportDIB(bitmap); 104 TransportDIB* dib = process->GetTransportDIB(bitmap);
103 if (!dib) 105 if (!dib)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); 159 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true);
158 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); 160 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height);
159 SkBitmap b; 161 SkBitmap b;
160 if (!canvas_->readPixels(skrect, &b)) 162 if (!canvas_->readPixels(skrect, &b))
161 return false; 163 return false;
162 output->writePixels(b, rect.x(), rect.y()); 164 output->writePixels(b, rect.x(), rect.y());
163 return true; 165 return true;
164 } 166 }
165 167
166 } // namespace content 168 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698