SkDiscardableMemory.h 1.8 KB

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