Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef SkDiscardableMemory_DEFINED |
michael@0 | 9 | #define SkDiscardableMemory_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkRefCnt.h" |
michael@0 | 12 | #include "SkTypes.h" |
michael@0 | 13 | |
michael@0 | 14 | /** |
michael@0 | 15 | * Interface for discardable memory. Implementation is provided by the |
michael@0 | 16 | * embedder. |
michael@0 | 17 | */ |
michael@0 | 18 | class SK_API SkDiscardableMemory { |
michael@0 | 19 | public: |
michael@0 | 20 | /** |
michael@0 | 21 | * Factory method that creates, initializes and locks an SkDiscardableMemory |
michael@0 | 22 | * object. If either of these steps fails, a NULL pointer will be returned. |
michael@0 | 23 | */ |
michael@0 | 24 | static SkDiscardableMemory* Create(size_t bytes); |
michael@0 | 25 | |
michael@0 | 26 | /** |
michael@0 | 27 | * Factory class that creates, initializes and locks an SkDiscardableMemory |
michael@0 | 28 | * object. If either of these steps fails, a NULL pointer will be returned. |
michael@0 | 29 | */ |
michael@0 | 30 | class Factory : public SkRefCnt { |
michael@0 | 31 | public: |
michael@0 | 32 | virtual SkDiscardableMemory* create(size_t bytes) = 0; |
michael@0 | 33 | private: |
michael@0 | 34 | typedef SkRefCnt INHERITED; |
michael@0 | 35 | }; |
michael@0 | 36 | |
michael@0 | 37 | /** Must not be called while locked. |
michael@0 | 38 | */ |
michael@0 | 39 | virtual ~SkDiscardableMemory() {} |
michael@0 | 40 | |
michael@0 | 41 | /** |
michael@0 | 42 | * Locks the memory, prevent it from being discarded. Once locked. you may |
michael@0 | 43 | * obtain a pointer to that memory using the data() method. |
michael@0 | 44 | * |
michael@0 | 45 | * lock() may return false, indicating that the underlying memory was |
michael@0 | 46 | * discarded and that the lock failed. |
michael@0 | 47 | * |
michael@0 | 48 | * Nested calls to lock are not allowed. |
michael@0 | 49 | */ |
michael@0 | 50 | virtual bool lock() = 0; |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * Returns the current pointer for the discardable memory. This call is ONLY |
michael@0 | 54 | * valid when the discardable memory object is locked. |
michael@0 | 55 | */ |
michael@0 | 56 | virtual void* data() = 0; |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Unlock the memory so that it can be purged by the system. Must be called |
michael@0 | 60 | * after every successful lock call. |
michael@0 | 61 | */ |
michael@0 | 62 | virtual void unlock() = 0; |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | #endif |