Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Image.cpp
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 "include/core/SkData.h"
12#include "include/core/SkM44.h"
18
19namespace {
20
21jlong Image_Create(JNIEnv* env, jobject, jbyteArray jdata) {
22 auto size = env->GetArrayLength(jdata);
23 auto* data = env->GetByteArrayElements(jdata, nullptr);
25
26 env->ReleaseByteArrayElements(jdata, data, 0);
27
28 return reinterpret_cast<jlong>(image.release());
29}
30
31void Image_Release(JNIEnv*, jobject, jlong native_instance) {
32 SkSafeUnref(reinterpret_cast<const SkImage*>(native_instance));
33}
34
35jint Image_GetWidth(JNIEnv*, jobject, jlong native_instance) {
36 const auto* image = reinterpret_cast<const SkImage*>(native_instance);
37 return image ? image->width() : 0;
38}
39
40jint Image_GetHeight(JNIEnv*, jobject, jlong native_instance) {
41 const auto* image = reinterpret_cast<const SkImage*>(native_instance);
42 return image ? image->height() : 0;
43}
44
45jlong Image_MakeShader(JNIEnv*, jobject, jlong native_instance, jint jtmx, jint jtmy,
46 jint sampling_desc, jfloat sampling_b, jfloat sampling_c,
47 jlong native_matrix) {
48 sk_sp<SkShader> shader;
49
50 if (const auto* image = reinterpret_cast<const SkImage*>(native_instance)) {
51 const auto tmx = jetski::utils::TileMode(jtmx),
53 const auto sampling = jetski::utils::SamplingOptions(sampling_desc,
54 sampling_b, sampling_c);
55
56 const auto* lm = reinterpret_cast<const SkM44*>(native_matrix);
57 shader = lm
58 ? image->makeShader(tmx, tmy, sampling, lm->asM33())
59 : image->makeShader(tmx, tmy, sampling);
60 }
61
62 return reinterpret_cast<jlong>(shader.release());
63}
64
65} // namespace
66
68 static const JNINativeMethod methods[] = {
69 {"nCreate" , "([B)J" , reinterpret_cast<void*>(Image_Create) },
70 {"nRelease" , "(J)V" , reinterpret_cast<void*>(Image_Release) },
71
72 {"nGetWidth" , "(J)I" , reinterpret_cast<void*>(Image_GetWidth) },
73 {"nGetHeight" , "(J)I" , reinterpret_cast<void*>(Image_GetHeight)},
74
75 {"nMakeShader", "(JIIIFFJ)J" , reinterpret_cast<void*>(Image_MakeShader)},
76 };
77
78 const auto clazz = env->FindClass("org/skia/jetski/Image");
79 return clazz
80 ? env->RegisterNatives(clazz, methods, std::size(methods))
81 : JNI_ERR;
82}
static void SkSafeUnref(T *obj)
Definition SkRefCnt.h:149
constexpr size_t SkToSizeT(S x)
Definition SkTo.h:31
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition SkData.cpp:111
int width() const
Definition SkImage.h:285
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkImage.cpp:179
int height() const
Definition SkImage.h:291
Definition SkM44.h:150
T * release()
Definition SkRefCnt.h:324
sk_sp< SkImage > image
Definition examples.cpp:29
int register_jetski_Image(JNIEnv *env)
Definition Image.cpp:67
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SkSamplingOptions sampling
Definition SkRecords.h:337
Definition __init__.py:1
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
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
SkTileMode TileMode(jint tm)
Definition Utils.cpp:26
SkSamplingOptions SamplingOptions(jint desc, jfloat coeffB, jfloat coeffC)
Definition Utils.cpp:13
SkTileMode tmy
SkTileMode tmx