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