aboutsummaryrefslogtreecommitdiff
path: root/nativeruntime/src/main/java/org/robolectric/nativeruntime/BitmapNatives.java
blob: b273771c4bddb02592fe5c9896a638bc88a9c3eb (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.robolectric.nativeruntime;

import android.graphics.Bitmap;
import android.graphics.ColorSpace;
import android.hardware.HardwareBuffer;
import android.os.Parcel;
import java.io.OutputStream;
import java.nio.Buffer;

/**
 * Native methods for Bitmap JNI registration.
 *
 * <p>Native method signatures are derived from
 * https://cs.android.com/android/platform/superproject/+/android-12.0.0_r1:frameworks/base/graphics/java/android/graphics/Bitmap.java
 */
public final class BitmapNatives {

  public static native Bitmap nativeCreate(
      int[] colors,
      int offset,
      int stride,
      int width,
      int height,
      int nativeConfig,
      boolean mutable,
      long nativeColorSpace);

  public static native Bitmap nativeCopy(long nativeSrcBitmap, int nativeConfig, boolean isMutable);

  public static native Bitmap nativeCopyAshmem(long nativeSrcBitmap);

  public static native Bitmap nativeCopyAshmemConfig(long nativeSrcBitmap, int nativeConfig);

  public static native long nativeGetNativeFinalizer();

  public static native void nativeRecycle(long nativeBitmap);

  public static native void nativeReconfigure(
      long nativeBitmap, int width, int height, int config, boolean isPremultiplied);

  public static native boolean nativeCompress(
      long nativeBitmap, int format, int quality, OutputStream stream, byte[] tempStorage);

  public static native void nativeErase(long nativeBitmap, int color);

  public static native void nativeErase(long nativeBitmap, long colorSpacePtr, long color);

  public static native int nativeRowBytes(long nativeBitmap);

  public static native int nativeConfig(long nativeBitmap);

  public static native int nativeGetPixel(long nativeBitmap, int x, int y);

  public static native long nativeGetColor(long nativeBitmap, int x, int y);

  public static native void nativeGetPixels(
      long nativeBitmap, int[] pixels, int offset, int stride, int x, int y, int width, int height);

  public static native void nativeSetPixel(long nativeBitmap, int x, int y, int color);

  public static native void nativeSetPixels(
      long nativeBitmap, int[] colors, int offset, int stride, int x, int y, int width, int height);

  public static native void nativeCopyPixelsToBuffer(long nativeBitmap, Buffer dst);

  public static native void nativeCopyPixelsFromBuffer(long nativeBitmap, Buffer src);

  public static native int nativeGenerationId(long nativeBitmap);

  public static native Bitmap nativeCreateFromParcel(Parcel p);
  // returns true on success
  public static native boolean nativeWriteToParcel(long nativeBitmap, int density, Parcel p);
  // returns a new bitmap built from the native bitmap's alpha, and the paint
  public static native Bitmap nativeExtractAlpha(
      long nativeBitmap, long nativePaint, int[] offsetXY);

  public static native boolean nativeHasAlpha(long nativeBitmap);

  public static native boolean nativeIsPremultiplied(long nativeBitmap);

  public static native void nativeSetPremultiplied(long nativeBitmap, boolean isPremul);

  public static native void nativeSetHasAlpha(
      long nativeBitmap, boolean hasAlpha, boolean requestPremul);

  public static native boolean nativeHasMipMap(long nativeBitmap);

  public static native void nativeSetHasMipMap(long nativeBitmap, boolean hasMipMap);

  public static native boolean nativeSameAs(long nativeBitmap0, long nativeBitmap1);

  public static native void nativePrepareToDraw(long nativeBitmap);

  public static native int nativeGetAllocationByteCount(long nativeBitmap);

  public static native Bitmap nativeCopyPreserveInternalConfig(long nativeBitmap);

  public static native Bitmap nativeWrapHardwareBufferBitmap(
      HardwareBuffer buffer, long nativeColorSpace);

  public static native HardwareBuffer nativeGetHardwareBuffer(long nativeBitmap);

  public static native ColorSpace nativeComputeColorSpace(long nativePtr);

  public static native void nativeSetColorSpace(long nativePtr, long nativeColorSpace);

  public static native boolean nativeIsSRGB(long nativePtr);

  public static native boolean nativeIsSRGBLinear(long nativePtr);

  public static native void nativeSetImmutable(long nativePtr);

  public static native boolean nativeIsImmutable(long nativePtr);

  public static native boolean nativeIsBackedByAshmem(long nativePtr);

  private BitmapNatives() {}
}