Coverage Report

Created: 2024-05-20 07:14

/src/skia/src/gpu/ganesh/GrGpuBuffer.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2019 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
#include "src/gpu/ganesh/GrGpuBuffer.h"
9
10
#include "include/private/base/SkAlign.h"
11
#include "include/private/base/SkAssert.h"
12
#include "include/private/base/SkTo.h"
13
#include "src/gpu/ResourceKey.h"
14
#include "src/gpu/ganesh/GrCaps.h"
15
#include "src/gpu/ganesh/GrGpu.h"
16
17
#include <cstdint>
18
19
GrGpuBuffer::GrGpuBuffer(GrGpu* gpu, size_t sizeInBytes, GrGpuBufferType type,
20
                         GrAccessPattern pattern,
21
                         std::string_view label)
22
        : GrGpuResource(gpu, label)
23
        , fMapPtr(nullptr)
24
        , fSizeInBytes(sizeInBytes)
25
        , fAccessPattern(pattern)
26
73.9k
        , fIntendedType(type) {}
27
28
853
void* GrGpuBuffer::map() {
29
853
    if (this->wasDestroyed()) {
30
0
        return nullptr;
31
0
    }
32
853
    if (!fMapPtr) {
33
853
        this->onMap(this->mapType());
34
853
    }
35
853
    return fMapPtr;
36
853
}
37
38
0
void GrGpuBuffer::unmap() {
39
0
    if (this->wasDestroyed()) {
40
0
        return;
41
0
    }
42
0
    SkASSERT(fMapPtr);
43
0
    this->onUnmap(this->mapType());
44
0
    fMapPtr = nullptr;
45
0
}
Unexecuted instantiation: GrGpuBuffer::unmap()
Unexecuted instantiation: GrGpuBuffer::unmap()
46
47
76.3k
bool GrGpuBuffer::isMapped() const { return SkToBool(fMapPtr); }
48
49
0
bool GrGpuBuffer::clearToZero() {
50
0
    SkASSERT(!this->isMapped());
51
52
0
    if (this->wasDestroyed()) {
53
0
        return false;
54
0
    }
55
56
0
    if (this->intendedType()  == GrGpuBufferType::kXferGpuToCpu) {
57
0
        return false;
58
0
    }
59
60
0
    return this->onClearToZero();
61
0
}
Unexecuted instantiation: GrGpuBuffer::clearToZero()
Unexecuted instantiation: GrGpuBuffer::clearToZero()
62
63
74.3k
bool GrGpuBuffer::updateData(const void* src, size_t offset, size_t size, bool preserve) {
64
74.3k
    SkASSERT(!this->isMapped());
65
74.3k
    SkASSERT(size > 0 && offset + size <= fSizeInBytes);
66
74.3k
    SkASSERT(src);
67
68
74.3k
    if (this->wasDestroyed()) {
69
0
        return false;
70
0
    }
71
72
74.3k
    if (preserve) {
73
0
        size_t a = this->getGpu()->caps()->bufferUpdateDataPreserveAlignment();
74
0
        if (SkAlignTo(offset, a) != offset || SkAlignTo(size, a) != size) {
75
0
            return false;
76
0
        }
77
0
    }
78
79
74.3k
    if (this->intendedType() == GrGpuBufferType::kXferGpuToCpu) {
80
0
        return false;
81
0
    }
82
83
74.3k
    return this->onUpdateData(src, offset, size, preserve);
84
74.3k
}
GrGpuBuffer::updateData(void const*, unsigned long, unsigned long, bool)
Line
Count
Source
63
74.3k
bool GrGpuBuffer::updateData(const void* src, size_t offset, size_t size, bool preserve) {
64
74.3k
    SkASSERT(!this->isMapped());
65
74.3k
    SkASSERT(size > 0 && offset + size <= fSizeInBytes);
66
74.3k
    SkASSERT(src);
67
68
74.3k
    if (this->wasDestroyed()) {
69
0
        return false;
70
0
    }
71
72
74.3k
    if (preserve) {
73
0
        size_t a = this->getGpu()->caps()->bufferUpdateDataPreserveAlignment();
74
0
        if (SkAlignTo(offset, a) != offset || SkAlignTo(size, a) != size) {
75
0
            return false;
76
0
        }
77
0
    }
78
79
74.3k
    if (this->intendedType() == GrGpuBufferType::kXferGpuToCpu) {
80
0
        return false;
81
0
    }
82
83
74.3k
    return this->onUpdateData(src, offset, size, preserve);
84
74.3k
}
Unexecuted instantiation: GrGpuBuffer::updateData(void const*, unsigned long, unsigned long, bool)
85
86
void GrGpuBuffer::ComputeScratchKeyForDynamicBuffer(size_t size,
87
                                                    GrGpuBufferType intendedType,
88
146k
                                                    skgpu::ScratchKey* key) {
89
146k
    static const skgpu::ScratchKey::ResourceType kType = skgpu::ScratchKey::GenerateResourceType();
90
146k
    skgpu::ScratchKey::Builder builder(key, kType, 1 + (sizeof(size_t) + 3) / 4);
91
146k
    builder[0] = SkToU32(intendedType);
92
146k
    builder[1] = (uint32_t)size;
93
146k
    if (sizeof(size_t) > 4) {
94
146k
        builder[2] = (uint32_t)((uint64_t)size >> 32);
95
146k
    }
96
146k
}
97
98
73.9k
void GrGpuBuffer::computeScratchKey(skgpu::ScratchKey* key) const {
99
73.9k
    if (kDynamic_GrAccessPattern == fAccessPattern) {
100
72.8k
        ComputeScratchKeyForDynamicBuffer(fSizeInBytes, fIntendedType, key);
101
72.8k
    }
102
73.9k
}