1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package org.robolectric.shadows;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.P;
import static android.os.Build.VERSION_CODES.Q;
import static android.os.Build.VERSION_CODES.R;
import static android.os.Build.VERSION_CODES.S;
import static android.os.Build.VERSION_CODES.S_V2;
import static android.os.Build.VERSION_CODES.TIRAMISU;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.nativeruntime.BitmapShaderNatives;
import org.robolectric.nativeruntime.DefaultNativeRuntimeLoader;
import org.robolectric.shadows.ShadowNativeBitmapShader.Picker;
import org.robolectric.versioning.AndroidVersions.U;
/** Shadow for {@link BitmapShader} that is backed by native code */
@Implements(
value = BitmapShader.class,
minSdk = O,
shadowPicker = Picker.class,
callNativeMethodsByDefault = true)
public class ShadowNativeBitmapShader {
@Implementation(minSdk = O, maxSdk = P)
protected static long nativeCreate(
long nativeMatrix, Bitmap bitmap, int shaderTileModeX, int shaderTileModeY) {
return nativeCreate(
nativeMatrix,
bitmap != null ? bitmap.getNativeInstance() : 0,
shaderTileModeX,
shaderTileModeY,
false);
}
@Implementation(minSdk = Q, maxSdk = R)
protected static long nativeCreate(
long nativeMatrix, long bitmapHandle, int shaderTileModeX, int shaderTileModeY) {
return nativeCreate(nativeMatrix, bitmapHandle, shaderTileModeX, shaderTileModeY, false);
}
@Implementation(minSdk = S, maxSdk = S_V2)
protected static long nativeCreate(
long nativeMatrix,
long bitmapHandle,
int shaderTileModeX,
int shaderTileModeY,
boolean filter) {
DefaultNativeRuntimeLoader.injectAndLoad();
return BitmapShaderNatives.nativeCreate(
nativeMatrix, bitmapHandle, shaderTileModeX, shaderTileModeY, filter);
}
@Implementation(minSdk = TIRAMISU, maxSdk = U.SDK_INT)
protected static long nativeCreate(
long nativeMatrix,
long bitmapHandle,
int shaderTileModeX,
int shaderTileModeY,
boolean filter,
boolean isDirectSampled) {
return nativeCreate(nativeMatrix, bitmapHandle, shaderTileModeX, shaderTileModeY, filter);
}
/** Shadow picker for {@link BitmapShader}. */
public static final class Picker extends GraphicsShadowPicker<Object> {
public Picker() {
super(null, ShadowNativeBitmapShader.class);
}
}
}
|