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

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: '' 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 "skia/ext/platform_canvas.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/canvas_skia.h"
12 #include "ui/gfx/rect.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 // NOTE: The computation may be different when the canvas is a subrectangle of
40 // a larger bitmap.
41 return size().GetArea() * 4;
42 }
43
44 void BackingStoreSkia::PaintToBackingStore(
45 RenderProcessHost* process,
46 TransportDIB::Id bitmap,
47 const gfx::Rect& bitmap_rect,
48 const std::vector<gfx::Rect>& copy_rects) {
49 if (bitmap_rect.IsEmpty())
50 return;
51
52 const int width = bitmap_rect.width();
53 const int height = bitmap_rect.height();
54
55 if (width <= 0 || width > kMaxVideoLayerSize ||
56 height <= 0 || height > kMaxVideoLayerSize)
57 return;
58
59 TransportDIB* dib = process->GetTransportDIB(bitmap);
60 if (!dib)
61 return;
62
63 scoped_ptr<skia::PlatformCanvas> p_canvas(
64 dib->GetPlatformCanvas(width, height));
65 for (size_t i = 0; i < copy_rects.size(); i++) {
66 const gfx::Rect& copy_rect = copy_rects[i];
67 int x = copy_rect.x() - bitmap_rect.x();
68 int y = copy_rect.y() - bitmap_rect.y();
69 int w = copy_rect.width();
70 int h = copy_rect.height();
71 SkIRect srcrect = SkIRect::MakeXYWH(x, y, w, h);
72 SkRect dstrect = SkRect::MakeXYWH(
73 SkIntToScalar(copy_rect.x()), SkIntToScalar(copy_rect.y()),
74 SkIntToScalar(w), SkIntToScalar(h));
75 SkBitmap b = p_canvas->getTopPlatformDevice().accessBitmap(false);
76 canvas_.get()->drawBitmapRect(b, &srcrect, dstrect);
77 }
78 }
79
80 void BackingStoreSkia::ScrollBackingStore(int dx, int dy,
81 const gfx::Rect& clip_rect,
82 const gfx::Size& view_size) {
83 int x = std::min(clip_rect.x(), clip_rect.x() - dx);
84 int y = std::min(clip_rect.y(), clip_rect.y() - dy);
85 int w = clip_rect.width() + abs(dx);
86 int h = clip_rect.height() + abs(dy);
87 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h);
88 bitmap_.scrollRect(&rect, dx, dy);
89 }
90
91 bool BackingStoreSkia::CopyFromBackingStore(const gfx::Rect& rect,
92 skia::PlatformCanvas* output) {
93 const int width = std::min(size().width(), rect.width());
94 const int height = std::min(size().height(), rect.height());
95 if (!output->initialize(width, height, true))
96 return false;
97
98 SkBitmap bitmap = output->getTopPlatformDevice().accessBitmap(true);
99 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height);
100 SkBitmap b;
101 if (!canvas_->readPixels(skrect, &b))
102 return false;
103 output->writePixels(b, rect.x(), rect.y());
104 return true;
105 }
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