1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/lazy/SkDiscardablePixelRef.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 1.4 +/* 1.5 + * Copyright 2013 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 +#ifndef SkDiscardablePixelRef_DEFINED 1.12 +#define SkDiscardablePixelRef_DEFINED 1.13 + 1.14 +#include "SkDiscardableMemory.h" 1.15 +#include "SkImageGenerator.h" 1.16 +#include "SkImageInfo.h" 1.17 +#include "SkPixelRef.h" 1.18 + 1.19 +/** 1.20 + * A PixelRef backed by SkDiscardableMemory, with the ability to 1.21 + * re-generate the pixels (via a SkImageGenerator) if the DM is 1.22 + * purged. 1.23 + * 1.24 + * Since SkColorTable is reference-counted, we do not support indexed 1.25 + * color with this class; there would be no way for the discardable 1.26 + * memory system to unref the color table. 1.27 + */ 1.28 +class SkDiscardablePixelRef : public SkPixelRef { 1.29 +public: 1.30 + SK_DECLARE_INST_COUNT(SkDiscardablePixelRef) 1.31 + SK_DECLARE_UNFLATTENABLE_OBJECT() 1.32 + 1.33 +protected: 1.34 + ~SkDiscardablePixelRef(); 1.35 + 1.36 + virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; 1.37 + virtual void onUnlockPixels() SK_OVERRIDE; 1.38 + virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } 1.39 + 1.40 + virtual SkData* onRefEncodedData() SK_OVERRIDE { 1.41 + return fGenerator->refEncodedData(); 1.42 + } 1.43 + 1.44 +private: 1.45 + SkImageGenerator* const fGenerator; 1.46 + SkDiscardableMemory::Factory* const fDMFactory; 1.47 + const size_t fRowBytes; 1.48 + // These const members should not change over the life of the 1.49 + // PixelRef, since the SkBitmap doesn't expect them to change. 1.50 + 1.51 + SkDiscardableMemory* fDiscardableMemory; 1.52 + 1.53 + /* Takes ownership of SkImageGenerator. */ 1.54 + SkDiscardablePixelRef(const SkImageInfo&, SkImageGenerator*, 1.55 + size_t rowBytes, 1.56 + SkDiscardableMemory::Factory* factory); 1.57 + 1.58 + friend bool SkInstallDiscardablePixelRef(SkImageGenerator*, 1.59 + SkBitmap*, 1.60 + SkDiscardableMemory::Factory*); 1.61 + 1.62 + typedef SkPixelRef INHERITED; 1.63 +}; 1.64 + 1.65 +#endif // SkDiscardablePixelRef_DEFINED