michael@0: michael@0: /* michael@0: * Copyright 2010 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: michael@0: #ifndef SkBitmapCache_DEFINED michael@0: #define SkBitmapCache_DEFINED michael@0: michael@0: #include "SkBitmap.h" michael@0: michael@0: class SkBitmapCache : SkNoncopyable { michael@0: public: michael@0: SkBitmapCache(int maxEntries); michael@0: ~SkBitmapCache(); michael@0: michael@0: bool find(const void* buffer, size_t len, SkBitmap*) const; michael@0: void add(const void* buffer, size_t len, const SkBitmap&); michael@0: michael@0: private: michael@0: int fEntryCount; michael@0: const int fMaxEntries; michael@0: michael@0: struct Entry; michael@0: mutable Entry* fHead; michael@0: mutable Entry* fTail; michael@0: michael@0: inline Entry* detach(Entry*) const; michael@0: inline void attachToHead(Entry*) const; michael@0: michael@0: #ifdef SK_DEBUG michael@0: void validate() const; michael@0: #else michael@0: void validate() const {} michael@0: #endif michael@0: michael@0: class AutoValidate : SkNoncopyable { michael@0: public: michael@0: AutoValidate(const SkBitmapCache* bc) : fBC(bc) { bc->validate(); } michael@0: ~AutoValidate() { fBC->validate(); } michael@0: private: michael@0: const SkBitmapCache* fBC; michael@0: }; michael@0: }; michael@0: michael@0: #endif