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::IsNativeFontRenderingAllowed() { | |
| 35 return false; | |
| 36 } | |
| 37 | |
| 38 bool RecordingPlatformDeviceSkia::IsNativeRenderingAllowed() { | |
| 39 return true; | |
| 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/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
| |
| 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. | |
|
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
| |
| 66 if (raster_matrix_.invert(&inverse)) { | |
| 67 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
| |
| 68 SkASSERT(canvas != NULL); | |
| 69 canvas->save(); | |
| 70 canvas->concat(inverse); | |
| 71 SkPaint paint; | |
| 72 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
| 73 canvas->drawBitmap( | |
| 74 raster_canvas_->getDevice()->accessBitmap(false), 0, 0, &paint); | |
| 75 canvas->restore(); | |
| 76 } | |
| 77 // 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
| |
| 78 skia::EndPlatformPaint(raster_canvas_.get()); | |
| 79 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
| |
| 80 } | |
| 81 | |
| 82 #if defined(OS_WIN) | |
| 83 void RecordingPlatformDeviceSkia::DrawToNativeContext( | |
| 84 HDC dc, int x, int y, const RECT* src_rect) { | |
| 85 SkASSERT(false); | |
| 86 } | |
| 87 #elif defined(OS_MACOSX) | |
| 88 void RecordingPlatformDeviceSkia::DrawToNativeContext( | |
| 89 CGContext* context, int x, int y, const CGRect* src_rect) { | |
| 90 SkASSERT(false); | |
| 91 } | |
| 92 | |
| 93 CGContextRef RecordingPlatformDeviceSkia::GetBitmapContext() { | |
| 94 SkASSERT(false); | |
| 95 return NULL; | |
| 96 } | |
| 97 #elif defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_OPENBSD) | |
| 98 void RecordingPlatformDeviceSkia::DrawToNativeContext( | |
| 99 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) { | |
| 100 // Should never be called on Linux. | |
| 101 SkASSERT(false); | |
| 102 } | |
| 103 #endif | |
| 104 | |
| 105 } // namespace skia | |
| OLD | NEW |