Coverage Report

Created: 2024-05-20 07:14

/src/skia/src/gpu/graphite/Buffer.h
Line
Count
Source (jump to first uncovered line)
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:
19
0
    size_t size() const { return fSize; }
20
21
    // TODO(b/262249983): Separate into mapRead(), mapWrite() methods.
22
    // If the buffer is already mapped then pointer is returned. If an asyncMap() was started then
23
    // it is waited on. Otherwise, a synchronous map is performed.
24
    void* map();
25
    // Starts a new asynchronous map.
26
    void asyncMap(GpuFinishedProc = nullptr, GpuFinishedContext = nullptr);
27
    // If the buffer is mapped then unmaps. If an async map is pending then it is cancelled.
28
    void unmap();
29
30
0
    bool isMapped() const { return fMapPtr; }
31
32
    // Returns true if mapped or an asyncMap was started and hasn't been completed or canceled.
33
    virtual bool isUnmappable() const;
34
35
0
    const char* getResourceType() const override { return "Buffer"; }
36
37
protected:
38
    Buffer(const SharedContext* sharedContext,
39
           size_t size,
40
           bool commandBufferRefsAsUsageRefs = false)
41
            : Resource(sharedContext,
42
                       Ownership::kOwned,
43
                       skgpu::Budgeted::kYes,
44
                       size,
45
                       /*commandBufferRefsAsUsageRefs=*/commandBufferRefsAsUsageRefs)
46
0
            , fSize(size) {}
47
48
    void* fMapPtr = nullptr;
49
50
private:
51
    virtual void onMap() = 0;
52
    virtual void onAsyncMap(GpuFinishedProc, GpuFinishedContext);
53
    virtual void onUnmap() = 0;
54
55
    size_t             fSize;
56
};
57
58
} // namespace skgpu::graphite
59
60
#endif // skgpu_graphite_Buffer_DEFINED