| Index: content/renderer/browser_plugin/browser_plugin_backing_store.cc
|
| diff --git a/content/renderer/browser_plugin/browser_plugin_backing_store.cc b/content/renderer/browser_plugin/browser_plugin_backing_store.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2cb5aafd9f1f502d46c4af2ec8dd0f19adbbb243
|
| --- /dev/null
|
| +++ b/content/renderer/browser_plugin/browser_plugin_backing_store.cc
|
| @@ -0,0 +1,77 @@
|
| +// Copyright (c) 2012 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 "content/renderer/browser_plugin/browser_plugin_backing_store.h"
|
| +
|
| +#include "ui/gfx/canvas.h"
|
| +#include "ui/gfx/rect.h"
|
| +#include "ui/surface/transport_dib.h"
|
| +
|
| +// Max height and width for layers
|
| +static const int kMaxVideoLayerSize = 23170;
|
| +
|
| +BrowserPluginBackingStore::BrowserPluginBackingStore(const gfx::Size& size)
|
| + : size_(size) {
|
| + bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
|
| + size.width(), size.height());
|
| + bitmap_.allocPixels();
|
| + canvas_.reset(new SkCanvas(bitmap_));
|
| +}
|
| +
|
| +BrowserPluginBackingStore::~BrowserPluginBackingStore() {
|
| +}
|
| +
|
| +void BrowserPluginBackingStore::PaintToBackingStore(
|
| + const gfx::Rect& bitmap_rect,
|
| + const std::vector<gfx::Rect>& copy_rects,
|
| + TransportDIB* dib) {
|
| + 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;
|
| +
|
| + if (!dib)
|
| + return;
|
| +
|
| + SkPaint copy_paint;
|
| + copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
| +
|
| + SkBitmap sk_bitmap;
|
| + sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
|
| + sk_bitmap.setPixels(dib->memory());
|
| + 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();
|
| + SkIRect srcrect = SkIRect::MakeXYWH(x, y,
|
| + copy_rect.width(),
|
| + copy_rect.height());
|
| +
|
| + const gfx::Rect& copy_dst_rect = copy_rects[i];
|
| + SkRect dstrect = SkRect::MakeXYWH(
|
| + SkIntToScalar(copy_dst_rect.x()),
|
| + SkIntToScalar(copy_dst_rect.y()),
|
| + SkIntToScalar(copy_dst_rect.width()),
|
| + SkIntToScalar(copy_dst_rect.height()));
|
| + canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, ©_paint);
|
| + }
|
| +}
|
| +
|
| +void BrowserPluginBackingStore::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);
|
| +}
|
|
|