Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
src
gpu
ganesh
GrRingBuffer.h
Go to the documentation of this file.
1
/*
2
* Copyright 2020 Google LLC
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 GrRingBuffer_DEFINED
9
#define GrRingBuffer_DEFINED
10
11
#include "
src/gpu/ganesh/GrGpuBuffer.h
"
12
13
#include <vector>
14
15
class
GrGpu
;
16
17
/**
18
* A wrapper for a GPU buffer that allocates slices in a continuous ring.
19
*
20
* It's assumed that suballocate and startSubmit are always called in the same thread,
21
* and that finishSubmit could be called in a separate thread.
22
*/
23
class
GrRingBuffer
{
24
public
:
25
GrRingBuffer
(
GrGpu
* gpu,
size_t
size
,
size_t
alignment,
GrGpuBufferType
intendedType)
26
: fGpu(gpu)
27
, fTotalSize(
size
)
28
, fAlignment(alignment)
29
, fType(intendedType)
30
, fNewAllocation(false)
31
, fHead(0)
32
, fTail(0)
33
, fGenID(0) {
34
// We increment fHead and fTail without bound and let overflow handle any wrapping.
35
// Because of this, size needs to be a power of two.
36
SkASSERT
(
SkIsPow2
(
size
));
37
}
38
39
struct
Slice
{
40
GrGpuBuffer
*
fBuffer
;
41
size_t
fOffset
;
42
};
43
Slice
suballocate
(
size_t
size
);
44
45
// Backends should call startSubmit() at submit time
46
void
startSubmit
(
GrGpu
*);
47
48
size_t
size
()
const
{
return
fTotalSize; }
49
50
private
:
51
size_t
getAllocationOffset(
size_t
size
);
52
struct
SubmitData {
53
GrRingBuffer
* fOwner;
54
size_t
fLastHead;
55
size_t
fGenID;
56
};
57
static
void
FinishSubmit(
void
*);
58
59
GrGpu
* fGpu;
60
sk_sp<GrGpuBuffer>
fCurrentBuffer;
61
std::vector<sk_sp<GrGpuBuffer>> fPreviousBuffers;
// previous buffers we've used in this submit
62
size_t
fTotalSize;
63
size_t
fAlignment;
64
GrGpuBufferType
fType;
65
bool
fNewAllocation;
// true if there's been a new allocation in this submit
66
size_t
fHead;
// where we start allocating
67
size_t
fTail;
// where we start deallocating
68
uint64_t fGenID;
// incremented when createBuffer is called
69
};
70
71
#endif
GrGpuBuffer.h
GrGpuBufferType
GrGpuBufferType
Definition
GrTypesPriv.h:410
SkASSERT
#define SkASSERT(cond)
Definition
SkAssert.h:116
SkIsPow2
constexpr bool SkIsPow2(T value)
Definition
SkMath.h:51
GrGpuBuffer
Definition
GrGpuBuffer.h:24
GrGpu
Definition
GrGpu.h:62
GrRingBuffer
Definition
GrRingBuffer.h:23
GrRingBuffer::startSubmit
void startSubmit(GrGpu *)
Definition
GrRingBuffer.cpp:87
GrRingBuffer::GrRingBuffer
GrRingBuffer(GrGpu *gpu, size_t size, size_t alignment, GrGpuBufferType intendedType)
Definition
GrRingBuffer.h:25
GrRingBuffer::suballocate
Slice suballocate(size_t size)
Definition
GrRingBuffer.cpp:57
GrRingBuffer::size
size_t size() const
Definition
GrRingBuffer.h:48
sk_sp
Definition
SkRefCnt.h:220
GrRingBuffer::Slice
Definition
GrRingBuffer.h:39
GrRingBuffer::Slice::fOffset
size_t fOffset
Definition
GrRingBuffer.h:41
GrRingBuffer::Slice::fBuffer
GrGpuBuffer * fBuffer
Definition
GrRingBuffer.h:40
Generated on Fri Apr 26 2024 06:17:05 for Flutter Engine by
1.9.8