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

Unified Diff: skia/ext/recording_platform_device_skia.cc

Issue 10915065: Add PlatformPictureSkia and RecordingPlatformDeviceSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add IsPlatformPaintSupported(), update comment in WebPluginDelegateProxy::Paint and require direct … Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
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..d1f6b2ded95324653644c74fcd4f85764a30d2cd
--- /dev/null
+++ b/skia/ext/recording_platform_device_skia.cc
@@ -0,0 +1,125 @@
+// 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 {
+
+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();
+}
+
+RecordingPlatformDeviceSkia* RecordingPlatformDeviceSkia::Create(
+ SkPicture* picture, int width, int height) {
+ SkBitmap bm;
+ bm.setConfig(SkBitmap::kNo_Config, width, height);
+ return new RecordingPlatformDeviceSkia(bm, picture);
+}
+
+PlatformDevice::PlatformPaint RecordingPlatformDeviceSkia::
+ PlatformPaintSupport() {
+ return PLATFORM_PAINT_INDIRECT;
+}
+
+PlatformSurface RecordingPlatformDeviceSkia::BeginPlatformPaint() {
+ SkASSERT(raster_canvas_ == NULL);
+
+ SkCanvas* canvas = picture_->getRecordingCanvas();
+ SkASSERT(canvas != NULL);
+
+ SkIRect clip;
+ if (!canvas->getClipDeviceBounds(&clip)) {
+ raster_canvas_ = CreateBitmapCanvas(1, 1, false);
+ return skia::BeginPlatformPaint(raster_canvas_);
+ }
+
+ // 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.
+ raster_canvas_ = CreateBitmapCanvas(clip.fRight - clip.fLeft,
+ clip.fBottom - clip.fTop,
+ false);
+ raster_canvas_->translate(-clip.fLeft, -clip.fTop);
+
+ // 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);
+
+ return skia::BeginPlatformPaint(raster_canvas_);
+}
+
+void RecordingPlatformDeviceSkia::EndPlatformPaint() {
+ SkASSERT(raster_canvas_ != NULL);
+
+ SkCanvas* canvas = picture_->getRecordingCanvas();
+ SkASSERT(canvas != NULL);
+
+ SkMatrix matrix = canvas->getTotalMatrix();
+ SkMatrix inverse;
+ SkIRect clip;
+ // 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 (canvas->getClipDeviceBounds(&clip) && matrix.invert(&inverse)) {
+ canvas->save();
+ canvas->concat(inverse);
+ canvas->translate(clip.fLeft, clip.fTop);
+ 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

Powered by Google App Engine
This is Rietveld 408576698