blob: 447299f49dca9d5dbbcb7bc94a541faacf973d09 [file] [log] [blame]
reed@google.com58b21ec2012-07-30 18:20:12 +00001/*
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
12class SkImage_Picture : public SkImage_Base {
13public:
14 SkImage_Picture(SkPicture*);
15 virtual ~SkImage_Picture();
16
17 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE;
18
19private:
20 SkPicture* fPicture;
21
22 typedef SkImage_Base INHERITED;
23};
24
25///////////////////////////////////////////////////////////////////////////////
26
27SkImage_Picture::SkImage_Picture(SkPicture* pict) : INHERITED(pict->width(), pict->height()) {
28 pict->endRecording();
29 pict->ref();
30 fPicture = pict;
31}
32
33SkImage_Picture::~SkImage_Picture() {
34 fPicture->unref();
35}
36
37void SkImage_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
38 const SkPaint* paint) {
39 SkImagePrivDrawPicture(canvas, fPicture, x, y, paint);
40}
41
reed@google.com9ea5a3b2012-07-30 21:03:46 +000042SkImage* SkNewImageFromPicture(const SkPicture* srcPicture) {
43 /**
44 * We want to snapshot the playback status of the picture, w/o affecting
45 * its ability to continue recording (if needed).
46 *
47 * Optimally this will shared as much data/buffers as it can with
48 * srcPicture, and srcPicture will perform a copy-on-write as needed if it
49 * needs to mutate them later on.
50 */
51 SkAutoTUnref<SkPicture> playback(SkNEW_ARGS(SkPicture, (*srcPicture)));
52
53 return SkNEW_ARGS(SkImage_Picture, (playback));
reed@google.com58b21ec2012-07-30 18:20:12 +000054}