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

Side by Side Diff: chrome/browser/renderer_host/backing_store_skia.cc

Issue 6246129: BackingStoreSkia: Use skia for painting in RenderWidgetHostViewViews. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Use drawBitmapRect instead of readPixels/writePixels to avoid double-copy Created 9 years, 10 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) 2011 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 "chrome/browser/renderer_host/backing_store_skia.h"
6
7 #include "chrome/browser/renderer_host/render_process_host.h"
8 #include "gfx/canvas.h"
9 #include "gfx/canvas_skia.h"
10 #include "gfx/rect.h"
11 #include "skia/ext/platform_canvas.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13
14 // Assume that somewhere along the line, someone will do width * height * 4
15 // with signed numbers. If the maximum value is 2**31, then 2**31 / 4 =
16 // 2**29 and floor(sqrt(2**29)) = 23170.
17
18 // Max height and width for layers
19 static const int kMaxVideoLayerSize = 23170;
20
21 BackingStoreSkia::BackingStoreSkia(RenderWidgetHost* widget,
22 const gfx::Size& size)
23 : BackingStore(widget, size) {
24 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
25 bitmap_.allocPixels();
26 canvas_.reset(new SkCanvas(bitmap_));
27 }
28
29 BackingStoreSkia::~BackingStoreSkia() {
30 }
31
32 void BackingStoreSkia::SkiaShowRect(const gfx::Point& point,
33 gfx::Canvas* canvas) {
34 canvas->AsCanvasSkia()->drawBitmap(bitmap_,
35 SkIntToScalar(point.x()), SkIntToScalar(point.y()));
36 }
37
38 size_t BackingStoreSkia::MemorySize() {
39 return size().GetArea() * 4;
rjkroege 2011/02/07 21:03:24 My whining about this doesn't apply until you perm
sadrul 2011/02/07 21:31:51 Done.
40 }
41
42 void BackingStoreSkia::PaintToBackingStore(
43 RenderProcessHost* process,
44 TransportDIB::Id bitmap,
45 const gfx::Rect& bitmap_rect,
46 const std::vector<gfx::Rect>& copy_rects) {
47 if (bitmap_rect.IsEmpty())
48 return;
49
50 const int width = bitmap_rect.width();
51 const int height = bitmap_rect.height();
52
53 if (width <= 0 || width > kMaxVideoLayerSize ||
54 height <= 0 || height > kMaxVideoLayerSize)
55 return;
56
57 TransportDIB* dib = process->GetTransportDIB(bitmap);
58 if (!dib)
59 return;
60
61 scoped_ptr<skia::PlatformCanvas> p_canvas(
62 dib->GetPlatformCanvas(width, height));
63 for (size_t i = 0; i < copy_rects.size(); i++) {
64 const gfx::Rect& copy_rect = copy_rects[i];
65 int x = copy_rect.x() - bitmap_rect.x();
66 int y = copy_rect.y() - bitmap_rect.y();
67 int w = copy_rect.width();
68 int h = copy_rect.height();
69 SkIRect srcrect = SkIRect::MakeXYWH(x, y, w, h);
70 SkRect dstrect = SkRect::MakeXYWH(copy_rect.x(), copy_rect.y(), w, h);
71 SkBitmap b = p_canvas->getTopPlatformDevice().accessBitmap(false);
72 canvas_.get()->drawBitmapRect(b, &srcrect, dstrect);
73 }
74 }
75
76 void BackingStoreSkia::ScrollBackingStore(int dx, int dy,
77 const gfx::Rect& clip_rect,
78 const gfx::Size& view_size) {
79 int x = std::min(clip_rect.x(), clip_rect.x() - dx);
80 int y = std::min(clip_rect.y(), clip_rect.y() - dy);
81 int w = clip_rect.width() + abs(dx);
82 int h = clip_rect.height() + abs(dy);
83 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h);
84 bitmap_.scrollRect(&rect, dx, dy);
85 }
86
87 bool BackingStoreSkia::CopyFromBackingStore(const gfx::Rect& rect,
88 skia::PlatformCanvas* output) {
89 const int width = std::min(size().width(), rect.width());
90 const int height = std::min(size().height(), rect.height());
91 if (!output->initialize(width, height, true))
92 return false;
93
94 SkBitmap bitmap = output->getTopPlatformDevice().accessBitmap(true);
95 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height);
96 SkBitmap b;
97 if (!canvas_->readPixels(skrect, &b))
98 return false;
99 output->writePixels(b, rect.x(), rect.y());
100 return true;
101 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/backing_store_skia.h ('k') | chrome/browser/renderer_host/render_widget_host_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698