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

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

Issue 10830072: Browser Plugin: New Implementation (Renderer Side) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed according to comments by creis@. Moved postMessage stuff out for another cl Created 8 years, 4 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
(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 // Max height and width for layers
12 static const int kMaxSize = 23170;
13
14 BrowserPluginBackingStore::BrowserPluginBackingStore(
15 const gfx::Size& size,
16 float scale_factor)
17 : size_(size),
18 scale_factor_(scale_factor) {
19 gfx::Size pixel_size = size.Scale(scale_factor);
20 bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
21 pixel_size.width(), pixel_size.height());
22 bitmap_.allocPixels();
23 canvas_.reset(new SkCanvas(bitmap_));
24 }
25
26 BrowserPluginBackingStore::~BrowserPluginBackingStore() {
27 }
28
29 void BrowserPluginBackingStore::PaintToBackingStore(
30 const gfx::Rect& bitmap_rect,
31 const std::vector<gfx::Rect>& copy_rects,
32 TransportDIB* dib) {
33 if (bitmap_rect.IsEmpty())
34 return;
35
36 gfx::Rect pixel_bitmap_rect = bitmap_rect.Scale(scale_factor_);
37
38 const int width = pixel_bitmap_rect.width();
39 const int height = pixel_bitmap_rect.height();
40
41 if (width <= 0 || width > kMaxSize ||
42 height <= 0 || height > kMaxSize)
43 return;
44
45 if (!dib)
46 return;
47
48 SkPaint copy_paint;
49 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode);
50
51 SkBitmap sk_bitmap;
52 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
53 sk_bitmap.setPixels(dib->memory());
54 for (size_t i = 0; i < copy_rects.size(); i++) {
55 const gfx::Rect& pixel_copy_rect = copy_rects[i].Scale(scale_factor_);
56 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x();
57 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y();
58 SkIRect srcrect = SkIRect::MakeXYWH(x, y,
59 pixel_copy_rect.width(),
60 pixel_copy_rect.height());
61
62 SkRect dstrect = SkRect::MakeXYWH(
63 SkIntToScalar(pixel_copy_rect.x()),
64 SkIntToScalar(pixel_copy_rect.y()),
65 SkIntToScalar(pixel_copy_rect.width()),
66 SkIntToScalar(pixel_copy_rect.height()));
67 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, &copy_paint);
68 }
69 }
70
71 void BrowserPluginBackingStore::ScrollBackingStore(
72 int dx,
73 int dy,
74 const gfx::Rect& clip_rect,
75 const gfx::Size& view_size) {
76 gfx::Rect pixel_rect = clip_rect.Scale(scale_factor_);
77 int pixel_dx = dx * scale_factor_;
78 int pixel_dy = dy * scale_factor_;
79
80 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx);
81 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy);
82 int w = pixel_rect.width() + abs(pixel_dx);
83 int h = pixel_rect.height() + abs(pixel_dy);
84 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h);
85 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy);
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698