| 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 #ifndef SkDiscardableMemory_DEFINED | 8 #ifndef SkDiscardableMemory_DEFINED |
| 9 #define SkDiscardableMemory_DEFINED | 9 #define SkDiscardableMemory_DEFINED |
| 10 | 10 |
| 11 #include "SkRefCnt.h" |
| 11 #include "SkTypes.h" | 12 #include "SkTypes.h" |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * Interface for discardable memory. Implementation is provided by the | 15 * Interface for discardable memory. Implementation is provided by the |
| 15 * embedder. | 16 * embedder. |
| 16 */ | 17 */ |
| 17 class SK_API SkDiscardableMemory { | 18 class SK_API SkDiscardableMemory { |
| 18 | |
| 19 public: | 19 public: |
| 20 /** | 20 /** |
| 21 * Factory method that creates, initializes and locks an SkDiscardableMemor
y | 21 * Factory method that creates, initializes and locks an SkDiscardableMemor
y |
| 22 * object. If either of these steps fails, a NULL pointer will be returned. | 22 * object. If either of these steps fails, a NULL pointer will be returned. |
| 23 */ | 23 */ |
| 24 static SkDiscardableMemory* Create(size_t bytes); | 24 static SkDiscardableMemory* Create(size_t bytes); |
| 25 | 25 |
| 26 /** |
| 27 * Factory class that creates, initializes and locks an SkDiscardableMemory |
| 28 * object. If either of these steps fails, a NULL pointer will be returned. |
| 29 */ |
| 30 class Factory : public SkRefCnt { |
| 31 public: |
| 32 virtual SkDiscardableMemory* create(size_t bytes) = 0; |
| 33 private: |
| 34 typedef SkRefCnt INHERITED; |
| 35 }; |
| 36 |
| 26 /** Must not be called while locked. | 37 /** Must not be called while locked. |
| 27 */ | 38 */ |
| 28 virtual ~SkDiscardableMemory() {} | 39 virtual ~SkDiscardableMemory() {} |
| 29 | 40 |
| 30 /** | 41 /** |
| 31 * Locks the memory, prevent it from being discarded. Once locked. you may | 42 * Locks the memory, prevent it from being discarded. Once locked. you may |
| 32 * obtain a pointer to that memory using the data() method. | 43 * obtain a pointer to that memory using the data() method. |
| 33 * | 44 * |
| 34 * lock() may return false, indicating that the underlying memory was | 45 * lock() may return false, indicating that the underlying memory was |
| 35 * discarded and that the lock failed. | 46 * discarded and that the lock failed. |
| 36 * | 47 * |
| 37 * Nested calls to lock are not allowed. | 48 * Nested calls to lock are not allowed. |
| 38 */ | 49 */ |
| 39 virtual bool lock() = 0; | 50 virtual bool lock() = 0; |
| 40 | 51 |
| 41 /** | 52 /** |
| 42 * Returns the current pointer for the discardable memory. This call is ONLY | 53 * Returns the current pointer for the discardable memory. This call is ONLY |
| 43 * valid when the discardable memory object is locked. | 54 * valid when the discardable memory object is locked. |
| 44 */ | 55 */ |
| 45 virtual void* data() = 0; | 56 virtual void* data() = 0; |
| 46 | 57 |
| 47 /** | 58 /** |
| 48 * Unlock the memory so that it can be purged by the system. Must be called | 59 * Unlock the memory so that it can be purged by the system. Must be called |
| 49 * after every successful lock call. | 60 * after every successful lock call. |
| 50 */ | 61 */ |
| 51 virtual void unlock() = 0; | 62 virtual void unlock() = 0; |
| 52 }; | 63 }; |
| 53 | 64 |
| 54 #endif | 65 #endif |
| OLD | NEW |