Flutter Engine
The Flutter Engine
Utils.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 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
8#include <jni.h>
9
10#include <string>
14
15namespace jetski {
16namespace utils {
17
18// RAII helper for jstring -> cstring conversions
19class CString {
20public:
21 CString(JNIEnv* env, const jstring& jstr)
22 : fEnv(env)
23 , fJString(jstr)
24 , fCString(env->GetStringUTFChars(jstr, nullptr))
25 {}
26
28 fEnv->ReleaseStringUTFChars(fJString, fCString);
29 }
30
31 const char* str() const { return fCString; }
32 operator const char*() const { return fCString; }
33
34private:
35 JNIEnv* fEnv;
36 const jstring& fJString;
37 const char* fCString;
38
39 CString(CString&&) = delete;
40 CString(const CString&) = delete;
41 CString& operator=(CString&&) = delete;
42 CString& operator=(const CString&) = delete;
43};
44
45// RAII helper for jstring -> u16String conversions
46class U16String {
47public:
48 U16String(JNIEnv* env, const jstring& jstr)
49 : fEnv(env)
50 , fJString(jstr)
51 , fU16String(env->GetStringChars(jstr, nullptr))
52 {}
53
55 fEnv->ReleaseStringChars(fJString, fU16String);
56 }
57
58 operator const char16_t*() const { return reinterpret_cast<const char16_t*>(fU16String); }
59
60private:
61 JNIEnv* fEnv;
62 const jstring& fJString;
63 const jchar* fU16String;
64
65
66 U16String(U16String&&) = delete;
67 U16String(const U16String&) = delete;
68 U16String& operator=(U16String&&) = delete;
69 U16String& operator=(const U16String&) = delete;
70};
71
72// RAII helper for float array access
73class CFloats {
74public:
75 CFloats(JNIEnv* env, const jfloatArray& jfloats)
76 : fEnv(env)
77 , fJFloats(jfloats)
78 , fCFloats(env->GetFloatArrayElements(jfloats, nullptr))
79 {}
80
82 fEnv->ReleaseFloatArrayElements(fJFloats, fCFloats, 0);
83 }
84
85 operator const float*() const { return fCFloats; }
86
87private:
88 JNIEnv* fEnv;
89 const jfloatArray& fJFloats;
90 float* fCFloats;
91
92
93 CFloats(CFloats&&) = delete;
94 CFloats(const CFloats&) = delete;
95 CFloats& operator=(CFloats&&) = delete;
96 CFloats& operator=(const CFloats&) = delete;
97};
98
99SkSamplingOptions SamplingOptions(jint, jfloat, jfloat);
100SkTileMode TileMode(jint);
102
103} // namespace utils
104} // namespace jetski
SkBlendMode
Definition: SkBlendMode.h:38
SkTileMode
Definition: SkTileMode.h:13
CFloats(JNIEnv *env, const jfloatArray &jfloats)
Definition: Utils.h:75
CString(JNIEnv *env, const jstring &jstr)
Definition: Utils.h:21
const char * str() const
Definition: Utils.h:31
U16String(JNIEnv *env, const jstring &jstr)
Definition: Utils.h:48
Definition: __init__.py:1
SkTileMode TileMode(jint tm)
Definition: Utils.cpp:26
SkBlendMode BlendMode(jint bm)
Definition: Utils.cpp:36
SkSamplingOptions SamplingOptions(jint desc, jfloat coeffB, jfloat coeffC)
Definition: Utils.cpp:13
Definition: Utils.cpp:10
Definition: utils.py:1