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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_backing_store.cc

Issue 10996037: Do not convert from RectF to Rect by flooring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing mac build. 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/renderer/browser_plugin/browser_plugin_backing_store.h" 5 #include "content/renderer/browser_plugin/browser_plugin_backing_store.h"
6 6
7 #include "ui/gfx/canvas.h" 7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/rect.h" 8 #include "ui/gfx/rect.h"
9 #include "ui/gfx/rect_conversions.h"
9 #include "ui/surface/transport_dib.h" 10 #include "ui/surface/transport_dib.h"
10 11
11 namespace content { 12 namespace content {
12 13
13 // Max height and width for layers 14 // Max height and width for layers
14 static const int kMaxSize = 23170; 15 static const int kMaxSize = 23170;
15 16
16 BrowserPluginBackingStore::BrowserPluginBackingStore( 17 BrowserPluginBackingStore::BrowserPluginBackingStore(
17 const gfx::Size& size, 18 const gfx::Size& size,
18 float scale_factor) 19 float scale_factor)
19 : size_(size), 20 : size_(size),
20 scale_factor_(scale_factor) { 21 scale_factor_(scale_factor) {
21 gfx::Size pixel_size = size.Scale(scale_factor); 22 gfx::Size pixel_size = size.Scale(scale_factor);
22 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, 23 bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
23 pixel_size.width(), pixel_size.height()); 24 pixel_size.width(), pixel_size.height());
24 bitmap_.allocPixels(); 25 bitmap_.allocPixels();
25 canvas_.reset(new SkCanvas(bitmap_)); 26 canvas_.reset(new SkCanvas(bitmap_));
26 } 27 }
27 28
28 BrowserPluginBackingStore::~BrowserPluginBackingStore() { 29 BrowserPluginBackingStore::~BrowserPluginBackingStore() {
29 } 30 }
30 31
31 void BrowserPluginBackingStore::PaintToBackingStore( 32 void BrowserPluginBackingStore::PaintToBackingStore(
32 const gfx::Rect& bitmap_rect, 33 const gfx::Rect& bitmap_rect,
33 const std::vector<gfx::Rect>& copy_rects, 34 const std::vector<gfx::Rect>& copy_rects,
34 TransportDIB* dib) { 35 TransportDIB* dib) {
35 if (bitmap_rect.IsEmpty()) 36 if (bitmap_rect.IsEmpty())
36 return; 37 return;
37 38
38 gfx::Rect pixel_bitmap_rect = bitmap_rect.Scale(scale_factor_); 39 gfx::Rect pixel_bitmap_rect =
40 gfx::ToEnclosingRect(bitmap_rect.Scale(scale_factor_));
39 41
40 const int width = pixel_bitmap_rect.width(); 42 const int width = pixel_bitmap_rect.width();
41 const int height = pixel_bitmap_rect.height(); 43 const int height = pixel_bitmap_rect.height();
42 44
43 if (width <= 0 || width > kMaxSize || 45 if (width <= 0 || width > kMaxSize ||
44 height <= 0 || height > kMaxSize) 46 height <= 0 || height > kMaxSize)
45 return; 47 return;
46 48
47 if (!dib) 49 if (!dib)
48 return; 50 return;
49 51
50 SkPaint copy_paint; 52 SkPaint copy_paint;
51 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); 53 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode);
52 54
53 SkBitmap sk_bitmap; 55 SkBitmap sk_bitmap;
54 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 56 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
55 sk_bitmap.setPixels(dib->memory()); 57 sk_bitmap.setPixels(dib->memory());
56 for (size_t i = 0; i < copy_rects.size(); i++) { 58 for (size_t i = 0; i < copy_rects.size(); i++) {
57 const gfx::Rect& pixel_copy_rect = copy_rects[i].Scale(scale_factor_); 59 const gfx::Rect& pixel_copy_rect =
60 gfx::ToEnclosingRect(copy_rects[i].Scale(scale_factor_));
58 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x(); 61 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x();
59 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y(); 62 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y();
60 SkIRect srcrect = SkIRect::MakeXYWH(x, y, 63 SkIRect srcrect = SkIRect::MakeXYWH(x, y,
61 pixel_copy_rect.width(), 64 pixel_copy_rect.width(),
62 pixel_copy_rect.height()); 65 pixel_copy_rect.height());
63 66
64 SkRect dstrect = SkRect::MakeXYWH( 67 SkRect dstrect = SkRect::MakeXYWH(
65 SkIntToScalar(pixel_copy_rect.x()), 68 SkIntToScalar(pixel_copy_rect.x()),
66 SkIntToScalar(pixel_copy_rect.y()), 69 SkIntToScalar(pixel_copy_rect.y()),
67 SkIntToScalar(pixel_copy_rect.width()), 70 SkIntToScalar(pixel_copy_rect.width()),
68 SkIntToScalar(pixel_copy_rect.height())); 71 SkIntToScalar(pixel_copy_rect.height()));
69 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, &copy_paint); 72 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, &copy_paint);
70 } 73 }
71 } 74 }
72 75
73 void BrowserPluginBackingStore::ScrollBackingStore( 76 void BrowserPluginBackingStore::ScrollBackingStore(
74 int dx, 77 int dx,
75 int dy, 78 int dy,
76 const gfx::Rect& clip_rect, 79 const gfx::Rect& clip_rect,
77 const gfx::Size& view_size) { 80 const gfx::Size& view_size) {
78 gfx::Rect pixel_rect = clip_rect.Scale(scale_factor_); 81 gfx::Rect pixel_rect = gfx::ToEnclosingRect(clip_rect.Scale(scale_factor_));
79 int pixel_dx = dx * scale_factor_; 82 int pixel_dx = dx * scale_factor_;
80 int pixel_dy = dy * scale_factor_; 83 int pixel_dy = dy * scale_factor_;
81 84
82 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx); 85 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx);
83 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy); 86 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy);
84 int w = pixel_rect.width() + abs(pixel_dx); 87 int w = pixel_rect.width() + abs(pixel_dx);
85 int h = pixel_rect.height() + abs(pixel_dy); 88 int h = pixel_rect.height() + abs(pixel_dy);
86 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); 89 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h);
87 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy); 90 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy);
88 } 91 }
89 92
90 } // namespace content 93 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.mm ('k') | content/renderer/render_widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698