Flutter Engine
The Flutter Engine
GrEagerVertexAllocator.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 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
9
11
12//-------------------------------------------------------------------------------------------------
13void* GrEagerDynamicVertexAllocator::lock(size_t stride, int eagerCount) {
14 SkASSERT(!fLockCount);
15 SkASSERT(eagerCount);
16 if (void* data = fTarget->makeVertexSpace(stride, eagerCount, fVertexBuffer, fBaseVertex)) {
17 fLockStride = stride;
18 fLockCount = eagerCount;
19 return data;
20 }
21 fVertexBuffer->reset();
22 *fBaseVertex = 0;
23 return nullptr;
24}
25
27 SkASSERT(fLockCount);
28 SkASSERT(actualCount <= fLockCount);
29 fTarget->putBackVertices(fLockCount - actualCount, fLockStride);
30 if (!actualCount) {
31 fVertexBuffer->reset();
32 *fBaseVertex = 0;
33 }
34 fLockCount = 0;
35}
36
37//-------------------------------------------------------------------------------------------------
38void* GrCpuVertexAllocator::lock(size_t stride, int eagerCount) {
39 SkASSERT(!fLockStride && !fVertices && !fVertexData);
40 SkASSERT(stride && eagerCount);
41
42 fVertices = sk_malloc_throw(eagerCount * stride);
43 fLockStride = stride;
44
45 return fVertices;
46}
47
48void GrCpuVertexAllocator::unlock(int actualCount) {
49 SkASSERT(fLockStride && fVertices && !fVertexData);
50
51 fVertices = sk_realloc_throw(fVertices, actualCount * fLockStride);
52
53 fVertexData = GrThreadSafeCache::MakeVertexData(fVertices, actualCount, fLockStride);
54
55 fVertices = nullptr;
56 fLockStride = 0;
57}
58
60 SkASSERT(!fLockStride && !fVertices && fVertexData);
61
62 return std::move(fVertexData);
63}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void * sk_malloc_throw(size_t size)
Definition: SkMalloc.h:67
SK_API void * sk_realloc_throw(void *buffer, size_t size)
sk_sp< GrThreadSafeCache::VertexData > detachVertexData()
void * lock(size_t stride, int eagerCount) override
void unlock(int actualCount) override
void * lock(size_t stride, int eagerCount) final
void unlock(int actualCount) final
virtual void * makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp< const GrBuffer > *, int *startVertex)=0
virtual void putBackVertices(int vertices, size_t vertexStride)=0
static sk_sp< VertexData > MakeVertexData(const void *vertices, int vertexCount, size_t vertexSize)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63