OLD | NEW |
---|---|
(Empty) | |
1 | |
2 /* | |
3 * Copyright 2015 Google Inc. | |
4 * | |
5 * Use of this source code is governed by a BSD-style license that can be | |
6 * found in the LICENSE file. | |
7 */ | |
8 | |
9 | |
10 #ifndef GrTransferBuffer_DEFINED | |
11 #define GrTransferBuffer_DEFINED | |
12 | |
13 #include "GrGpuResource.h" | |
14 | |
15 class GrTransferBuffer : public GrGpuResource { | |
16 public: | |
17 /** | |
18 * Maps the buffer to be written by the CPU. | |
19 * | |
20 * The previous content of the buffer is invalidated. It is an error | |
bsalomon
2015/12/02 16:38:31
Looks like these comments came from geometrybuffer
jvanverth1
2015/12/02 18:05:07
Done.
| |
21 * to draw from the buffer while it is mapped. It is an error to call map | |
22 * on an already mapped buffer. It may fail if the backend doesn't support | |
23 * mapping the buffer. If the buffer is CPU backed then it will always | |
24 * succeed and is a free operation. Must be matched by an unmap() call. | |
25 * Currently only one map at a time is supported (no nesting of | |
26 * map/unmap). | |
27 * | |
28 * Note that buffer mapping does not go through GrContext and therefore is | |
29 * not serialized with other operations. | |
30 * | |
31 * @return a pointer to the data or nullptr if the map fails. | |
32 */ | |
33 void* map() { return (fMapPtr = this->onMap()); } | |
34 | |
35 /** | |
36 * Unmaps the buffer. | |
37 * | |
38 * The pointer returned by the previous map call will no longer be valid. | |
39 */ | |
40 void unmap() { | |
41 SkASSERT(fMapPtr); | |
42 this->onUnmap(); | |
43 fMapPtr = nullptr; | |
44 } | |
45 | |
46 /** | |
47 * Returns the same ptr that map() returned at time of map or nullptr if the | |
48 * is not mapped. | |
49 * | |
50 * @return ptr to mapped buffer data or nullptr if buffer is not mapped. | |
51 */ | |
52 void* mapPtr() const { return fMapPtr; } | |
53 | |
54 /** | |
55 Queries whether the buffer has been mapped. | |
56 | |
57 @return true if the buffer is mapped, false otherwise. | |
58 */ | |
59 bool isMapped() const { return SkToBool(fMapPtr); } | |
60 | |
61 /** | |
62 * Updates the buffer data. | |
bsalomon
2015/12/02 16:38:31
Do we want this at all or should we just assume ma
jvanverth1
2015/12/02 18:05:07
BufferData is supported by PBOs, as far as I can t
| |
63 * | |
64 * The size of the buffer will be preserved. The src data will be | |
65 * placed at the beginning of the buffer and any remaining contents will | |
66 * be undefined. srcSizeInBytes must be <= to the buffer size. | |
67 * | |
68 * The buffer must not be mapped. | |
69 * | |
70 * Note that buffer updates do not go through GrContext and therefore are | |
71 * not serialized with other operations. | |
72 * | |
73 * @return returns true if the update succeeds, false otherwise. | |
74 */ | |
75 bool updateData(const void* src, size_t srcSizeInBytes) { | |
76 SkASSERT(!this->isMapped()); | |
77 SkASSERT(srcSizeInBytes <= fGpuMemorySize); | |
78 return this->onUpdateData(src, srcSizeInBytes); | |
79 } | |
80 | |
81 protected: | |
82 GrTransferBuffer(GrGpu* gpu, size_t gpuMemorySize) | |
83 : INHERITED(gpu, kUncached_LifeCycle) | |
84 , fGpuMemorySize(gpuMemorySize) { | |
85 } | |
86 | |
87 private: | |
88 virtual size_t onGpuMemorySize() const { return fGpuMemorySize; } | |
89 | |
90 virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0; | |
91 virtual void* onMap() = 0; | |
92 virtual void onUnmap() = 0; | |
93 | |
94 void* fMapPtr; | |
95 size_t fGpuMemorySize; | |
96 | |
97 typedef GrGpuResource INHERITED; | |
98 }; | |
99 | |
100 #endif | |
OLD | NEW |