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

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: 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(const gfx::Size& size)
15 : size_(size) {
16 bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
17 size.width(), size.height());
18 bitmap_.allocPixels();
19 canvas_.reset(new SkCanvas(bitmap_));
20 }
21
22 BrowserPluginBackingStore::~BrowserPluginBackingStore() {
23 }
24
25 void BrowserPluginBackingStore::PaintToBackingStore(
26 const gfx::Rect& bitmap_rect,
27 const std::vector<gfx::Rect>& copy_rects,
28 TransportDIB* dib) {
29 if (bitmap_rect.IsEmpty())
30 return;
31
32 const int width = bitmap_rect.width();
33 const int height = bitmap_rect.height();
34
35 if (width <= 0 || width > kMaxSize ||
36 height <= 0 || height > kMaxSize)
37 return;
38
39 if (!dib)
40 return;
41
42 SkPaint copy_paint;
43 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode);
44
45 SkBitmap sk_bitmap;
46 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
47 sk_bitmap.setPixels(dib->memory());
48 for (size_t i = 0; i < copy_rects.size(); i++) {
49 const gfx::Rect& copy_rect = copy_rects[i];
50 int x = copy_rect.x() - bitmap_rect.x();
51 int y = copy_rect.y() - bitmap_rect.y();
52 SkIRect srcrect = SkIRect::MakeXYWH(x, y,
53 copy_rect.width(),
54 copy_rect.height());
55
56 const gfx::Rect& copy_dst_rect = copy_rects[i];
57 SkRect dstrect = SkRect::MakeXYWH(
58 SkIntToScalar(copy_dst_rect.x()),
59 SkIntToScalar(copy_dst_rect.y()),
60 SkIntToScalar(copy_dst_rect.width()),
61 SkIntToScalar(copy_dst_rect.height()));
62 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, &copy_paint);
63 }
64 }
65
66 void BrowserPluginBackingStore::ScrollBackingStore(
67 int dx,
68 int dy,
69 const gfx::Rect& clip_rect,
70 const gfx::Size& view_size) {
71 int x = std::min(clip_rect.x(), clip_rect.x() - dx);
72 int y = std::min(clip_rect.y(), clip_rect.y() - dy);
73 int w = clip_rect.width() + abs(dx);
74 int h = clip_rect.height() + abs(dy);
75 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h);
76 bitmap_.scrollRect(&rect, dx, dy);
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698