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