aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkImage_Picture.cpp
blob: 87221de27b555f700560c429c9110e52ae1bfd6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkImage_Base.h"
#include "SkImagePriv.h"
#include "SkPicture.h"

class SkImage_Picture : public SkImage_Base {
public:
    SkImage_Picture(SkPicture*);
    virtual ~SkImage_Picture();

    virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE;
    virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE;

    SkPicture* getPicture() { return fPicture; }

private:
    SkPicture*  fPicture;

    typedef SkImage_Base INHERITED;
};

///////////////////////////////////////////////////////////////////////////////

SkImage_Picture::SkImage_Picture(SkPicture* pict) : INHERITED(pict->width(), pict->height()) {
    pict->endRecording();
    pict->ref();
    fPicture = pict;
}

SkImage_Picture::~SkImage_Picture() {
    fPicture->unref();
}

void SkImage_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
                             const SkPaint* paint) {
    SkImagePrivDrawPicture(canvas, fPicture, x, y, paint);
}

void SkImage_Picture::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst,
                             const SkPaint* paint) {
    SkImagePrivDrawPicture(canvas, fPicture, src, dst, paint);
}

SkImage* SkNewImageFromPicture(const SkPicture* srcPicture) {
    /**
     *  We want to snapshot the playback status of the picture, w/o affecting
     *  its ability to continue recording (if needed).
     *
     *  Optimally this will shared as much data/buffers as it can with
     *  srcPicture, and srcPicture will perform a copy-on-write as needed if it
     *  needs to mutate them later on.
     */
    SkAutoTUnref<SkPicture> playback(SkNEW_ARGS(SkPicture, (*srcPicture)));

    return SkNEW_ARGS(SkImage_Picture, (playback));
}

SkPicture* SkPictureImageGetPicture(SkImage* pictureImage) {
    return static_cast<SkImage_Picture*>(pictureImage)->getPicture();
}