| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef _ANDROID_GRAPHICS_UTILS_H_ |
| 18 |
#define _ANDROID_GRAPHICS_UTILS_H_ |
| 19 |
|
| 20 |
#include "SkStream.h" |
| 21 |
|
| 22 |
#include <jni.h> |
| 23 |
#include <androidfw/Asset.h> |
| 24 |
|
| 25 |
namespace android { |
| 26 |
|
| 27 |
class AssetStreamAdaptor : public SkStreamRewindable { |
| 28 |
public: |
| 29 |
explicit AssetStreamAdaptor(Asset*); |
| 30 |
|
| 31 |
virtual bool rewind(); |
| 32 |
virtual size_t read(void* buffer, size_t size); |
| 33 |
virtual bool hasLength() const { return true; } |
| 34 |
virtual size_t getLength() const; |
| 35 |
virtual bool hasPosition() const; |
| 36 |
virtual size_t getPosition() const; |
| 37 |
virtual bool seek(size_t position); |
| 38 |
virtual bool move(long offset); |
| 39 |
virtual bool isAtEnd() const; |
| 40 |
|
| 41 |
protected: |
| 42 |
SkStreamRewindable* onDuplicate() const override; |
| 43 |
|
| 44 |
private: |
| 45 |
Asset* fAsset; |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
sk_sp<SkData> CopyAssetToData(Asset*); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
class AutoFDSeek { |
| 58 |
public: |
| 59 |
explicit AutoFDSeek(int fd) : fFD(fd) { |
| 60 |
fCurr = ::lseek(fd, 0, SEEK_CUR); |
| 61 |
} |
| 62 |
~AutoFDSeek() { |
| 63 |
if (fCurr >= 0) { |
| 64 |
::lseek(fFD, fCurr, SEEK_SET); |
| 65 |
} |
| 66 |
} |
| 67 |
private: |
| 68 |
int fFD; |
| 69 |
off64_t fCurr; |
| 70 |
}; |
| 71 |
|
| 72 |
jobject nullObjectReturn(const char msg[]); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
bool isSeekable(int descriptor); |
| 77 |
|
| 78 |
JNIEnv* get_env_or_die(JavaVM* jvm); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
JNIEnv* requireEnv(JavaVM* jvm); |
| 89 |
|
| 90 |
}; |
| 91 |
|
| 92 |
#endif |