Chromium Code Reviews| Index: chrome/browser/renderer_host/backing_store_skia.cc |
| diff --git a/chrome/browser/renderer_host/backing_store_skia.cc b/chrome/browser/renderer_host/backing_store_skia.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ab20b939e13aec7ce3fd523f6d56b4f7a6c4797a |
| --- /dev/null |
| +++ b/chrome/browser/renderer_host/backing_store_skia.cc |
| @@ -0,0 +1,100 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/renderer_host/backing_store_skia.h" |
| + |
| +#include "chrome/browser/renderer_host/render_process_host.h" |
| +#include "gfx/canvas.h" |
| +#include "gfx/canvas_skia.h" |
| +#include "gfx/rect.h" |
| +#include "skia/ext/platform_canvas.h" |
| +#include "third_party/skia/include/core/SkCanvas.h" |
| + |
| +// Assume that somewhere along the line, someone will do width * height * 4 |
| +// with signed numbers. If the maximum value is 2**31, then 2**31 / 4 = |
| +// 2**29 and floor(sqrt(2**29)) = 23170. |
| + |
| +// Max height and width for layers |
| +static const int kMaxVideoLayerSize = 23170; |
| + |
| +BackingStoreSkia::BackingStoreSkia(RenderWidgetHost* widget, |
| + const gfx::Size& size) |
| + : BackingStore(widget, size) { |
| + bitmap_.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
| + bitmap_.allocPixels(); |
| + canvas_.reset(new SkCanvas(bitmap_)); |
| +} |
| + |
| +BackingStoreSkia::~BackingStoreSkia() { |
| +} |
| + |
| +void BackingStoreSkia::SkiaShowRect(const gfx::Point& point, |
| + gfx::Canvas* canvas) { |
| + canvas->AsCanvasSkia()->drawBitmap(bitmap_, point.x(), point.y()); |
| +} |
| + |
| +size_t BackingStoreSkia::MemorySize() { |
| + 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
|
| +} |
| + |
| +void BackingStoreSkia::PaintToBackingStore( |
| + RenderProcessHost* process, |
| + TransportDIB::Id bitmap, |
| + const gfx::Rect& bitmap_rect, |
| + const std::vector<gfx::Rect>& copy_rects) { |
| + if (bitmap_rect.IsEmpty()) |
| + return; |
| + |
| + const int width = bitmap_rect.width(); |
| + const int height = bitmap_rect.height(); |
| + |
| + if (width <= 0 || width > kMaxVideoLayerSize || |
| + height <= 0 || height > kMaxVideoLayerSize) |
| + return; |
| + |
| + TransportDIB* dib = process->GetTransportDIB(bitmap); |
| + if (!dib) |
| + return; |
| + |
| + scoped_ptr<skia::PlatformCanvas> p_canvas( |
| + dib->GetPlatformCanvas(width, height)); |
| + for (size_t i = 0; i < copy_rects.size(); i++) { |
| + const gfx::Rect& copy_rect = copy_rects[i]; |
| + int x = copy_rect.x() - bitmap_rect.x(); |
| + int y = copy_rect.y() - bitmap_rect.y(); |
| + int w = copy_rect.width(); |
| + int h = copy_rect.height(); |
| + SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); |
| + 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
|
| + p_canvas->readPixels(rect, &b); |
| + canvas_.get()->writePixels(b, copy_rect.x(), copy_rect.y()); |
| + } |
| +} |
| + |
| +void BackingStoreSkia::ScrollBackingStore(int dx, int dy, |
| + const gfx::Rect& clip_rect, |
| + const gfx::Size& view_size) { |
| + int x = std::min(clip_rect.x(), clip_rect.x() - dx); |
| + int y = std::min(clip_rect.y(), clip_rect.y() - dy); |
| + int w = clip_rect.width() + abs(dx); |
| + int h = clip_rect.height() + abs(dy); |
| + SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); |
| + bitmap_.scrollRect(&rect, dx, dy); |
| +} |
| + |
| +bool BackingStoreSkia::CopyFromBackingStore(const gfx::Rect& rect, |
| + skia::PlatformCanvas* output) { |
| + const int width = std::min(size().width(), rect.width()); |
| + const int height = std::min(size().height(), rect.height()); |
| + if (!output->initialize(width, height, true)) |
| + return false; |
| + |
| + SkBitmap bitmap = output->getTopPlatformDevice().accessBitmap(true); |
| + SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); |
| + SkBitmap b; |
| + if (!canvas_->readPixels(skrect, &b)) |
| + return false; |
| + output->writePixels(b, rect.x(), rect.y()); |
| + return true; |
| +} |