Flutter Engine
The Flutter Engine
SkDiscardableMemory.h
Go to the documentation of this file.
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 SkDiscardableMemory_DEFINED
9#define SkDiscardableMemory_DEFINED
10
13
14/**
15 * Interface for discardable memory. Implementation is provided by the
16 * embedder.
17 */
19public:
20 /**
21 * Factory method that creates, initializes and locks an SkDiscardableMemory
22 * object. If either of these steps fails, a nullptr pointer will be returned.
23 */
24 static SkDiscardableMemory* Create(size_t bytes);
25
26 /**
27 * Factory class that creates, initializes and locks an SkDiscardableMemory
28 * object. If either of these steps fails, a nullptr pointer will be returned.
29 */
30 class Factory : public SkRefCnt {
31 public:
32 virtual SkDiscardableMemory* create(size_t bytes) = 0;
33 private:
34 using INHERITED = SkRefCnt;
35 };
36
37 /** Must not be called while locked.
38 */
40
41 /**
42 * Locks the memory, prevent it from being discarded. Once locked. you may
43 * obtain a pointer to that memory using the data() method.
44 *
45 * lock() may return false, indicating that the underlying memory was
46 * discarded and that the lock failed.
47 *
48 * Nested calls to lock are not allowed.
49 */
50 [[nodiscard]] virtual bool lock() = 0;
51
52 /**
53 * Returns the current pointer for the discardable memory. This call is ONLY
54 * valid when the discardable memory object is locked.
55 */
56 virtual void* data() = 0;
57
58 /**
59 * Unlock the memory so that it can be purged by the system. Must be called
60 * after every successful lock call.
61 */
62 virtual void unlock() = 0;
63
64protected:
68};
69
70#endif
static sk_sp< Effect > Create()
Definition: RefCntTest.cpp:117
#define SK_SPI
Definition: SkAPI.h:41
virtual SkDiscardableMemory * create(size_t bytes)=0
virtual bool lock()=0
SkDiscardableMemory(const SkDiscardableMemory &)=delete
virtual void unlock()=0
SkDiscardableMemory & operator=(const SkDiscardableMemory &)=delete
virtual void * data()=0
SkDiscardableMemory()=default