OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/browser_plugin/browser_plugin_backing_store.h" |
| 6 |
| 7 #include "ui/gfx/canvas.h" |
| 8 #include "ui/gfx/rect.h" |
| 9 #include "ui/surface/transport_dib.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 // Max height and width for layers |
| 14 static const int kMaxSize = 23170; |
| 15 |
| 16 BrowserPluginBackingStore::BrowserPluginBackingStore( |
| 17 const gfx::Size& size, |
| 18 float scale_factor) |
| 19 : size_(size), |
| 20 scale_factor_(scale_factor) { |
| 21 gfx::Size pixel_size = size.Scale(scale_factor); |
| 22 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, |
| 23 pixel_size.width(), pixel_size.height()); |
| 24 bitmap_.allocPixels(); |
| 25 canvas_.reset(new SkCanvas(bitmap_)); |
| 26 } |
| 27 |
| 28 BrowserPluginBackingStore::~BrowserPluginBackingStore() { |
| 29 } |
| 30 |
| 31 void BrowserPluginBackingStore::PaintToBackingStore( |
| 32 const gfx::Rect& bitmap_rect, |
| 33 const std::vector<gfx::Rect>& copy_rects, |
| 34 TransportDIB* dib) { |
| 35 if (bitmap_rect.IsEmpty()) |
| 36 return; |
| 37 |
| 38 gfx::Rect pixel_bitmap_rect = bitmap_rect.Scale(scale_factor_); |
| 39 |
| 40 const int width = pixel_bitmap_rect.width(); |
| 41 const int height = pixel_bitmap_rect.height(); |
| 42 |
| 43 if (width <= 0 || width > kMaxSize || |
| 44 height <= 0 || height > kMaxSize) |
| 45 return; |
| 46 |
| 47 if (!dib) |
| 48 return; |
| 49 |
| 50 SkPaint copy_paint; |
| 51 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 52 |
| 53 SkBitmap sk_bitmap; |
| 54 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 55 sk_bitmap.setPixels(dib->memory()); |
| 56 for (size_t i = 0; i < copy_rects.size(); i++) { |
| 57 const gfx::Rect& pixel_copy_rect = copy_rects[i].Scale(scale_factor_); |
| 58 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x(); |
| 59 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y(); |
| 60 SkIRect srcrect = SkIRect::MakeXYWH(x, y, |
| 61 pixel_copy_rect.width(), |
| 62 pixel_copy_rect.height()); |
| 63 |
| 64 SkRect dstrect = SkRect::MakeXYWH( |
| 65 SkIntToScalar(pixel_copy_rect.x()), |
| 66 SkIntToScalar(pixel_copy_rect.y()), |
| 67 SkIntToScalar(pixel_copy_rect.width()), |
| 68 SkIntToScalar(pixel_copy_rect.height())); |
| 69 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, ©_paint); |
| 70 } |
| 71 } |
| 72 |
| 73 void BrowserPluginBackingStore::ScrollBackingStore( |
| 74 int dx, |
| 75 int dy, |
| 76 const gfx::Rect& clip_rect, |
| 77 const gfx::Size& view_size) { |
| 78 gfx::Rect pixel_rect = clip_rect.Scale(scale_factor_); |
| 79 int pixel_dx = dx * scale_factor_; |
| 80 int pixel_dy = dy * scale_factor_; |
| 81 |
| 82 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); |
| 84 int w = pixel_rect.width() + abs(pixel_dx); |
| 85 int h = pixel_rect.height() + abs(pixel_dy); |
| 86 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); |
| 87 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy); |
| 88 } |
| 89 |
| 90 } // namespace content |
OLD | NEW |