aboutsummaryrefslogtreecommitdiff
path: root/shadows/framework/src/main/java/org/robolectric/shadows/ShadowNativePicture.java
blob: 493076c284b8a4e545a9f549a52592da471d7369 (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
package org.robolectric.shadows;

import static android.os.Build.VERSION_CODES.O;

import android.graphics.Picture;
import java.io.InputStream;
import java.io.OutputStream;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.nativeruntime.DefaultNativeRuntimeLoader;
import org.robolectric.nativeruntime.PictureNatives;
import org.robolectric.shadows.ShadowNativePicture.Picker;

/** Shadow for {@link Picture} that is backed by native code */
@Implements(value = Picture.class, minSdk = O, shadowPicker = Picker.class, isInAndroidSdk = false)
public class ShadowNativePicture {

  @Implementation
  protected static long nativeConstructor(long nativeSrcOr0) {
    DefaultNativeRuntimeLoader.injectAndLoad();
    return PictureNatives.nativeConstructor(nativeSrcOr0);
  }

  @Implementation
  protected static long nativeCreateFromStream(InputStream stream, byte[] storage) {
    DefaultNativeRuntimeLoader.injectAndLoad();
    return PictureNatives.nativeCreateFromStream(stream, storage);
  }

  @Implementation
  protected static int nativeGetWidth(long nativePicture) {
    return PictureNatives.nativeGetWidth(nativePicture);
  }

  @Implementation
  protected static int nativeGetHeight(long nativePicture) {
    return PictureNatives.nativeGetHeight(nativePicture);
  }

  @Implementation
  protected static long nativeBeginRecording(long nativeCanvas, int w, int h) {
    return PictureNatives.nativeBeginRecording(nativeCanvas, w, h);
  }

  @Implementation
  protected static void nativeEndRecording(long nativeCanvas) {
    PictureNatives.nativeEndRecording(nativeCanvas);
  }

  @Implementation
  protected static void nativeDraw(long nativeCanvas, long nativePicture) {
    PictureNatives.nativeDraw(nativeCanvas, nativePicture);
  }

  @Implementation
  protected static boolean nativeWriteToStream(
      long nativePicture, OutputStream stream, byte[] storage) {
    return PictureNatives.nativeWriteToStream(nativePicture, stream, storage);
  }

  @Implementation
  protected static void nativeDestructor(long nativePicture) {
    PictureNatives.nativeDestructor(nativePicture);
  }

  /** Shadow picker for {@link Picture}. */
  public static final class Picker extends GraphicsShadowPicker<Object> {
    public Picker() {
      super(ShadowPicture.class, ShadowNativePicture.class);
    }
  }
}