Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b39c4a3

Browse files
authored
Flutter GPU: Add GpuContext.createHostBuffer (#49822)
Just a quick fix to use the same pattern as other GpuContext derivative things.
1 parent 0104ff8 commit b39c4a3

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

impeller/fixtures/dart_tests.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void instantiateDefaultContext() {
2121

2222
@pragma('vm:entry-point')
2323
void canEmplaceHostBuffer() {
24-
final gpu.HostBuffer hostBuffer = gpu.HostBuffer(gpu.gpuContext);
24+
final gpu.HostBuffer hostBuffer = gpu.gpuContext.createHostBuffer();
2525

2626
final gpu.BufferView view0 = hostBuffer
2727
.emplace(Int8List.fromList(<int>[0, 1, 2, 3]).buffer.asByteData());
@@ -216,7 +216,7 @@ void uniformBindFailsForInvalidHostBufferOffset() {
216216
final gpu.RenderPipeline pipeline = createUnlitRenderPipeline();
217217
encoder.bindPipeline(pipeline);
218218

219-
final gpu.HostBuffer transients = gpu.HostBuffer(gpu.gpuContext);
219+
final gpu.HostBuffer transients = gpu.gpuContext.createHostBuffer();
220220
final gpu.BufferView vertInfoData = transients.emplace(float32(<double>[
221221
1, 0, 0, 0, // mvp
222222
0, 1, 0, 0, // mvp
@@ -262,7 +262,7 @@ void canCreateRenderPassAndSubmit() {
262262
encoder.setColorBlendEnable(true);
263263
encoder.setColorBlendEquation(gpu.ColorBlendEquation());
264264

265-
final gpu.HostBuffer transients = gpu.HostBuffer(gpu.gpuContext);
265+
final gpu.HostBuffer transients = gpu.gpuContext.createHostBuffer();
266266
final gpu.BufferView vertices = transients.emplace(float32(<double>[
267267
-0.5, -0.5, //
268268
0.5, 0.5, //

lib/gpu/lib/src/buffer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ base class DeviceBuffer extends NativeFieldWrapperClass1 with Buffer {
135135
/// and automatically inserts padding between emplaced data if necessary.
136136
base class HostBuffer extends NativeFieldWrapperClass1 with Buffer {
137137
/// Creates a new HostBuffer.
138-
HostBuffer(GpuContext gpuContext) {
138+
HostBuffer._initialize(GpuContext gpuContext) {
139139
_initialize(gpuContext);
140140
}
141141

lib/gpu/lib/src/context.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ base class GpuContext extends NativeFieldWrapperClass1 {
6969
return result.isValid ? result : null;
7070
}
7171

72+
HostBuffer createHostBuffer() {
73+
return HostBuffer._initialize(this);
74+
}
75+
7276
/// Allocates a new texture in GPU-resident memory.
7377
///
7478
/// Returns [null] if the [Texture] creation failed.

0 commit comments

Comments
 (0)