| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright 2012 Google Inc. |    2  * Copyright 2012 Google Inc. | 
|    3  * |    3  * | 
|    4  * Use of this source code is governed by a BSD-style license that can be |    4  * Use of this source code is governed by a BSD-style license that can be | 
|    5  * found in the LICENSE file. |    5  * found in the LICENSE file. | 
|    6  */ |    6  */ | 
|    7  |    7  | 
|    8 #ifndef SkBitmapHeap_DEFINED |    8 #ifndef SkBitmapHeap_DEFINED | 
|    9 #define SkBitmapHeap_DEFINED |    9 #define SkBitmapHeap_DEFINED | 
|   10  |   10  | 
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  109      * @param heapSize  The maximum size of the heap. Because of the sequential 
     limitation imposed |  109      * @param heapSize  The maximum size of the heap. Because of the sequential 
     limitation imposed | 
|  110      *   by our LRU implementation we can guarantee that the heap will never gro
     w beyond this size. |  110      *   by our LRU implementation we can guarantee that the heap will never gro
     w beyond this size. | 
|  111      */ |  111      */ | 
|  112     SkBitmapHeap(ExternalStorage* externalStorage, int32_t heapSize = UNLIMITED_
     SIZE); |  112     SkBitmapHeap(ExternalStorage* externalStorage, int32_t heapSize = UNLIMITED_
     SIZE); | 
|  113  |  113  | 
|  114     virtual ~SkBitmapHeap(); |  114     virtual ~SkBitmapHeap(); | 
|  115  |  115  | 
|  116     /** |  116     /** | 
|  117      * Retrieves the bitmap from the specified slot in the heap |  117      * Retrieves the bitmap from the specified slot in the heap | 
|  118      * |  118      * | 
|  119      * @return  The bitmap located at that slot or NULL if external storage is b
     eing used. |  119      * @return  The bitmap located at that slot or nullptr if external storage i
     s being used. | 
|  120      */ |  120      */ | 
|  121     SkBitmap* getBitmap(int32_t slot) const override { |  121     SkBitmap* getBitmap(int32_t slot) const override { | 
|  122         SkASSERT(fExternalStorage == NULL); |  122         SkASSERT(fExternalStorage == nullptr); | 
|  123         SkBitmapHeapEntry* entry = getEntry(slot); |  123         SkBitmapHeapEntry* entry = getEntry(slot); | 
|  124         if (entry) { |  124         if (entry) { | 
|  125             return &entry->fBitmap; |  125             return &entry->fBitmap; | 
|  126         } |  126         } | 
|  127         return NULL; |  127         return nullptr; | 
|  128     } |  128     } | 
|  129  |  129  | 
|  130     /** |  130     /** | 
|  131      * Retrieves the bitmap from the specified slot in the heap |  131      * Retrieves the bitmap from the specified slot in the heap | 
|  132      * |  132      * | 
|  133      * @return  The bitmap located at that slot or NULL if external storage is b
     eing used. |  133      * @return  The bitmap located at that slot or nullptr if external storage i
     s being used. | 
|  134      */ |  134      */ | 
|  135     void releaseRef(int32_t slot) override { |  135     void releaseRef(int32_t slot) override { | 
|  136         SkASSERT(fExternalStorage == NULL); |  136         SkASSERT(fExternalStorage == nullptr); | 
|  137         if (fOwnerCount != IGNORE_OWNERS) { |  137         if (fOwnerCount != IGNORE_OWNERS) { | 
|  138             SkBitmapHeapEntry* entry = getEntry(slot); |  138             SkBitmapHeapEntry* entry = getEntry(slot); | 
|  139             if (entry) { |  139             if (entry) { | 
|  140                 entry->releaseRef(); |  140                 entry->releaseRef(); | 
|  141             } |  141             } | 
|  142         } |  142         } | 
|  143     } |  143     } | 
|  144  |  144  | 
|  145     /** |  145     /** | 
|  146      * Inserts a bitmap into the heap. The stored version of bitmap is guarantee
     d to be immutable |  146      * Inserts a bitmap into the heap. The stored version of bitmap is guarantee
     d to be immutable | 
|  147      * and is not dependent on the lifecycle of the provided bitmap. |  147      * and is not dependent on the lifecycle of the provided bitmap. | 
|  148      * |  148      * | 
|  149      * @param bitmap  the bitmap to be inserted into the heap |  149      * @param bitmap  the bitmap to be inserted into the heap | 
|  150      * @return  the slot in the heap where the bitmap is stored or INVALID_SLOT 
     if the bitmap could |  150      * @return  the slot in the heap where the bitmap is stored or INVALID_SLOT 
     if the bitmap could | 
|  151      *          not be added to the heap. If it was added the slot will remain v
     alid... |  151      *          not be added to the heap. If it was added the slot will remain v
     alid... | 
|  152      *            (1) indefinitely if no owner count has been specified. |  152      *            (1) indefinitely if no owner count has been specified. | 
|  153      *            (2) until all owners have called releaseRef on the appropriate
      SkBitmapHeapEntry* |  153      *            (2) until all owners have called releaseRef on the appropriate
      SkBitmapHeapEntry* | 
|  154      */ |  154      */ | 
|  155     int32_t insert(const SkBitmap& bitmap); |  155     int32_t insert(const SkBitmap& bitmap); | 
|  156  |  156  | 
|  157     /** |  157     /** | 
|  158      * Retrieves an entry from the heap at a given slot. |  158      * Retrieves an entry from the heap at a given slot. | 
|  159      * |  159      * | 
|  160      * @param slot  the slot in the heap where a bitmap was stored. |  160      * @param slot  the slot in the heap where a bitmap was stored. | 
|  161      * @return  a SkBitmapHeapEntry that wraps the bitmap or NULL if external st
     orage is used. |  161      * @return  a SkBitmapHeapEntry that wraps the bitmap or nullptr if external
      storage is used. | 
|  162      */ |  162      */ | 
|  163     SkBitmapHeapEntry* getEntry(int32_t slot) const { |  163     SkBitmapHeapEntry* getEntry(int32_t slot) const { | 
|  164         SkASSERT(slot <= fStorage.count()); |  164         SkASSERT(slot <= fStorage.count()); | 
|  165         if (fExternalStorage != NULL) { |  165         if (fExternalStorage != nullptr) { | 
|  166             return NULL; |  166             return nullptr; | 
|  167         } |  167         } | 
|  168         return fStorage[slot]; |  168         return fStorage[slot]; | 
|  169     } |  169     } | 
|  170  |  170  | 
|  171     /** |  171     /** | 
|  172      * Returns a count of the number of items currently in the heap |  172      * Returns a count of the number of items currently in the heap | 
|  173      */ |  173      */ | 
|  174     int count() const { |  174     int count() const { | 
|  175         SkASSERT(fExternalStorage != NULL || |  175         SkASSERT(fExternalStorage != nullptr || | 
|  176                  fStorage.count() - fUnusedSlots.count() == fLookupTable.count()
     ); |  176                  fStorage.count() - fUnusedSlots.count() == fLookupTable.count()
     ); | 
|  177         return fLookupTable.count(); |  177         return fLookupTable.count(); | 
|  178     } |  178     } | 
|  179  |  179  | 
|  180     /** |  180     /** | 
|  181      * Returns the total number of bytes allocated by the bitmaps in the heap |  181      * Returns the total number of bytes allocated by the bitmaps in the heap | 
|  182      */ |  182      */ | 
|  183     size_t bytesAllocated() const { |  183     size_t bytesAllocated() const { | 
|  184         return fBytesAllocated; |  184         return fBytesAllocated; | 
|  185     } |  185     } | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|  208      */ |  208      */ | 
|  209     void endAddingOwnersDeferral(bool add); |  209     void endAddingOwnersDeferral(bool add); | 
|  210  |  210  | 
|  211 private: |  211 private: | 
|  212     struct LookupEntry { |  212     struct LookupEntry { | 
|  213         LookupEntry(const SkBitmap& bm) |  213         LookupEntry(const SkBitmap& bm) | 
|  214         : fGenerationId(bm.getGenerationID()) |  214         : fGenerationId(bm.getGenerationID()) | 
|  215         , fPixelOrigin(bm.pixelRefOrigin()) |  215         , fPixelOrigin(bm.pixelRefOrigin()) | 
|  216         , fWidth(bm.width()) |  216         , fWidth(bm.width()) | 
|  217         , fHeight(bm.height()) |  217         , fHeight(bm.height()) | 
|  218         , fMoreRecentlyUsed(NULL) |  218         , fMoreRecentlyUsed(nullptr) | 
|  219         , fLessRecentlyUsed(NULL){} |  219         , fLessRecentlyUsed(nullptr){} | 
|  220  |  220  | 
|  221         const uint32_t fGenerationId; // SkPixelRef GenerationID. |  221         const uint32_t fGenerationId; // SkPixelRef GenerationID. | 
|  222         const SkIPoint fPixelOrigin; |  222         const SkIPoint fPixelOrigin; | 
|  223         const uint32_t fWidth; |  223         const uint32_t fWidth; | 
|  224         const uint32_t fHeight; |  224         const uint32_t fHeight; | 
|  225  |  225  | 
|  226         // TODO: Generalize the LRU caching mechanism |  226         // TODO: Generalize the LRU caching mechanism | 
|  227         LookupEntry* fMoreRecentlyUsed; |  227         LookupEntry* fMoreRecentlyUsed; | 
|  228         LookupEntry* fLessRecentlyUsed; |  228         LookupEntry* fLessRecentlyUsed; | 
|  229  |  229  | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  253      *               in the lookup table is populated with the entry from the he
     ap storage. |  253      *               in the lookup table is populated with the entry from the he
     ap storage. | 
|  254      */ |  254      */ | 
|  255     int findInLookupTable(const LookupEntry& key, SkBitmapHeapEntry** entry); |  255     int findInLookupTable(const LookupEntry& key, SkBitmapHeapEntry** entry); | 
|  256  |  256  | 
|  257     LookupEntry* findEntryToReplace(const SkBitmap& replacement); |  257     LookupEntry* findEntryToReplace(const SkBitmap& replacement); | 
|  258     bool copyBitmap(const SkBitmap& originalBitmap, SkBitmap& copiedBitmap); |  258     bool copyBitmap(const SkBitmap& originalBitmap, SkBitmap& copiedBitmap); | 
|  259  |  259  | 
|  260     /** |  260     /** | 
|  261      * Remove a LookupEntry from the LRU, in preparation for either deleting or 
     appending as most |  261      * Remove a LookupEntry from the LRU, in preparation for either deleting or 
     appending as most | 
|  262      * recent. Points the LookupEntry's old neighbors at each other, and sets fL
     eastRecentlyUsed |  262      * recent. Points the LookupEntry's old neighbors at each other, and sets fL
     eastRecentlyUsed | 
|  263      * (if there is still an entry left). Sets LookupEntry's fMoreRecentlyUsed t
     o NULL and leaves |  263      * (if there is still an entry left). Sets LookupEntry's fMoreRecentlyUsed t
     o nullptr and leaves | 
|  264      * its fLessRecentlyUsed unmodified. |  264      * its fLessRecentlyUsed unmodified. | 
|  265      */ |  265      */ | 
|  266     void removeFromLRU(LookupEntry* entry); |  266     void removeFromLRU(LookupEntry* entry); | 
|  267  |  267  | 
|  268     /** |  268     /** | 
|  269      * Append a LookupEntry to the end of the LRU cache, marking it as the most |  269      * Append a LookupEntry to the end of the LRU cache, marking it as the most | 
|  270      * recently used. Assumes that the LookupEntry is already in fLookupTable, |  270      * recently used. Assumes that the LookupEntry is already in fLookupTable, | 
|  271      * but is not in the LRU cache. If it is in the cache, removeFromLRU should |  271      * but is not in the LRU cache. If it is in the cache, removeFromLRU should | 
|  272      * be called first. |  272      * be called first. | 
|  273      */ |  273      */ | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  290     const int32_t fOwnerCount; |  290     const int32_t fOwnerCount; | 
|  291     size_t fBytesAllocated; |  291     size_t fBytesAllocated; | 
|  292  |  292  | 
|  293     bool fDeferAddingOwners; |  293     bool fDeferAddingOwners; | 
|  294     SkTDArray<int> fDeferredEntries; |  294     SkTDArray<int> fDeferredEntries; | 
|  295  |  295  | 
|  296     typedef SkBitmapHeapReader INHERITED; |  296     typedef SkBitmapHeapReader INHERITED; | 
|  297 }; |  297 }; | 
|  298  |  298  | 
|  299 #endif // SkBitmapHeap_DEFINED |  299 #endif // SkBitmapHeap_DEFINED | 
| OLD | NEW |