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

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: Minor style changes and move skia include to .cpp file. 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..42005d5eb8f2674b4ed4ecfa77f0a7f49470e59a
--- /dev/null
+++ b/skia/ext/recording_platform_device_skia.cc
@@ -0,0 +1,105 @@
+// 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),
+ picture_(picture) {
+ SetPlatformDevice(this, this);
+}
+
+RecordingPlatformDeviceSkia::~RecordingPlatformDeviceSkia() {
+}
+
+bool RecordingPlatformDeviceSkia::IsNativeFontRenderingAllowed() {
+ return false;
+}
+
+bool RecordingPlatformDeviceSkia::IsNativeRenderingAllowed() {
+ return true;
+}
+
+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);
+ raster_canvas_ = CreateBitmapCanvas(width(), height(), false);
+ raster_canvas_->unref(); // SkRefPtr and create both took a reference.
+
+ // Copy picture and playback to raster surface.
reed1 2012/09/17 16:51:24 Why do you need to make a copy of the picture?
reveman 2012/09/17 21:22:16 Is there another way to playback a SkPicture witho
+ 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_.get());
+}
+
+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.
reed1 2012/09/17 16:51:24 If you're done with the raster after this call, it
reveman 2012/09/17 21:22:16 Ah, thanks for pointing this out! It would be nice
+ if (raster_matrix_.invert(&inverse)) {
+ SkCanvas* canvas = picture_->getRecordingCanvas();
reed1 2012/09/17 16:51:24 Shouldn't we "reset" the recording at this point,
reveman 2012/09/17 21:22:16 We need to maintain all the state that's been set
+ SkASSERT(canvas != NULL);
+ canvas->save();
+ canvas->concat(inverse);
+ SkPaint paint;
+ paint.setXfermodeMode(SkXfermode::kSrc_Mode);
+ canvas->drawBitmap(
+ raster_canvas_->getDevice()->accessBitmap(false), 0, 0, &paint);
+ canvas->restore();
+ }
+ // PlatformCanvas matches begin and end calls.
reed1 2012/09/17 16:51:24 1. not sure what that comment means. 2. who delete
reveman 2012/09/17 21:22:16 hm, I copied that from vector_platform_device_skia
+ skia::EndPlatformPaint(raster_canvas_.get());
+ raster_canvas_ = NULL;
reed1 2012/09/17 16:51:24 At this point, perhaps we should just covert over
reveman 2012/09/17 21:22:16 The current patch is creating temporary bitmaps th
+}
+
+#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