Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "skia/ext/recording_platform_device_skia.h" | |
| 6 | |
| 7 #include "skia/ext/platform_canvas.h" | |
| 8 #include "third_party/skia/include/core/SkClipStack.h" | |
| 9 #include "third_party/skia/include/core/SkDraw.h" | |
| 10 #include "third_party/skia/include/core/SkPicture.h" | |
| 11 #include "third_party/skia/include/core/SkRect.h" | |
| 12 #include "third_party/skia/include/core/SkRegion.h" | |
| 13 #include "third_party/skia/include/core/SkScalar.h" | |
| 14 | |
| 15 namespace skia { | |
| 16 | |
| 17 SkDevice* CreateRecordingPlatformDeviceSkia( | |
| 18 SkPicture* picture, int width, int height) { | |
| 19 SkBitmap bm; | |
| 20 bm.setConfig(SkBitmap::kNo_Config, width, height); | |
| 21 return new RecordingPlatformDeviceSkia(bm, picture); | |
| 22 } | |
| 23 | |
| 24 RecordingPlatformDeviceSkia::RecordingPlatformDeviceSkia( | |
| 25 const SkBitmap& bitmap, SkPicture* picture) | |
| 26 : SkDevice(bitmap), | |
| 27 picture_(picture) { | |
| 28 SetPlatformDevice(this, this); | |
| 29 } | |
| 30 | |
| 31 RecordingPlatformDeviceSkia::~RecordingPlatformDeviceSkia() { | |
| 32 } | |
| 33 | |
| 34 bool RecordingPlatformDeviceSkia::SupportsPlatformPaint() { | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 bool RecordingPlatformDeviceSkia::SupportsDirectPlatformPaint() { | |
| 39 return false; | |
| 40 } | |
| 41 | |
| 42 PlatformSurface RecordingPlatformDeviceSkia::BeginPlatformPaint() { | |
| 43 // Even when recording drawing commands of the page, we have to | |
| 44 // provide a raster surface for plugins to render into. Therefore we | |
| 45 // create a BitmapPlatformDevice here and return the context from it, | |
| 46 // then layer on the raster data as an image in EndPlatformPaint. | |
| 47 SkASSERT(raster_canvas_ == NULL); | |
| 48 raster_canvas_ = CreateBitmapCanvas(width(), height(), false); | |
| 49 raster_canvas_->unref(); // SkRefPtr and create both took a reference. | |
| 50 | |
| 51 // Copy picture and playback to raster surface. | |
|
reed1
2012/09/20 13:42:28
you're right about needing to copy so we can conti
reveman
2012/09/20 17:01:26
sure.
| |
| 52 SkPicture raster_picture(*picture_); | |
| 53 raster_canvas_->drawPicture(raster_picture); | |
| 54 // Save the effect of all currently recorded matrix operations. | |
| 55 raster_matrix_ = raster_canvas_->getTotalMatrix(); | |
| 56 | |
| 57 return skia::BeginPlatformPaint(raster_canvas_.get()); | |
| 58 } | |
| 59 | |
| 60 void RecordingPlatformDeviceSkia::EndPlatformPaint() { | |
| 61 SkASSERT(raster_canvas_ != NULL); | |
| 62 SkMatrix inverse; | |
| 63 // To add a drawing command that will render the raster surface at the | |
| 64 // correct origin we need to revert the effect of all currently | |
| 65 // recorded matrix operations. | |
| 66 if (raster_matrix_.invert(&inverse)) { | |
| 67 SkCanvas* canvas = picture_->getRecordingCanvas(); | |
| 68 SkASSERT(canvas != NULL); | |
| 69 canvas->save(); | |
| 70 canvas->concat(inverse); | |
| 71 SkPaint paint; | |
| 72 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
| 73 // TODO(reveman): Need to mark bitmap as being "immutable" before | |
| 74 // calling drawBitmap to avoid having the picture recording code do | |
| 75 // a deep-copy of it. | |
| 76 canvas->drawBitmap( | |
| 77 raster_canvas_->getDevice()->accessBitmap(false), 0, 0, &paint); | |
| 78 canvas->restore(); | |
| 79 } | |
| 80 skia::EndPlatformPaint(raster_canvas_.get()); | |
| 81 raster_canvas_ = NULL; | |
| 82 } | |
| 83 | |
| 84 #if defined(OS_WIN) | |
| 85 void RecordingPlatformDeviceSkia::DrawToNativeContext( | |
| 86 HDC dc, int x, int y, const RECT* src_rect) { | |
| 87 SkASSERT(false); | |
| 88 } | |
| 89 #elif defined(OS_MACOSX) | |
| 90 void RecordingPlatformDeviceSkia::DrawToNativeContext( | |
| 91 CGContext* context, int x, int y, const CGRect* src_rect) { | |
| 92 SkASSERT(false); | |
| 93 } | |
| 94 | |
| 95 CGContextRef RecordingPlatformDeviceSkia::GetBitmapContext() { | |
| 96 SkASSERT(false); | |
| 97 return NULL; | |
| 98 } | |
| 99 #elif defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_OPENBSD) | |
| 100 void RecordingPlatformDeviceSkia::DrawToNativeContext( | |
| 101 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) { | |
| 102 // Should never be called on Linux. | |
| 103 SkASSERT(false); | |
| 104 } | |
| 105 #endif | |
| 106 | |
| 107 } // namespace skia | |
| OLD | NEW |