• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 skgpu_graphite_Buffer_DEFINED
9 #define skgpu_graphite_Buffer_DEFINED
10 
11 #include "include/gpu/GpuTypes.h"
12 #include "src/gpu/graphite/Resource.h"
13 #include "src/gpu/graphite/ResourceTypes.h"
14 
15 namespace skgpu::graphite {
16 
17 class Buffer : public Resource {
18 public:
size()19     size_t size() const { return fSize; }
isProtected()20     Protected isProtected() const { return fIsProtected; }
21 
22     // TODO(b/262249983): Separate into mapRead(), mapWrite() methods.
23     // If the buffer is already mapped then pointer is returned. If an asyncMap() was started then
24     // it is waited on. Otherwise, a synchronous map is performed.
25     void* map();
26     // Starts a new asynchronous map.
27     void asyncMap(GpuFinishedProc = nullptr, GpuFinishedContext = nullptr);
28     // If the buffer is mapped then unmaps. If an async map is pending then it is cancelled.
29     void unmap();
30 
isMapped()31     bool isMapped() const { return fMapPtr; }
32 
33     // Returns true if mapped or an asyncMap was started and hasn't been completed or canceled.
34     virtual bool isUnmappable() const;
35 
getResourceType()36     const char* getResourceType() const override { return "Buffer"; }
37 
38 protected:
39     Buffer(const SharedContext* sharedContext,
40            size_t size,
41            Protected isProtected,
42            bool reusableRequiresPurgeable = false)
Resource(sharedContext,Ownership::kOwned,size,reusableRequiresPurgeable)43             : Resource(sharedContext,
44                        Ownership::kOwned,
45                        size,
46                        reusableRequiresPurgeable)
47             , fSize(size)
48             , fIsProtected(isProtected) {}
49 
50     void* fMapPtr = nullptr;
51 
52 private:
53     virtual void onMap() = 0;
54     virtual void onAsyncMap(GpuFinishedProc, GpuFinishedContext);
55     virtual void onUnmap() = 0;
56 
57     size_t    fSize;
58     Protected fIsProtected;
59 };
60 
61 } // namespace skgpu::graphite
62 
63 #endif // skgpu_graphite_Buffer_DEFINED
64