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

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 "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_, point.x(), point.y());
35 }
36
37 size_t BackingStoreSkia::MemorySize() {
38 return size().GetArea() * 4;
rjkroege 2011/02/07 19:36:40 you are making a presumption about the way that bi
sadrul 2011/02/07 20:55:39 I wasn't exactly sure what to do where. The SkBitm
39 }
40
41 void BackingStoreSkia::PaintToBackingStore(
42 RenderProcessHost* process,
43 TransportDIB::Id bitmap,
44 const gfx::Rect& bitmap_rect,
45 const std::vector<gfx::Rect>& copy_rects) {
46 if (bitmap_rect.IsEmpty())
47 return;
48
49 const int width = bitmap_rect.width();
50 const int height = bitmap_rect.height();
51
52 if (width <= 0 || width > kMaxVideoLayerSize ||
53 height <= 0 || height > kMaxVideoLayerSize)
54 return;
55
56 TransportDIB* dib = process->GetTransportDIB(bitmap);
57 if (!dib)
58 return;
59
60 scoped_ptr<skia::PlatformCanvas> p_canvas(
61 dib->GetPlatformCanvas(width, height));
62 for (size_t i = 0; i < copy_rects.size(); i++) {
63 const gfx::Rect& copy_rect = copy_rects[i];
64 int x = copy_rect.x() - bitmap_rect.x();
65 int y = copy_rect.y() - bitmap_rect.y();
66 int w = copy_rect.width();
67 int h = copy_rect.height();
68 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h);
69 SkBitmap b;
rjkroege 2011/02/07 19:36:40 This looks like a double copy of the bitmap. If so
sadrul 2011/02/07 20:55:39 I changed this to use drawBitmapRect instead of re
70 p_canvas->readPixels(rect, &b);
71 canvas_.get()->writePixels(b, copy_rect.x(), copy_rect.y());
72 }
73 }
74
75 void BackingStoreSkia::ScrollBackingStore(int dx, int dy,
76 const gfx::Rect& clip_rect,
77 const gfx::Size& view_size) {
78 int x = std::min(clip_rect.x(), clip_rect.x() - dx);
79 int y = std::min(clip_rect.y(), clip_rect.y() - dy);
80 int w = clip_rect.width() + abs(dx);
81 int h = clip_rect.height() + abs(dy);
82 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h);
83 bitmap_.scrollRect(&rect, dx, dy);
84 }
85
86 bool BackingStoreSkia::CopyFromBackingStore(const gfx::Rect& rect,
87 skia::PlatformCanvas* output) {
88 const int width = std::min(size().width(), rect.width());
89 const int height = std::min(size().height(), rect.height());
90 if (!output->initialize(width, height, true))
91 return false;
92
93 SkBitmap bitmap = output->getTopPlatformDevice().accessBitmap(true);
94 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height);
95 SkBitmap b;
96 if (!canvas_->readPixels(skrect, &b))
97 return false;
98 output->writePixels(b, rect.x(), rect.y());
99 return true;
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698