| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "SkChecksum.h" | 8 #include "SkChecksum.h" |
| 9 #include "SkResourceCache.h" | 9 #include "SkResourceCache.h" |
| 10 #include "SkMipMap.h" | 10 #include "SkMipMap.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 #include "SkDiscardableMemory.h" | 66 #include "SkDiscardableMemory.h" |
| 67 | 67 |
| 68 class SkOneShotDiscardablePixelRef : public SkPixelRef { | 68 class SkOneShotDiscardablePixelRef : public SkPixelRef { |
| 69 public: | 69 public: |
| 70 SK_DECLARE_INST_COUNT(SkOneShotDiscardablePixelRef) | 70 SK_DECLARE_INST_COUNT(SkOneShotDiscardablePixelRef) |
| 71 // Ownership of the discardablememory is transfered to the pixelref | 71 // Ownership of the discardablememory is transfered to the pixelref |
| 72 SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_
t rowBytes); | 72 SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_
t rowBytes); |
| 73 ~SkOneShotDiscardablePixelRef(); | 73 ~SkOneShotDiscardablePixelRef(); |
| 74 | 74 |
| 75 protected: | 75 protected: |
| 76 virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; | 76 bool onNewLockPixels(LockRec*) SK_OVERRIDE; |
| 77 virtual void onUnlockPixels() SK_OVERRIDE; | 77 void onUnlockPixels() SK_OVERRIDE; |
| 78 virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE; | 78 size_t getAllocatedSizeInBytes() const SK_OVERRIDE; |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 SkDiscardableMemory* fDM; | 81 SkDiscardableMemory* fDM; |
| 82 size_t fRB; | 82 size_t fRB; |
| 83 bool fFirstTime; | 83 bool fFirstTime; |
| 84 | 84 |
| 85 typedef SkPixelRef INHERITED; | 85 typedef SkPixelRef INHERITED; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& in
fo, | 88 SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& in
fo, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return this->info().getSafeSize(fRB); | 136 return this->info().getSafeSize(fRB); |
| 137 } | 137 } |
| 138 | 138 |
| 139 class SkResourceCacheDiscardableAllocator : public SkBitmap::Allocator { | 139 class SkResourceCacheDiscardableAllocator : public SkBitmap::Allocator { |
| 140 public: | 140 public: |
| 141 SkResourceCacheDiscardableAllocator(SkResourceCache::DiscardableFactory fact
ory) { | 141 SkResourceCacheDiscardableAllocator(SkResourceCache::DiscardableFactory fact
ory) { |
| 142 SkASSERT(factory); | 142 SkASSERT(factory); |
| 143 fFactory = factory; | 143 fFactory = factory; |
| 144 } | 144 } |
| 145 | 145 |
| 146 virtual bool allocPixelRef(SkBitmap*, SkColorTable*) SK_OVERRIDE; | 146 bool allocPixelRef(SkBitmap*, SkColorTable*) SK_OVERRIDE; |
| 147 | 147 |
| 148 private: | 148 private: |
| 149 SkResourceCache::DiscardableFactory fFactory; | 149 SkResourceCache::DiscardableFactory fFactory; |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 bool SkResourceCacheDiscardableAllocator::allocPixelRef(SkBitmap* bitmap, SkColo
rTable* ctable) { | 152 bool SkResourceCacheDiscardableAllocator::allocPixelRef(SkBitmap* bitmap, SkColo
rTable* ctable) { |
| 153 size_t size = bitmap->getSize(); | 153 size_t size = bitmap->getSize(); |
| 154 uint64_t size64 = bitmap->computeSize64(); | 154 uint64_t size64 = bitmap->computeSize64(); |
| 155 if (0 == size || size64 > (uint64_t)size) { | 155 if (0 == size || size64 > (uint64_t)size) { |
| 156 return false; | 156 return false; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 } | 547 } |
| 548 | 548 |
| 549 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { | 549 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { |
| 550 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); | 550 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); |
| 551 } | 551 } |
| 552 | 552 |
| 553 void SkGraphics::PurgeResourceCache() { | 553 void SkGraphics::PurgeResourceCache() { |
| 554 return SkResourceCache::PurgeAll(); | 554 return SkResourceCache::PurgeAll(); |
| 555 } | 555 } |
| 556 | 556 |
| OLD | NEW |