Flutter Engine
The Flutter Engine
Macros | Functions | Variables
jni_skqp.cpp File Reference
#include <mutex>
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
#include <jni.h>
#include <sys/stat.h>
#include "include/core/SkStream.h"
#include "include/private/base/SkTo.h"
#include "src/utils/SkOSPath.h"
#include "tools/ResourceFactory.h"
#include "tools/skqp/src/skqp.h"

Go to the source code of this file.

Macros

#define jassert(env, cond, ret)
 

Functions

JNIEXPORT void JNICALL Java_org_skia_skqp_SkQP_nInit (JNIEnv *, jobject, jobject, jstring)
 
JNIEXPORT jobjectArray JNICALL Java_org_skia_skqp_SkQP_nExecuteUnitTest (JNIEnv *, jobject, jint)
 
JNIEXPORT void JNICALL Java_org_skia_skqp_SkQP_nMakeReport (JNIEnv *, jobject)
 
static sk_sp< SkDataopen_asset_data (const char *path)
 
static jobjectArray make_java_string_array (JNIEnv *env, jint arraySize)
 
static void set_string_array_element (JNIEnv *env, jobjectArray a, const char *s, unsigned i)
 
template<typename T , typename F >
static jobjectArray to_java_string_array (JNIEnv *env, const std::vector< T > &array, F stringizeFn)
 
static std::string to_string (JNIEnv *env, jstring jString)
 
static const char * get_sksl_error_name (const SkQP::SkSLErrorTest &t)
 
static const char * get_sksl_error_shader_text (const SkQP::SkSLErrorTest &t)
 

Variables

static AAssetManager * sAAssetManager = nullptr
 
static AndroidAssetManager gAndroidAssetManager
 
static std::mutex gMutex
 
static SkQP gSkQP
 

Macro Definition Documentation

◆ jassert

#define jassert (   env,
  cond,
  ret 
)
Value:
do { if (!(cond)) { \
(env)->ThrowNew((env)->FindClass("java/lang/Exception"), \
__FILE__ ": assert(" #cond ") failed."); \
return ret; } } while (0)
Definition: __init__.py:1

Definition at line 83 of file jni_skqp.cpp.

Function Documentation

◆ get_sksl_error_name()

static const char * get_sksl_error_name ( const SkQP::SkSLErrorTest t)
static

Definition at line 124 of file jni_skqp.cpp.

124 {
125 return t.name.c_str();
126}
std::string name
Definition: skqp.h:47

◆ get_sksl_error_shader_text()

static const char * get_sksl_error_shader_text ( const SkQP::SkSLErrorTest t)
static

Definition at line 128 of file jni_skqp.cpp.

128 {
129 return t.shaderText.c_str();
130}
std::string shaderText
Definition: skqp.h:48

◆ Java_org_skia_skqp_SkQP_nExecuteUnitTest()

jobjectArray Java_org_skia_skqp_SkQP_nExecuteUnitTest ( JNIEnv *  env,
jobject  object,
jint  index 
)

Definition at line 164 of file jni_skqp.cpp.

166 {
167 std::vector<std::string> errors;
168 {
169 std::lock_guard<std::mutex> lock(gMutex);
170 jassert(env, index < (jint)gSkQP.getUnitTests().size(), nullptr);
172 }
173 if (errors.empty()) {
174 return nullptr;
175 }
176 jobjectArray array = make_java_string_array(env, errors.size());
177 for (size_t i = 0; i < errors.size(); ++i) {
178 set_string_array_element(env, array, errors[i].c_str(), i);
179 }
180 return (jobjectArray)env->NewGlobalRef(array);
181}
const std::vector< UnitTest > & getUnitTests() const
Definition: skqp.h:74
std::vector< std::string > executeTest(UnitTest)
Definition: skqp.cpp:147
static std::mutex gMutex
Definition: jni_skqp.cpp:80
static jobjectArray make_java_string_array(JNIEnv *env, jint arraySize)
Definition: jni_skqp.cpp:90
#define jassert(env, cond, ret)
Definition: jni_skqp.cpp:83
static SkQP gSkQP
Definition: jni_skqp.cpp:81
static void set_string_array_element(JNIEnv *env, jobjectArray a, const char *s, unsigned i)
Definition: jni_skqp.cpp:98

◆ Java_org_skia_skqp_SkQP_nInit()

void Java_org_skia_skqp_SkQP_nInit ( JNIEnv *  env,
jobject  object,
jobject  assetManager,
jstring  dataDir 
)

Definition at line 132 of file jni_skqp.cpp.

133 {
134 jclass SkQP_class = env->GetObjectClass(object);
135
136 // tools/Resources
138
139 std::string reportDirectory = to_string(env, dataDir);
140
141 jassert(env, assetManager,);
142 // This global must be set before using AndroidAssetManager
143 sAAssetManager = AAssetManager_fromJava(env, assetManager);
145
146 std::lock_guard<std::mutex> lock(gMutex);
147 gSkQP.init(&gAndroidAssetManager, reportDirectory.c_str());
148
149 const std::vector<SkQP::UnitTest>& unitTests = gSkQP.getUnitTests();
150 const std::vector<SkQP::SkSLErrorTest>& skslErrorTests = gSkQP.getSkSLErrorTests();
151
152 constexpr char kStringArrayType[] = "[Ljava/lang/String;";
153 env->SetObjectField(object,
154 env->GetFieldID(SkQP_class, "mUnitTests", kStringArrayType),
156 env->SetObjectField(object,
157 env->GetFieldID(SkQP_class, "mSkSLErrorTestName", kStringArrayType),
159 env->SetObjectField(object,
160 env->GetFieldID(SkQP_class, "mSkSLErrorTestShader", kStringArrayType),
162}
sk_sp< SkData >(* gResourceFactory)(const char *)
Definition: Resources.cpp:21
const std::vector< SkSLErrorTest > & getSkSLErrorTests() const
Definition: skqp.h:77
void init(SkQPAssetManager *assetManager, const char *reportDirectory)
Definition: skqp.cpp:120
static const char * GetUnitTestName(UnitTest)
Definition: skqp.cpp:114
static AndroidAssetManager gAndroidAssetManager
Definition: jni_skqp.cpp:79
static std::string to_string(JNIEnv *env, jstring jString)
Definition: jni_skqp.cpp:116
static sk_sp< SkData > open_asset_data(const char *path)
Definition: jni_skqp.cpp:32
static const char * get_sksl_error_shader_text(const SkQP::SkSLErrorTest &t)
Definition: jni_skqp.cpp:128
static const char * get_sksl_error_name(const SkQP::SkSLErrorTest &t)
Definition: jni_skqp.cpp:124
static AAssetManager * sAAssetManager
Definition: jni_skqp.cpp:30
static jobjectArray to_java_string_array(JNIEnv *env, const std::vector< T > &array, F stringizeFn)
Definition: jni_skqp.cpp:106

◆ Java_org_skia_skqp_SkQP_nMakeReport()

void Java_org_skia_skqp_SkQP_nMakeReport ( JNIEnv *  ,
jobject   
)

Definition at line 183 of file jni_skqp.cpp.

183 {
184 std::lock_guard<std::mutex> lock(gMutex);
186}
void makeReport()
Definition: skqp.cpp:192

◆ make_java_string_array()

static jobjectArray make_java_string_array ( JNIEnv *  env,
jint  arraySize 
)
static

Definition at line 90 of file jni_skqp.cpp.

90 {
91 jclass stringClass = env->FindClass("java/lang/String");
92 jassert(env, stringClass, nullptr);
93 jobjectArray jarray = env->NewObjectArray(arraySize, stringClass, nullptr);
94 jassert(env, jarray != nullptr, nullptr);
95 return jarray;
96}

◆ open_asset_data()

static sk_sp< SkData > open_asset_data ( const char *  path)
static

Definition at line 32 of file jni_skqp.cpp.

32 {
34 if (sAAssetManager) {
35 if (AAsset* asset = AAssetManager_open(sAAssetManager, path, AASSET_MODE_STREAMING)) {
36 if (size_t size = SkToSizeT(AAsset_getLength(asset))) {
38 int ret = AAsset_read(asset, data->writable_data(), size);
39 if (ret != SkToInt(size)) {
40 SK_ABORT("ERROR: AAsset_read != AAsset_getLength (%s)\n", path);
41 }
42 }
43 AAsset_close(asset);
44 }
45 }
46 return data;
47}
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31
constexpr int SkToInt(S x)
Definition: SkTo.h:29
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ set_string_array_element()

static void set_string_array_element ( JNIEnv *  env,
jobjectArray  a,
const char *  s,
unsigned  i 
)
static

Definition at line 98 of file jni_skqp.cpp.

98 {
99 jstring jstr = env->NewStringUTF(s);
100 jassert(env, jstr != nullptr,);
101 env->SetObjectArrayElement(a, (jsize)i, jstr);
102 env->DeleteLocalRef(jstr);
103}
struct MyStruct s
struct MyStruct a[10]

◆ to_java_string_array()

template<typename T , typename F >
static jobjectArray to_java_string_array ( JNIEnv *  env,
const std::vector< T > &  array,
F  stringizeFn 
)
static

Definition at line 106 of file jni_skqp.cpp.

108 {
109 jobjectArray jarray = make_java_string_array(env, (jint)array.size());
110 for (size_t i = 0; i < array.size(); ++i) {
111 set_string_array_element(env, jarray, stringizeFn(array[i]), i);
112 }
113 return jarray;
114}

◆ to_string()

static std::string to_string ( JNIEnv *  env,
jstring  jString 
)
static

Definition at line 116 of file jni_skqp.cpp.

116 {
117 const char* utf8String = env->GetStringUTFChars(jString, nullptr);
118 jassert(env, utf8String && utf8String[0], "");
119 std::string sString(utf8String);
120 env->ReleaseStringUTFChars(jString, utf8String);
121 return sString;
122}

Variable Documentation

◆ gAndroidAssetManager

AndroidAssetManager gAndroidAssetManager
static

Definition at line 79 of file jni_skqp.cpp.

◆ gMutex

std::mutex gMutex
static

Definition at line 80 of file jni_skqp.cpp.

◆ gSkQP

SkQP gSkQP
static

Definition at line 81 of file jni_skqp.cpp.

◆ sAAssetManager

AAssetManager* sAAssetManager = nullptr
static

Definition at line 30 of file jni_skqp.cpp.