1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/image/SkImage_Picture.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#include "SkImage_Base.h" 1.12 +#include "SkImagePriv.h" 1.13 +#include "SkPicture.h" 1.14 + 1.15 +class SkImage_Picture : public SkImage_Base { 1.16 +public: 1.17 + SkImage_Picture(SkPicture*); 1.18 + virtual ~SkImage_Picture(); 1.19 + 1.20 + virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE; 1.21 + virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE; 1.22 + 1.23 + SkPicture* getPicture() { return fPicture; } 1.24 + 1.25 +private: 1.26 + SkPicture* fPicture; 1.27 + 1.28 + typedef SkImage_Base INHERITED; 1.29 +}; 1.30 + 1.31 +/////////////////////////////////////////////////////////////////////////////// 1.32 + 1.33 +SkImage_Picture::SkImage_Picture(SkPicture* pict) : INHERITED(pict->width(), pict->height()) { 1.34 + pict->endRecording(); 1.35 + pict->ref(); 1.36 + fPicture = pict; 1.37 +} 1.38 + 1.39 +SkImage_Picture::~SkImage_Picture() { 1.40 + fPicture->unref(); 1.41 +} 1.42 + 1.43 +void SkImage_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 1.44 + const SkPaint* paint) { 1.45 + SkImagePrivDrawPicture(canvas, fPicture, x, y, paint); 1.46 +} 1.47 + 1.48 +void SkImage_Picture::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, 1.49 + const SkPaint* paint) { 1.50 + SkImagePrivDrawPicture(canvas, fPicture, src, dst, paint); 1.51 +} 1.52 + 1.53 +SkImage* SkNewImageFromPicture(const SkPicture* srcPicture) { 1.54 + /** 1.55 + * We want to snapshot the playback status of the picture, w/o affecting 1.56 + * its ability to continue recording (if needed). 1.57 + * 1.58 + * Optimally this will shared as much data/buffers as it can with 1.59 + * srcPicture, and srcPicture will perform a copy-on-write as needed if it 1.60 + * needs to mutate them later on. 1.61 + */ 1.62 + SkAutoTUnref<SkPicture> playback(SkNEW_ARGS(SkPicture, (*srcPicture))); 1.63 + 1.64 + return SkNEW_ARGS(SkImage_Picture, (playback)); 1.65 +} 1.66 + 1.67 +SkPicture* SkPictureImageGetPicture(SkImage* pictureImage) { 1.68 + return static_cast<SkImage_Picture*>(pictureImage)->getPicture(); 1.69 +}