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

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

Issue 12389084: Fix Aura backing store to work with non-integer scale factors. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge with trunk Created 7 years, 9 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
« no previous file with comments | « content/browser/renderer_host/backing_store_aura.h ('k') | no next file » | 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 #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 #include "ui/gfx/size_conversions.h"
17 #include "ui/gfx/vector2d_conversions.h" 17 #include "ui/gfx/vector2d_conversions.h"
18 18
19 namespace {
20
21 gfx::Size ToPixelSize(gfx::Size dipSize, float scale) {
22 return gfx::ToCeiledSize(gfx::ScaleSize(dipSize, scale));
23 }
24
25 } // namespace
26
27
19 namespace content { 28 namespace content {
20 29
21 // Assume that somewhere along the line, someone will do width * height * 4 30 // Assume that somewhere along the line, someone will do width * height * 4
22 // with signed numbers. If the maximum value is 2**31, then 2**31 / 4 = 31 // with signed numbers. If the maximum value is 2**31, then 2**31 / 4 =
23 // 2**29 and floor(sqrt(2**29)) = 23170. 32 // 2**29 and floor(sqrt(2**29)) = 23170.
24 33
25 // Max height and width for layers 34 // Max height and width for layers
26 static const int kMaxVideoLayerSize = 23170; 35 static const int kMaxVideoLayerSize = 23170;
27 36
28 BackingStoreAura::BackingStoreAura(RenderWidgetHost* widget, 37 BackingStoreAura::BackingStoreAura(RenderWidgetHost* widget,
29 const gfx::Size& size) 38 const gfx::Size& size)
30 : BackingStore(widget, size) { 39 : BackingStore(widget, size) {
31 device_scale_factor_ = 40 device_scale_factor_ =
32 ui::GetScaleFactorScale(GetScaleFactorForView(widget->GetView())); 41 ui::GetScaleFactorScale(GetScaleFactorForView(widget->GetView()));
33 gfx::Size pixel_size = gfx::ToFlooredSize( 42 gfx::Size pixel_size = ToPixelSize(size, device_scale_factor_);
34 gfx::ScaleSize(size, device_scale_factor_));
35 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, 43 bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
36 pixel_size.width(), pixel_size.height()); 44 pixel_size.width(), pixel_size.height());
37 bitmap_.allocPixels(); 45 bitmap_.allocPixels();
38 canvas_.reset(new SkCanvas(bitmap_)); 46 canvas_.reset(new SkCanvas(bitmap_));
39 } 47 }
40 48
41 BackingStoreAura::~BackingStoreAura() { 49 BackingStoreAura::~BackingStoreAura() {
42 } 50 }
43 51
44 void BackingStoreAura::SkiaShowRect(const gfx::Point& point, 52 void BackingStoreAura::SkiaShowRect(const gfx::Point& point,
45 gfx::Canvas* canvas) { 53 gfx::Canvas* canvas) {
46 gfx::ImageSkia image = gfx::ImageSkia(gfx::ImageSkiaRep(bitmap_, 54 gfx::ImageSkia image = gfx::ImageSkia(gfx::ImageSkiaRep(bitmap_,
47 ui::GetScaleFactorFromScale(device_scale_factor_))); 55 ui::GetScaleFactorFromScale(device_scale_factor_)));
48 canvas->DrawImageInt(image, point.x(), point.y()); 56 canvas->DrawImageInt(image, point.x(), point.y());
49 } 57 }
50 58
51 void BackingStoreAura::ScaleFactorChanged(float device_scale_factor) { 59 void BackingStoreAura::ScaleFactorChanged(float device_scale_factor) {
52 if (device_scale_factor == device_scale_factor_) 60 if (device_scale_factor == device_scale_factor_)
53 return; 61 return;
54 62
55 gfx::Size old_pixel_size = gfx::ToFlooredSize( 63 gfx::Size old_pixel_size = ToPixelSize(size(), device_scale_factor_);
56 gfx::ScaleSize(size(), device_scale_factor_));
57 device_scale_factor_ = device_scale_factor; 64 device_scale_factor_ = device_scale_factor;
58 65
59 gfx::Size pixel_size = gfx::ToFlooredSize( 66 gfx::Size pixel_size = ToPixelSize(size(), device_scale_factor_);
60 gfx::ScaleSize(size(), device_scale_factor_));
61 SkBitmap new_bitmap; 67 SkBitmap new_bitmap;
62 new_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 68 new_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
63 pixel_size.width(), pixel_size.height()); 69 pixel_size.width(), pixel_size.height());
64 new_bitmap.allocPixels(); 70 new_bitmap.allocPixels();
65 scoped_ptr<SkCanvas> new_canvas(new SkCanvas(new_bitmap)); 71 scoped_ptr<SkCanvas> new_canvas(new SkCanvas(new_bitmap));
66 72
67 // Copy old contents; a low-res flash is better than a black flash. 73 // Copy old contents; a low-res flash is better than a black flash.
68 SkPaint copy_paint; 74 SkPaint copy_paint;
69 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); 75 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode);
70 SkIRect src_rect = SkIRect::MakeWH(old_pixel_size.width(), 76 SkIRect src_rect = SkIRect::MakeWH(old_pixel_size.width(),
71 old_pixel_size.height()); 77 old_pixel_size.height());
72 SkRect dst_rect = SkRect::MakeWH(pixel_size.width(), pixel_size.height()); 78 SkRect dst_rect = SkRect::MakeWH(pixel_size.width(), pixel_size.height());
73 new_canvas.get()->drawBitmapRect(bitmap_, &src_rect, dst_rect, &copy_paint); 79 new_canvas.get()->drawBitmapRect(bitmap_, &src_rect, dst_rect, &copy_paint);
74 80
75 canvas_.swap(new_canvas); 81 canvas_.swap(new_canvas);
76 bitmap_ = new_bitmap; 82 bitmap_ = new_bitmap;
77 } 83 }
78 84
79 size_t BackingStoreAura::MemorySize() { 85 size_t BackingStoreAura::MemorySize() {
80 // NOTE: The computation may be different when the canvas is a subrectangle of 86 // NOTE: The computation may be different when the canvas is a subrectangle of
81 // a larger bitmap. 87 // a larger bitmap.
82 return gfx::ToFlooredSize( 88 return ToPixelSize(size(), device_scale_factor_).GetArea() * 4;
83 gfx::ScaleSize(size(), device_scale_factor_)).GetArea() * 4;
84 } 89 }
85 90
86 void BackingStoreAura::PaintToBackingStore( 91 void BackingStoreAura::PaintToBackingStore(
87 RenderProcessHost* process, 92 RenderProcessHost* process,
88 TransportDIB::Id bitmap, 93 TransportDIB::Id bitmap,
89 const gfx::Rect& bitmap_rect, 94 const gfx::Rect& bitmap_rect,
90 const std::vector<gfx::Rect>& copy_rects, 95 const std::vector<gfx::Rect>& copy_rects,
91 float scale_factor, 96 float scale_factor,
92 const base::Closure& completion_callback, 97 const base::Closure& completion_callback,
93 bool* scheduled_completion_callback) { 98 bool* scheduled_completion_callback) {
94 *scheduled_completion_callback = false; 99 *scheduled_completion_callback = false;
95 if (bitmap_rect.IsEmpty()) 100 if (bitmap_rect.IsEmpty())
96 return; 101 return;
97 102
98 gfx::Rect pixel_bitmap_rect = gfx::ToEnclosedRect( 103 gfx::Rect pixel_bitmap_rect = gfx::ToEnclosingRect(
99 gfx::ScaleRect(bitmap_rect, scale_factor)); 104 gfx::ScaleRect(bitmap_rect, scale_factor));
100 105
101 const int width = pixel_bitmap_rect.width(); 106 const int width = pixel_bitmap_rect.width();
102 const int height = pixel_bitmap_rect.height(); 107 const int height = pixel_bitmap_rect.height();
103 108
104 if (width <= 0 || width > kMaxVideoLayerSize || 109 if (width <= 0 || width > kMaxVideoLayerSize ||
105 height <= 0 || height > kMaxVideoLayerSize) 110 height <= 0 || height > kMaxVideoLayerSize)
106 return; 111 return;
107 112
108 TransportDIB* dib = process->GetTransportDIB(bitmap); 113 TransportDIB* dib = process->GetTransportDIB(bitmap);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 167
163 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); 168 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height);
164 SkBitmap b; 169 SkBitmap b;
165 if (!canvas_->readPixels(skrect, &b)) 170 if (!canvas_->readPixels(skrect, &b))
166 return false; 171 return false;
167 SkCanvas(output->GetBitmap()).writePixels(b, rect.x(), rect.y()); 172 SkCanvas(output->GetBitmap()).writePixels(b, rect.x(), rect.y());
168 return true; 173 return true;
169 } 174 }
170 175
171 } // namespace content 176 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/backing_store_aura.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698