Flutter Engine
The Flutter Engine
ImageFilter.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
14
15namespace {
16
17static void ImageFilter_Release(JNIEnv* env, jobject, jlong native_imageFilter) {
18 SkSafeUnref(reinterpret_cast<SkImageFilter*>(native_imageFilter));
19}
20
21static long ImageFilter_DistantLitDiffuse(JNIEnv* env, jobject, jfloat x, jfloat y, jfloat z,
22 jfloat r, jfloat g, jfloat b,
23 jfloat surfaceScale, jfloat kd,
24 jlong native_input) {
25 SkPoint3 direction = SkPoint3::Make(x, y, z);
26 auto color = SkColor4f{r, g, b, 1}.toSkColor();
27 auto input = sk_ref_sp(reinterpret_cast<SkImageFilter*>(native_input));
28 auto filter = SkImageFilters::DistantLitDiffuse(direction, color, surfaceScale, kd, std::move(input));
29 return reinterpret_cast<jlong>(filter.release());
30}
31
32static long ImageFilter_Blur(JNIEnv* env, jobject, jfloat sigmaX, jfloat sigmaY,
33 jint jTileMode, jfloat l, jfloat t, jfloat r,
34 jfloat b, jlong native_input) {
35 auto input = sk_ref_sp(reinterpret_cast<SkImageFilter*>(native_input));
36 auto filter = SkImageFilters::Blur(sigmaX, sigmaY,
37 jetski::utils::TileMode(jTileMode),
38 std::move(input), SkRect::MakeLTRB(l,t,r,b));
39 return reinterpret_cast<jlong>(filter.release());
40}
41
42static long ImageFilter_DropShadow(JNIEnv* env, jobject, jfloat dx, jfloat dy,
43 jfloat sigmaX, jfloat sigmaY,
44 jfloat r, jfloat g, jfloat b,
45 jlong native_input) {
46 auto color = SkColor4f{r, g, b, 1}.toSkColor();
47 auto input = sk_ref_sp(reinterpret_cast<SkImageFilter*>(native_input));
48 auto filter = SkImageFilters::DropShadow(dx, dy, sigmaX, sigmaY, color, std::move(input));
49 return reinterpret_cast<jlong>(filter.release());
50}
51
52static long ImageFilter_Blend(JNIEnv* env, jobject, jint bm, jlong background, jlong foreground) {
53 auto bg = sk_ref_sp(reinterpret_cast<SkImageFilter*>(background));
54 auto fg = sk_ref_sp(reinterpret_cast<SkImageFilter*>(foreground));
55 auto filter = SkImageFilters::Blend(jetski::utils::BlendMode(bm), std::move(bg), std::move(fg));
56 return reinterpret_cast<jlong>(filter.release());
57}
58
59static long ImageFilter_Image(JNIEnv* env, jobject, jlong native_image) {
60 auto image = sk_ref_sp(reinterpret_cast<SkImage*>(native_image));
61 auto filter = SkImageFilters::Image(std::move(image), SkFilterMode::kLinear);
62 return reinterpret_cast<jlong>(filter.release());
63}
64
65} // namespace
66
68 static const JNINativeMethod methods[] = {
69 {"nRelease" , "(J)V" , reinterpret_cast<void*>(ImageFilter_Release)},
70 {"nDistantLitDiffuse", "(FFFFFFFFJ)J" , reinterpret_cast<void*>(ImageFilter_DistantLitDiffuse)},
71 {"nBlur" , "(FFIFFFFJ)J" , reinterpret_cast<void*>(ImageFilter_Blur)},
72 {"nDropShadow" , "(FFFFFFFJ)J" , reinterpret_cast<void*>(ImageFilter_DropShadow)},
73 {"nBlend" , "(IJJ)J" , reinterpret_cast<void*>(ImageFilter_Blend)},
74 {"nImage" , "(J)J" , reinterpret_cast<void*>(ImageFilter_Image)},
75 };
76
77 const auto clazz = env->FindClass("org/skia/jetski/ImageFilter");
78 return clazz
79 ? env->RegisterNatives(clazz, methods, std::size(methods))
80 : JNI_ERR;
81}
int register_jetski_ImageFilter(JNIEnv *env)
Definition: ImageFilter.cpp:67
static void SkSafeUnref(T *obj)
Definition: SkRefCnt.h:149
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
static sk_sp< SkImageFilter > DropShadow(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, SkColor color, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > DistantLitDiffuse(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
static sk_sp< SkImageFilter > Blend(SkBlendMode mode, sk_sp< SkImageFilter > background, sk_sp< SkImageFilter > foreground=nullptr, const CropRect &cropRect={})
DlColor color
static bool b
double y
double x
sk_sp< const SkImage > image
Definition: SkRecords.h:269
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
Definition: __init__.py:1
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
SkBlendMode BlendMode(jint bm)
Definition: Utils.cpp:36
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646