 Chromium Code Reviews
 Chromium Code Reviews Issue 12645006:
  Create a platform-dependent object for accessing purgeable memory.  (Closed) 
  Base URL: https://skia.googlecode.com/svn/trunk
    
  
    Issue 12645006:
  Create a platform-dependent object for accessing purgeable memory.  (Closed) 
  Base URL: https://skia.googlecode.com/svn/trunk| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkPurgeableMemoryBlock_DEFINED | |
| 9 #define SkPurgeableMemoryBlock_DEFINED | |
| 10 | |
| 11 #include "SkTypes.h" | |
| 12 | |
| 13 class SkPurgeableMemoryBlock : public SkNoncopyable { | |
| 14 | |
| 15 public: | |
| 16 /** | |
| 17 * Whether or not this platform has an implementation for purgeable memory. | |
| 18 */ | |
| 19 static bool PlatformSupportsPurgeableMemory(); | |
| 
djsollen
2013/03/14 13:56:31
writing SkPurgeableMemoryBlock::PlatformSupportsPu
 
scroggo
2013/03/14 15:36:13
Done.
 | |
| 20 | |
| 21 /** | |
| 22 * Create a new purgeable memory block of 'size' bytes. Returns NULL if not supported on this | |
| 23 * platform or on failure. | |
| 24 * @param size Number of bytes requested. | |
| 25 * @return A new block, or NULL on failure. | |
| 26 */ | |
| 27 static SkPurgeableMemoryBlock* CreatePurgeableMemoryBlock(size_t size); | |
| 
djsollen
2013/03/14 13:56:31
following the naming of other factories like SkBlu
 
scroggo
2013/03/14 15:36:13
Done.
 | |
| 28 | |
| 29 #ifdef SK_DEBUG | |
| 30 /** | |
| 31 * Whether the platform supports one shot purge of all unpinned blocks. If so, | |
| 32 * PurgeAllUnpinnedBlocks will be used to test a purge. Otherwise, purge wi ll be called on | |
| 33 * individual blocks. | |
| 34 */ | |
| 35 static bool PlatformSupportsPurgingAllUnpinnedBlocks(); | |
| 36 | |
| 37 /** | |
| 38 * Purge all unpinned blocks at once, if the platform supports it. | |
| 39 */ | |
| 40 static bool PurgeAllUnpinnedBlocks(); | |
| 41 | |
| 42 // If PlatformSupportsPurgingAllUnpinnedBlocks returns true, this will not b e called, so it can | |
| 43 // simply return false. | |
| 44 bool purge(); | |
| 45 | |
| 46 bool isPinned() const { return fPinned; } | |
| 47 | |
| 48 #ifdef SK_BUILD_FOR_ANDROID | |
| 49 int getFD() const { return fFD; } | |
| 
djsollen
2013/03/14 13:56:31
Is this really needed? Who calls this?
 
scroggo
2013/03/14 15:36:13
This is a debug only function just for debugging.
 
scroggo
2013/03/14 18:05:32
Removed! Thanks for adding the purge function!
 | |
| 50 #endif | |
| 51 | |
| 52 #endif | |
| 53 | |
| 54 ~SkPurgeableMemoryBlock(); | |
| 55 | |
| 56 /** | |
| 57 * Output parameter for pin(), stating whether the data has been retained. | |
| 58 */ | |
| 59 enum PinResult { | |
| 60 /** | |
| 61 * The data has been purged, or this is the first call to pin. | |
| 62 */ | |
| 63 kUninitialized_PinResult, | |
| 64 | |
| 65 /** | |
| 66 * The data has been retained. The memory contains the same data it hel d when unpin() was | |
| 67 * called. | |
| 68 */ | |
| 69 kRetained_PinResult, | |
| 70 }; | |
| 71 | |
| 72 /** | |
| 73 * Pin the memory for use. Must not be called while already pinned. | |
| 74 * @param PinResult Whether the data was retained. Ignored on failure. | |
| 75 * @return Pointer to the pinned data on success. NULL on failure. | |
| 76 */ | |
| 77 void* pin(PinResult*); | |
| 78 | |
| 79 /** | |
| 80 * Unpin the data so it can be purged if necessary. | |
| 81 */ | |
| 82 void unpin(); | |
| 83 | |
| 84 private: | |
| 85 void* fAddr; | |
| 86 size_t fSize; | |
| 87 bool fPinned; | |
| 88 #ifdef SK_BUILD_FOR_ANDROID | |
| 89 int fFD; | |
| 90 #endif | |
| 91 | |
| 92 // Unimplemented default constructor is private, to prevent manual creation. | |
| 93 SkPurgeableMemoryBlock(); | |
| 94 | |
| 95 // The correct way to create a new one is from the static CreatePurgeableMem oryBlock. | |
| 96 SkPurgeableMemoryBlock(size_t); | |
| 97 }; | |
| 98 | |
| 99 #endif // SkPurgeableMemoryBlock_DEFINED | |
| OLD | NEW |