2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkImage_Base.h"
9 #include "SkImagePriv.h"
10 #include "SkPicture.h"
12 class SkImage_Picture : public SkImage_Base {
14 SkImage_Picture(SkPicture*);
15 virtual ~SkImage_Picture();
17 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE;
18 virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE;
20 SkPicture* getPicture() { return fPicture; }
25 typedef SkImage_Base INHERITED;
28 ///////////////////////////////////////////////////////////////////////////////
30 SkImage_Picture::SkImage_Picture(SkPicture* pict) : INHERITED(pict->width(), pict->height()) {
36 SkImage_Picture::~SkImage_Picture() {
40 void SkImage_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
41 const SkPaint* paint) {
42 SkImagePrivDrawPicture(canvas, fPicture, x, y, paint);
45 void SkImage_Picture::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst,
46 const SkPaint* paint) {
47 SkImagePrivDrawPicture(canvas, fPicture, src, dst, paint);
50 SkImage* SkNewImageFromPicture(const SkPicture* srcPicture) {
52 * We want to snapshot the playback status of the picture, w/o affecting
53 * its ability to continue recording (if needed).
55 * Optimally this will shared as much data/buffers as it can with
56 * srcPicture, and srcPicture will perform a copy-on-write as needed if it
57 * needs to mutate them later on.
59 SkAutoTUnref<SkPicture> playback(SkNEW_ARGS(SkPicture, (*srcPicture)));
61 return SkNEW_ARGS(SkImage_Picture, (playback));
64 SkPicture* SkPictureImageGetPicture(SkImage* pictureImage) {
65 return static_cast<SkImage_Picture*>(pictureImage)->getPicture();