-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ShadowHardwareRenderer.java
64 lines (53 loc) · 2.01 KB
/
ShadowHardwareRenderer.java
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
package org.robolectric.shadows;
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 android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.HardwareRenderer;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import org.robolectric.shadow.api.Shadow;
@Implements(
value = HardwareRenderer.class,
isInAndroidSdk = false,
looseSignatures = true,
minSdk = Q)
public class ShadowHardwareRenderer {
private static long nextCreateProxy = 0;
@Implementation(maxSdk = Q)
protected static long nCreateProxy(boolean translucent, long rootRenderNode) {
return ++nextCreateProxy;
}
@Implementation
protected static long nCreateTextureLayer(long nativeProxy) {
return ShadowVirtualRefBasePtr.put(nativeProxy);
}
@Implementation(minSdk = R, maxSdk = R)
protected static long nCreateProxy(
boolean translucent, boolean isWideGamut, long rootRenderNode) {
return nCreateProxy(translucent, rootRenderNode);
}
// need to use loose signatures here to account for signature changes
@Implementation(minSdk = S)
protected static long nCreateProxy(Object translucent, Object rootRenderNode) {
// TODO Find an approach to support the same method with disconnected range
return nCreateProxy((boolean) translucent, (long) rootRenderNode);
}
@Implementation
protected static Bitmap createHardwareBitmap(
/*RenderNode*/ Object node, /*int*/ Object width, /*int*/ Object height) {
return createHardwareBitmap((int) width, (int) height);
}
private static Bitmap createHardwareBitmap(int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.HARDWARE);
ShadowBitmap shadowBitmap = Shadow.extract(bitmap);
shadowBitmap.setMutable(false);
return bitmap;
}
@Resetter
public static void reset() {
nextCreateProxy = 0;
}
}