reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkImage_Base.h" |
| 9 | #include "SkImagePriv.h" |
| 10 | #include "SkPicture.h" |
| 11 | |
| 12 | class SkImage_Picture : public SkImage_Base { |
| 13 | public: |
| 14 | SkImage_Picture(SkPicture*); |
| 15 | virtual ~SkImage_Picture(); |
| 16 | |
| 17 | virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE; |
| 18 | |
junov@chromium.org | 45c3db8 | 2013-04-11 17:52:05 +0000 | [diff] [blame^] | 19 | SkPicture* getPicture() { return fPicture; } |
| 20 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 21 | private: |
| 22 | SkPicture* fPicture; |
| 23 | |
| 24 | typedef SkImage_Base INHERITED; |
| 25 | }; |
| 26 | |
| 27 | /////////////////////////////////////////////////////////////////////////////// |
| 28 | |
| 29 | SkImage_Picture::SkImage_Picture(SkPicture* pict) : INHERITED(pict->width(), pict->height()) { |
| 30 | pict->endRecording(); |
| 31 | pict->ref(); |
| 32 | fPicture = pict; |
| 33 | } |
| 34 | |
| 35 | SkImage_Picture::~SkImage_Picture() { |
| 36 | fPicture->unref(); |
| 37 | } |
| 38 | |
| 39 | void SkImage_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
| 40 | const SkPaint* paint) { |
| 41 | SkImagePrivDrawPicture(canvas, fPicture, x, y, paint); |
| 42 | } |
| 43 | |
reed@google.com | 9ea5a3b | 2012-07-30 21:03:46 +0000 | [diff] [blame] | 44 | SkImage* SkNewImageFromPicture(const SkPicture* srcPicture) { |
| 45 | /** |
| 46 | * We want to snapshot the playback status of the picture, w/o affecting |
| 47 | * its ability to continue recording (if needed). |
| 48 | * |
| 49 | * Optimally this will shared as much data/buffers as it can with |
| 50 | * srcPicture, and srcPicture will perform a copy-on-write as needed if it |
| 51 | * needs to mutate them later on. |
| 52 | */ |
| 53 | SkAutoTUnref<SkPicture> playback(SkNEW_ARGS(SkPicture, (*srcPicture))); |
| 54 | |
| 55 | return SkNEW_ARGS(SkImage_Picture, (playback)); |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 56 | } |
junov@chromium.org | 45c3db8 | 2013-04-11 17:52:05 +0000 | [diff] [blame^] | 57 | |
| 58 | SkPicture* SkPictureImageGetPicture(SkImage* pictureImage) { |
| 59 | return static_cast<SkImage_Picture*>(pictureImage)->getPicture(); |
| 60 | } |