1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkDiscardableMemory.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +/* 1.5 + * Copyright 2013 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkDiscardableMemory_DEFINED 1.12 +#define SkDiscardableMemory_DEFINED 1.13 + 1.14 +#include "SkRefCnt.h" 1.15 +#include "SkTypes.h" 1.16 + 1.17 +/** 1.18 + * Interface for discardable memory. Implementation is provided by the 1.19 + * embedder. 1.20 + */ 1.21 +class SK_API SkDiscardableMemory { 1.22 +public: 1.23 + /** 1.24 + * Factory method that creates, initializes and locks an SkDiscardableMemory 1.25 + * object. If either of these steps fails, a NULL pointer will be returned. 1.26 + */ 1.27 + static SkDiscardableMemory* Create(size_t bytes); 1.28 + 1.29 + /** 1.30 + * Factory class that creates, initializes and locks an SkDiscardableMemory 1.31 + * object. If either of these steps fails, a NULL pointer will be returned. 1.32 + */ 1.33 + class Factory : public SkRefCnt { 1.34 + public: 1.35 + virtual SkDiscardableMemory* create(size_t bytes) = 0; 1.36 + private: 1.37 + typedef SkRefCnt INHERITED; 1.38 + }; 1.39 + 1.40 + /** Must not be called while locked. 1.41 + */ 1.42 + virtual ~SkDiscardableMemory() {} 1.43 + 1.44 + /** 1.45 + * Locks the memory, prevent it from being discarded. Once locked. you may 1.46 + * obtain a pointer to that memory using the data() method. 1.47 + * 1.48 + * lock() may return false, indicating that the underlying memory was 1.49 + * discarded and that the lock failed. 1.50 + * 1.51 + * Nested calls to lock are not allowed. 1.52 + */ 1.53 + virtual bool lock() = 0; 1.54 + 1.55 + /** 1.56 + * Returns the current pointer for the discardable memory. This call is ONLY 1.57 + * valid when the discardable memory object is locked. 1.58 + */ 1.59 + virtual void* data() = 0; 1.60 + 1.61 + /** 1.62 + * Unlock the memory so that it can be purged by the system. Must be called 1.63 + * after every successful lock call. 1.64 + */ 1.65 + virtual void unlock() = 0; 1.66 +}; 1.67 + 1.68 +#endif