From 8f3c3e284155ff26a23c29a089305bdb0a6ab7e4 Mon Sep 17 00:00:00 2001 From: eguven Date: Fri, 19 Oct 2018 03:14:26 -0700 Subject: [PATCH] Add GlUtil createBuffer overload which doesn't copy values ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217846755 --- .../android/exoplayer2/util/GlUtil.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/GlUtil.java b/library/core/src/main/java/com/google/android/exoplayer2/util/GlUtil.java index 72a782c2ac..df22e6dc2e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/GlUtil.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/GlUtil.java @@ -95,14 +95,23 @@ public final class GlUtil { return program; } - /** Allocates a FloatBuffer with the given data. */ + /** + * Allocates a FloatBuffer with the given data. + * + * @param data Used to initialize the new buffer. + */ public static FloatBuffer createBuffer(float[] data) { - ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length * C.BYTES_PER_FLOAT); - byteBuffer.order(ByteOrder.nativeOrder()); - FloatBuffer buffer = byteBuffer.asFloatBuffer(); - buffer.put(data); - buffer.flip(); - return buffer; + return (FloatBuffer) createBuffer(data.length).put(data).flip(); + } + + /** + * Allocates a FloatBuffer. + * + * @param capacity The new buffer's capacity, in floats. + */ + public static FloatBuffer createBuffer(int capacity) { + ByteBuffer byteBuffer = ByteBuffer.allocateDirect(capacity * C.BYTES_PER_FLOAT); + return byteBuffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); } /**