180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2010 Google Inc.
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkBitmapCache_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkBitmapCache_DEFINED
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkBitmap.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkBitmapCache : SkNoncopyable {
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkBitmapCache(int maxEntries);
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ~SkBitmapCache();
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool find(const void* buffer, size_t len, SkBitmap*) const;
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void add(const void* buffer, size_t len, const SkBitmap&);
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int fEntryCount;
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const int fMaxEntries;
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    struct Entry;
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    mutable Entry*  fHead;
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    mutable Entry*  fTail;
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    inline Entry* detach(Entry*) const;
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    inline void attachToHead(Entry*) const;
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void validate() const;
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#else
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void validate() const {}
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    class AutoValidate : SkNoncopyable {
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    public:
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        AutoValidate(const SkBitmapCache* bc) : fBC(bc) { bc->validate(); }
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        ~AutoValidate() { fBC->validate(); }
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    private:
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const SkBitmapCache* fBC;
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
50