| Index: skia/ext/recording_platform_device_skia.cc
|
| diff --git a/skia/ext/recording_platform_device_skia.cc b/skia/ext/recording_platform_device_skia.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d319373e2d67f03bc91aed103ab7ecd60538a8da
|
| --- /dev/null
|
| +++ b/skia/ext/recording_platform_device_skia.cc
|
| @@ -0,0 +1,110 @@
|
| +// 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 "skia/ext/recording_platform_device_skia.h"
|
| +
|
| +#include "skia/ext/platform_canvas.h"
|
| +#include "third_party/skia/include/core/SkClipStack.h"
|
| +#include "third_party/skia/include/core/SkDraw.h"
|
| +#include "third_party/skia/include/core/SkPicture.h"
|
| +#include "third_party/skia/include/core/SkRect.h"
|
| +#include "third_party/skia/include/core/SkRegion.h"
|
| +#include "third_party/skia/include/core/SkScalar.h"
|
| +
|
| +namespace skia {
|
| +
|
| +SkDevice* CreateRecordingPlatformDeviceSkia(
|
| + SkPicture* picture, int width, int height) {
|
| + SkBitmap bm;
|
| + bm.setConfig(SkBitmap::kNo_Config, width, height);
|
| + return new RecordingPlatformDeviceSkia(bm, picture);
|
| +}
|
| +
|
| +RecordingPlatformDeviceSkia::RecordingPlatformDeviceSkia(
|
| + const SkBitmap& bitmap, SkPicture* picture)
|
| + : SkDevice(bitmap),
|
| + raster_canvas_(NULL),
|
| + picture_(picture) {
|
| + SetPlatformDevice(this, this);
|
| +}
|
| +
|
| +RecordingPlatformDeviceSkia::~RecordingPlatformDeviceSkia() {
|
| + if (raster_canvas_)
|
| + raster_canvas_->unref();
|
| +}
|
| +
|
| +PlatformDevice::PlatformPaint RecordingPlatformDeviceSkia::
|
| + PlatformPaintSupport() {
|
| + return PLATFORM_PAINT_INDIRECT;
|
| +}
|
| +
|
| +PlatformSurface RecordingPlatformDeviceSkia::BeginPlatformPaint() {
|
| + // Even when recording drawing commands of the page, we have to
|
| + // provide a raster surface for plugins to render into. Therefore we
|
| + // create a BitmapPlatformDevice here and return the context from it,
|
| + // then layer on the raster data as an image in EndPlatformPaint.
|
| + SkASSERT(raster_canvas_ == NULL);
|
| + // TODO(reveman): Need to restrict size of bitmap to the current clip.
|
| + // See http://crbug.com/152011
|
| + raster_canvas_ = CreateBitmapCanvas(width(), height(), false);
|
| +
|
| + // We make a copy so that our original picture_ can continue to record.
|
| + // Normally if you "draw" a picture, that forces its recording to stop.
|
| + SkPicture raster_picture(*picture_);
|
| + raster_canvas_->drawPicture(raster_picture);
|
| + // Save the effect of all currently recorded matrix operations.
|
| + raster_matrix_ = raster_canvas_->getTotalMatrix();
|
| +
|
| + return skia::BeginPlatformPaint(raster_canvas_);
|
| +}
|
| +
|
| +void RecordingPlatformDeviceSkia::EndPlatformPaint() {
|
| + SkASSERT(raster_canvas_ != NULL);
|
| + SkMatrix inverse;
|
| + // To add a drawing command that will render the raster surface at the
|
| + // correct origin we need to revert the effect of all currently
|
| + // recorded matrix operations.
|
| + if (raster_matrix_.invert(&inverse)) {
|
| + SkCanvas* canvas = picture_->getRecordingCanvas();
|
| + SkASSERT(canvas != NULL);
|
| + canvas->save();
|
| + canvas->concat(inverse);
|
| + SkPaint paint;
|
| + paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
| + // TODO(reveman): Need to mark bitmap as being "immutable" before
|
| + // calling drawBitmap to avoid having the picture recording code do
|
| + // a deep-copy of it.
|
| + canvas->drawBitmap(
|
| + raster_canvas_->getDevice()->accessBitmap(false), 0, 0, &paint);
|
| + canvas->restore();
|
| + }
|
| + skia::EndPlatformPaint(raster_canvas_);
|
| + raster_canvas_->unref();
|
| + raster_canvas_ = NULL;
|
| +}
|
| +
|
| +#if defined(OS_WIN)
|
| +void RecordingPlatformDeviceSkia::DrawToNativeContext(
|
| + HDC dc, int x, int y, const RECT* src_rect) {
|
| + SkASSERT(false);
|
| +}
|
| +#elif defined(OS_MACOSX)
|
| +void RecordingPlatformDeviceSkia::DrawToNativeContext(
|
| + CGContext* context, int x, int y, const CGRect* src_rect) {
|
| + SkASSERT(false);
|
| +}
|
| +
|
| +CGContextRef RecordingPlatformDeviceSkia::GetBitmapContext() {
|
| + SkASSERT(false);
|
| + return NULL;
|
| +}
|
| +#elif defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_OPENBSD)
|
| +void RecordingPlatformDeviceSkia::DrawToNativeContext(
|
| + PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
|
| + // Should never be called on Linux.
|
| + SkASSERT(false);
|
| +}
|
| +#endif
|
| +
|
| +} // namespace skia
|
|
|