• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.graphics;
18 
19 /**
20  * Fake android.graphics.Bitmap class that's minimum for testing
21  */
22 public final class Bitmap {
23 
24   private final long mNativePtr;
25 
26   private final int mWidth;
27   private final int mHeight;
28 
Bitmap(int width, int height, long nativePtr, byte[] buffer)29   public Bitmap(int width, int height, long nativePtr, byte[] buffer) {
30     this.mWidth = width;
31     this.mHeight = height;
32     this.mNativePtr = nativePtr;
33     dumpData.add(nativePtr, buffer);
34   }
35 
36   private static final class DumpData {
37     private final int format;
38     private final long[] natives;
39     private final byte[][] buffers;
40     private final int max;
41     private int count;
42 
DumpData(int format, int max)43     public DumpData(int format, int max) {
44       this.max = max;
45       this.format = format;
46       this.natives = new long[max];
47       this.buffers = new byte[max][];
48       this.count = 0;
49     }
50 
add(long nativePtr, byte[] buffer)51     public void add(long nativePtr, byte[] buffer) {
52       natives[count] = nativePtr;
53       buffers[count] = buffer;
54       count = (count >= max) ? max : count + 1;
55     }
56   };
57 
58   // assume default format 'PNG' and maximum 10 test bitmaps
59   private static DumpData dumpData = new DumpData(1, 10);
60 }
61