michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkImage_Base.h" michael@0: #include "SkImagePriv.h" michael@0: #include "SkPicture.h" michael@0: michael@0: class SkImage_Picture : public SkImage_Base { michael@0: public: michael@0: SkImage_Picture(SkPicture*); michael@0: virtual ~SkImage_Picture(); michael@0: michael@0: virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE; michael@0: virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE; michael@0: michael@0: SkPicture* getPicture() { return fPicture; } michael@0: michael@0: private: michael@0: SkPicture* fPicture; michael@0: michael@0: typedef SkImage_Base INHERITED; michael@0: }; michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: SkImage_Picture::SkImage_Picture(SkPicture* pict) : INHERITED(pict->width(), pict->height()) { michael@0: pict->endRecording(); michael@0: pict->ref(); michael@0: fPicture = pict; michael@0: } michael@0: michael@0: SkImage_Picture::~SkImage_Picture() { michael@0: fPicture->unref(); michael@0: } michael@0: michael@0: void SkImage_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, michael@0: const SkPaint* paint) { michael@0: SkImagePrivDrawPicture(canvas, fPicture, x, y, paint); michael@0: } michael@0: michael@0: void SkImage_Picture::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, michael@0: const SkPaint* paint) { michael@0: SkImagePrivDrawPicture(canvas, fPicture, src, dst, paint); michael@0: } michael@0: michael@0: SkImage* SkNewImageFromPicture(const SkPicture* srcPicture) { michael@0: /** michael@0: * We want to snapshot the playback status of the picture, w/o affecting michael@0: * its ability to continue recording (if needed). michael@0: * michael@0: * Optimally this will shared as much data/buffers as it can with michael@0: * srcPicture, and srcPicture will perform a copy-on-write as needed if it michael@0: * needs to mutate them later on. michael@0: */ michael@0: SkAutoTUnref playback(SkNEW_ARGS(SkPicture, (*srcPicture))); michael@0: michael@0: return SkNEW_ARGS(SkImage_Picture, (playback)); michael@0: } michael@0: michael@0: SkPicture* SkPictureImageGetPicture(SkImage* pictureImage) { michael@0: return static_cast(pictureImage)->getPicture(); michael@0: }