blob: 367a48fad9b93d9121b8c6fee2a4e1eb8d944055 [file] [log] [blame]
Leon Scroggins III0c01dbf2017-10-20 14:08:11 -04001#ifndef _ANDROID_GRAPHICS_BYTE_BUFFER_STREAM_ADAPTOR_H_
2#define _ANDROID_GRAPHICS_BYTE_BUFFER_STREAM_ADAPTOR_H_
3
4#include <jni.h>
5#include <memory>
6
7class SkStream;
8
9/**
10 * Create an adaptor for treating a java.nio.ByteBuffer as an SkStream.
11 *
12 * This will special case direct ByteBuffers, but not the case where a byte[]
13 * can be used directly. For that, use CreateByteArrayStreamAdaptor.
14 *
15 * @param jbyteBuffer corresponding to the java ByteBuffer. This method will
16 * add a global ref.
17 * @param initialPosition returned by ByteBuffer.position(). Decoding starts
18 * from here.
19 * @param limit returned by ByteBuffer.limit().
20 *
21 * Returns null on failure.
22 */
23std::unique_ptr<SkStream> CreateByteBufferStreamAdaptor(JNIEnv*, jobject jbyteBuffer,
24 size_t initialPosition, size_t limit);
25
26/**
27 * Create an adaptor for treating a Java byte[] as an SkStream.
28 *
29 * @param offset into the byte[] of the beginning of the data to use.
30 * @param length of data to use, starting from offset.
31 *
32 * Returns null on failure.
33 */
34std::unique_ptr<SkStream> CreateByteArrayStreamAdaptor(JNIEnv*, jbyteArray array, size_t offset,
35 size_t length);
36
37#endif // _ANDROID_GRAPHICS_BYTE_BUFFER_STREAM_ADAPTOR_H_