21 import java.util.HashMap;
23 import Beatmup.Exceptions.CoreException;
24 import Beatmup.Geometry.IntPoint;
25 import Beatmup.Imaging.Color;
26 import Beatmup.Imaging.FloatColor;
27 import Beatmup.Imaging.PixelFormat;
36 System.loadLibrary(
"c++_shared");
37 System.loadLibrary(
"beatmup");
40 private final HashMap<Long, Bitmap> bitmaps;
42 private long eventListenerHandle;
45 private static native
long attachEventListener(
long ctx);
46 private static native
void detachEventListener(
long eventListenerHandle);
47 private static native
long getTotalRam();
49 private native
float performTask(
long ctx,
int poolIndex,
Task task)
throws CoreException;
50 private native
int submitTask(
long ctx,
int poolIndex,
Task task);
51 private native
int submitPersistentTask(
long ctx,
int poolIndex,
Task task);
52 private native
void repeatTask(
long ctx,
int poolIndex,
Task task,
boolean abortCurrent);
53 private native
void waitForJob(
long ctx,
int poolIndex,
int job);
54 private native
boolean abortJob(
long ctx,
int poolIndex,
int job);
55 private native
void waitForAllJobs(
long ctx,
int poolIndex);
56 private native
boolean busy(
long ctx,
int poolIndex);
59 private native
long renderChessboard(
long ctx,
int width,
int height,
int cellSize,
int pixelFormat);
60 private native
long copyBitmap(
Bitmap bitmap,
int newPixelFormat);
61 private native
IntPoint scanlineSearchInt(
long bitmap,
int startX,
int startY,
int r,
int g,
int b,
int a);
62 private native
IntPoint scanlineSearchFloat(
long bitmap,
int startX,
int startY,
float r,
float g,
float b,
float a);
64 private native
int maxAllowedWorkerCount(
long ctx,
int poolIndex);
65 private native
void limitWorkerCount(
long ctx,
int poolIndex,
int count);
79 return performTask(
handle, 0, task);
91 return performTask(
handle, poolIndex, task);
101 repeatTask(
handle, 0, task, abortCurrent);
112 repeatTask(
handle, poolIndex, task, abortCurrent);
122 return submitPersistentTask(
handle, 0, task);
133 return submitPersistentTask(
handle, poolIndex, task);
142 waitForJob(
handle, 0, job);
152 waitForJob(
handle, poolIndex, job);
162 return abortJob(
handle, 0, job);
173 return abortJob(
handle, poolIndex, job);
182 limitWorkerCount(
handle, 0, newCount);
192 limitWorkerCount(
handle, poolIndex, newCount);
221 eventListenerHandle = attachEventListener(
handle);
222 bitmaps =
new HashMap<>();
231 synchronized (bitmaps) {
232 bitmaps.put(bitmap.
handle, bitmap);
242 synchronized (bitmaps) {
243 bitmaps.remove(bitmap.
handle);
250 synchronized (bitmaps) {
251 for (
Bitmap bitmap : bitmaps.values()) {
257 detachEventListener(eventListenerHandle);
272 renderChessboard(
handle, width, height, cellSize, pixelFormat.ordinal())
284 return new Bitmap(
this, copyBitmap(source, pixelFormat.ordinal()));
297 return scanlineSearchInt(bitmap.
handle, start.x, start.y, color.
r, color.
g, color.
b, color.
a);
301 return scanlineSearchFloat(source.
handle, start.x, start.y, color.
r, color.
g, color.
b, color.
a);
335 return getTotalRam();
boolean isGPUReady()
Tests whether the GPU was already queried and successfully initialized.
int submitPersistentTask(Task task, int poolIndex)
Submits a persistent task in a specified thread pool.
void repeatTask(Task task, boolean abortCurrent)
Ensures a given task executed at least once.
void check()
Checks if the main thread pool is doing great: rethrows exceptions occurred during tasks execution,...
Bitmap copyBitmap(Bitmap source, PixelFormat pixelFormat)
Creates a copy of given bitmap.
Bitmap renderChessboard(int width, int height, int cellSize, PixelFormat pixelFormat)
Renders a chessboard-like image.
void watchBitmap(Bitmap bitmap)
Adds a bitmap to the watch list.
boolean abortJob(int job, int poolIndex)
Aborts a given submitted job.
void limitWorkerCount(int newCount, int poolIndex)
Sets maximum number of threads executing tasks in a given thread pool.
void repeatTask(Task task, boolean abortCurrent, int poolIndex)
Ensures a given task executed at least once in a specific thread pool.
float performTask(Task task)
Performs a given task in the main thread pool.
synchronized void dispose()
Destroys the native object.
void limitWorkerCount(int newCount)
Sets maximum number of threads executing tasks in the main thread pool.
void waitForJob(int job)
Blocks until a given job in the main thread pool finishes.
IntPoint scanlineSearch(Bitmap bitmap, Color color, IntPoint start)
Goes through a bitmap in scanline order (left to right, top to bottom) until a pixel of a given color...
boolean isGPUQueried()
Tests whether the GPU was already queried.
int submitPersistentTask(Task task)
Submits a persistent task in the main thread pool.
float performTask(Task task, int poolIndex)
Performs a given task.
void waitForJob(int job, int poolIndex)
Blocks until a given job in the main thread pool finishes.
void check(int poolIndex)
Checks if a specific thread pool is doing great: rethrows exceptions occurred during tasks execution,...
Context(long handle)
Creates a new context.
static final IntPoint SCANLINE_SEARCH_NOT_FOUND
Returned by Beatmup.Context.scanlineSearch() if no pixel of a specific color is found in the image.
synchronized void unwatchBitmap(Bitmap bitmap)
Removes a bitmap from the watch list.
static long getTotalRAMBytes()
void recycleGPUGarbage()
Recycles GPU-managed resources that are ready to be disposed in a separate task.
boolean abortJob(int job)
Aborts a given submitted job.
Exception occurred in the engine.
Integer RGBA color value.
Floating-point RGBA color value.
Base class for objects natively managed by Beatmup.
long handle
pointer to the native object
synchronized void dispose()
Destroys the native object.