OLD | NEW |
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/gfx/rect_conversions.h" |
10 #include "ui/gfx/size_conversions.h" | 10 #include "ui/gfx/size_conversions.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 BrowserPluginBackingStore::~BrowserPluginBackingStore() { | 30 BrowserPluginBackingStore::~BrowserPluginBackingStore() { |
31 } | 31 } |
32 | 32 |
33 void BrowserPluginBackingStore::PaintToBackingStore( | 33 void BrowserPluginBackingStore::PaintToBackingStore( |
34 const gfx::Rect& bitmap_rect, | 34 const gfx::Rect& bitmap_rect, |
35 const std::vector<gfx::Rect>& copy_rects, | 35 const std::vector<gfx::Rect>& copy_rects, |
36 TransportDIB* dib) { | 36 TransportDIB* dib) { |
37 if (bitmap_rect.IsEmpty()) | 37 if (bitmap_rect.IsEmpty()) |
38 return; | 38 return; |
39 | 39 |
40 gfx::RectF scaled_bitmap_rect = bitmap_rect; | 40 gfx::Rect pixel_bitmap_rect = gfx::ToFlooredRectDeprecated( |
41 scaled_bitmap_rect.Scale(scale_factor_); | 41 gfx::ScaleRect(bitmap_rect, scale_factor_)); |
42 gfx::Rect pixel_bitmap_rect = | |
43 gfx::ToFlooredRectDeprecated(scaled_bitmap_rect); | |
44 | 42 |
45 const int width = pixel_bitmap_rect.width(); | 43 const int width = pixel_bitmap_rect.width(); |
46 const int height = pixel_bitmap_rect.height(); | 44 const int height = pixel_bitmap_rect.height(); |
47 | 45 |
48 if (width <= 0 || width > kMaxSize || | 46 if (width <= 0 || width > kMaxSize || |
49 height <= 0 || height > kMaxSize) | 47 height <= 0 || height > kMaxSize) |
50 return; | 48 return; |
51 | 49 |
52 if (!dib) | 50 if (!dib) |
53 return; | 51 return; |
54 | 52 |
55 SkPaint copy_paint; | 53 SkPaint copy_paint; |
56 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 54 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
57 | 55 |
58 SkBitmap sk_bitmap; | 56 SkBitmap sk_bitmap; |
59 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 57 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
60 sk_bitmap.setPixels(dib->memory()); | 58 sk_bitmap.setPixels(dib->memory()); |
61 for (size_t i = 0; i < copy_rects.size(); i++) { | 59 for (size_t i = 0; i < copy_rects.size(); i++) { |
62 gfx::RectF scaled_copy_rect = copy_rects[i]; | 60 const gfx::Rect& pixel_copy_rect = gfx::ToEnclosingRect( |
63 scaled_copy_rect.Scale(scale_factor_); | 61 gfx::ScaleRect(copy_rects[i], scale_factor_)); |
64 const gfx::Rect& pixel_copy_rect = gfx::ToEnclosingRect(scaled_copy_rect); | |
65 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x(); | 62 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x(); |
66 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y(); | 63 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y(); |
67 SkIRect srcrect = SkIRect::MakeXYWH(x, y, | 64 SkIRect srcrect = SkIRect::MakeXYWH(x, y, |
68 pixel_copy_rect.width(), | 65 pixel_copy_rect.width(), |
69 pixel_copy_rect.height()); | 66 pixel_copy_rect.height()); |
70 | 67 |
71 SkRect dstrect = SkRect::MakeXYWH( | 68 SkRect dstrect = SkRect::MakeXYWH( |
72 SkIntToScalar(pixel_copy_rect.x()), | 69 SkIntToScalar(pixel_copy_rect.x()), |
73 SkIntToScalar(pixel_copy_rect.y()), | 70 SkIntToScalar(pixel_copy_rect.y()), |
74 SkIntToScalar(pixel_copy_rect.width()), | 71 SkIntToScalar(pixel_copy_rect.width()), |
75 SkIntToScalar(pixel_copy_rect.height())); | 72 SkIntToScalar(pixel_copy_rect.height())); |
76 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, ©_paint); | 73 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, ©_paint); |
77 } | 74 } |
78 } | 75 } |
79 | 76 |
80 void BrowserPluginBackingStore::ScrollBackingStore( | 77 void BrowserPluginBackingStore::ScrollBackingStore( |
81 int dx, | 78 int dx, |
82 int dy, | 79 int dy, |
83 const gfx::Rect& clip_rect, | 80 const gfx::Rect& clip_rect, |
84 const gfx::Size& view_size) { | 81 const gfx::Size& view_size) { |
85 gfx::RectF scaled_clip_rect = clip_rect; | 82 gfx::Rect pixel_rect = gfx::ToEnclosingRect( |
86 scaled_clip_rect.Scale(scale_factor_); | 83 gfx::ScaleRect(clip_rect, scale_factor_)); |
87 gfx::Rect pixel_rect = gfx::ToEnclosingRect(scaled_clip_rect); | |
88 int pixel_dx = dx * scale_factor_; | 84 int pixel_dx = dx * scale_factor_; |
89 int pixel_dy = dy * scale_factor_; | 85 int pixel_dy = dy * scale_factor_; |
90 | 86 |
91 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx); | 87 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx); |
92 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy); | 88 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy); |
93 int w = pixel_rect.width() + abs(pixel_dx); | 89 int w = pixel_rect.width() + abs(pixel_dx); |
94 int h = pixel_rect.height() + abs(pixel_dy); | 90 int h = pixel_rect.height() + abs(pixel_dy); |
95 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); | 91 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); |
96 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy); | 92 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy); |
97 } | 93 } |
98 | 94 |
99 } // namespace content | 95 } // namespace content |
OLD | NEW |