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