michael@0: /* michael@0: * Copyright 2013 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: #ifndef SkDiscardablePixelRef_DEFINED michael@0: #define SkDiscardablePixelRef_DEFINED michael@0: michael@0: #include "SkDiscardableMemory.h" michael@0: #include "SkImageGenerator.h" michael@0: #include "SkImageInfo.h" michael@0: #include "SkPixelRef.h" michael@0: michael@0: /** michael@0: * A PixelRef backed by SkDiscardableMemory, with the ability to michael@0: * re-generate the pixels (via a SkImageGenerator) if the DM is michael@0: * purged. michael@0: * michael@0: * Since SkColorTable is reference-counted, we do not support indexed michael@0: * color with this class; there would be no way for the discardable michael@0: * memory system to unref the color table. michael@0: */ michael@0: class SkDiscardablePixelRef : public SkPixelRef { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkDiscardablePixelRef) michael@0: SK_DECLARE_UNFLATTENABLE_OBJECT() michael@0: michael@0: protected: michael@0: ~SkDiscardablePixelRef(); michael@0: michael@0: virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; michael@0: virtual void onUnlockPixels() SK_OVERRIDE; michael@0: virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } michael@0: michael@0: virtual SkData* onRefEncodedData() SK_OVERRIDE { michael@0: return fGenerator->refEncodedData(); michael@0: } michael@0: michael@0: private: michael@0: SkImageGenerator* const fGenerator; michael@0: SkDiscardableMemory::Factory* const fDMFactory; michael@0: const size_t fRowBytes; michael@0: // These const members should not change over the life of the michael@0: // PixelRef, since the SkBitmap doesn't expect them to change. michael@0: michael@0: SkDiscardableMemory* fDiscardableMemory; michael@0: michael@0: /* Takes ownership of SkImageGenerator. */ michael@0: SkDiscardablePixelRef(const SkImageInfo&, SkImageGenerator*, michael@0: size_t rowBytes, michael@0: SkDiscardableMemory::Factory* factory); michael@0: michael@0: friend bool SkInstallDiscardablePixelRef(SkImageGenerator*, michael@0: SkBitmap*, michael@0: SkDiscardableMemory::Factory*); michael@0: michael@0: typedef SkPixelRef INHERITED; michael@0: }; michael@0: michael@0: #endif // SkDiscardablePixelRef_DEFINED