Flutter Engine
The Flutter Engine
GrGpuBuffer.cpp
Go to the documentation of this file.
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
9
13#include "src/gpu/ResourceKey.h"
16
17#include <cstdint>
18
20 GrAccessPattern pattern,
21 std::string_view label)
22 : GrGpuResource(gpu, label)
23 , fMapPtr(nullptr)
24 , fSizeInBytes(sizeInBytes)
25 , fAccessPattern(pattern)
26 , fIntendedType(type) {}
27
29 if (this->wasDestroyed()) {
30 return nullptr;
31 }
32 if (!fMapPtr) {
33 this->onMap(this->mapType());
34 }
35 return fMapPtr;
36}
37
39 if (this->wasDestroyed()) {
40 return;
41 }
43 this->onUnmap(this->mapType());
44 fMapPtr = nullptr;
45}
46
47bool GrGpuBuffer::isMapped() const { return SkToBool(fMapPtr); }
48
50 SkASSERT(!this->isMapped());
51
52 if (this->wasDestroyed()) {
53 return false;
54 }
55
57 return false;
58 }
59
60 return this->onClearToZero();
61}
62
63bool GrGpuBuffer::updateData(const void* src, size_t offset, size_t size, bool preserve) {
64 SkASSERT(!this->isMapped());
65 SkASSERT(size > 0 && offset + size <= fSizeInBytes);
67
68 if (this->wasDestroyed()) {
69 return false;
70 }
71
72 if (preserve) {
73 size_t a = this->getGpu()->caps()->bufferUpdateDataPreserveAlignment();
74 if (SkAlignTo(offset, a) != offset || SkAlignTo(size, a) != size) {
75 return false;
76 }
77 }
78
80 return false;
81 }
82
83 return this->onUpdateData(src, offset, size, preserve);
84}
85
87 GrGpuBufferType intendedType,
90 skgpu::ScratchKey::Builder builder(key, kType, 1 + (sizeof(size_t) + 3) / 4);
92 builder[1] = (uint32_t)size;
93 if (sizeof(size_t) > 4) {
94 builder[2] = (uint32_t)((uint64_t)size >> 32);
95 }
96}
97
98void GrGpuBuffer::computeScratchKey(skgpu::ScratchKey* key) const {
99 if (kDynamic_GrAccessPattern == fAccessPattern) {
100 ComputeScratchKeyForDynamicBuffer(fSizeInBytes, fIntendedType, key);
101 }
102}
GrGpuBufferType
Definition: GrTypesPriv.h:411
GrAccessPattern
Definition: GrTypesPriv.h:424
@ kDynamic_GrAccessPattern
Definition: GrTypesPriv.h:426
static constexpr size_t SkAlignTo(size_t x, size_t alignment)
Definition: SkAlign.h:33
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
constexpr uint32_t SkToU32(S x)
Definition: SkTo.h:26
GLenum type
size_t bufferUpdateDataPreserveAlignment() const
Definition: GrCaps.h:250
static void ComputeScratchKeyForDynamicBuffer(size_t size, GrGpuBufferType, skgpu::ScratchKey *)
Definition: GrGpuBuffer.cpp:86
size_t size() const final
Definition: GrGpuBuffer.h:34
bool clearToZero()
Definition: GrGpuBuffer.cpp:49
GrGpuBuffer(GrGpu *, size_t sizeInBytes, GrGpuBufferType, GrAccessPattern, std::string_view label)
Definition: GrGpuBuffer.cpp:19
void * map()
Definition: GrGpuBuffer.cpp:28
GrGpuBufferType intendedType() const
Definition: GrGpuBuffer.h:99
virtual bool onUpdateData(const void *src, size_t offset, size_t size, bool preserve)=0
virtual void onUnmap(MapType)=0
virtual bool onClearToZero()=0
bool isMapped() const
Definition: GrGpuBuffer.cpp:47
bool updateData(const void *src, size_t offset, size_t size, bool preserve)
Definition: GrGpuBuffer.cpp:63
virtual void onMap(MapType)=0
void * fMapPtr
Definition: GrGpuBuffer.h:119
void unmap()
Definition: GrGpuBuffer.cpp:38
GrGpu * getGpu() const
bool wasDestroyed() const
Definition: GrGpu.h:62
const GrCaps * caps() const
Definition: GrGpu.h:73
static ResourceType GenerateResourceType()
Definition: ResourceKey.cpp:16
uint32_t ResourceType
Definition: ResourceKey.h:200
struct MyStruct a[10]
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SeparatedVector2 offset