Beatmup
wrapper_core.cpp
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "wrapper.h"
20 
21 #include "include/Beatmup_Object.h"
22 #include "include/Beatmup_Visual_Android_BasicDisplay.h"
23 #include "include/Beatmup_Context.h"
24 #include "include/Beatmup_Android_Context.h"
25 #include "include/Beatmup_Object.h"
26 #include "include/Beatmup_Pipelining_CustomPipeline.h"
27 #include "include/Beatmup_Pipelining_Multitask.h"
28 #include "include/Beatmup_Pipelining_TaskHolder.h"
29 #include "include/Beatmup_Utils_Callback.h"
30 #include "include/Beatmup_Utils_ChunkAsset.h"
31 #include "include/Beatmup_Utils_ChunkCollection.h"
32 #include "include/Beatmup_Utils_ChunkFile.h"
33 #include "include/Beatmup_Utils_VariablesBundle.h"
34 #include "include/Beatmup_Sequence.h"
35 
36 #include "android/context.h"
37 #include "context_event_listener.h"
38 #include "callback_task.h"
39 
40 #include <android/asset_manager_jni.h>
41 #include <android/native_window_jni.h>
42 
43 #include <core/bitmap/tools.h>
48 #include <core/gpu/swapper.h>
51 
52 
53 // defining the pool
55 
56 /////////////////////////////////////////////////////////////////////////////////////////////
57 // OBJECT
58 /////////////////////////////////////////////////////////////////////////////////////////////
59 
60 JNIMETHOD(void, disposeNative, Java_Beatmup_Object, disposeNative)(JNIEnv * jenv, jobject jObj) {
62 #ifdef DEBUG_LOGGING
63  LOG_I("Disposing object #%lld", (jlong)nativeObj);
64 #endif
65  if (nativeObj) {
68  delete nativeObj;
69  }
70 }
71 
72 /////////////////////////////////////////////////////////////////////////////////////////////
73 // DISPLAY
74 /////////////////////////////////////////////////////////////////////////////////////////////
75 
76 JNIMETHOD(jboolean, bindSurfaceToContext, Java_Beatmup_Visual_Android_BasicDisplay, bindSurfaceToContext)(JNIEnv * jenv, jobject, jobject jCtx, jobject surface) {
78 
79  // retrieving the context
81 
82  // binding a new surface
83  if (surface) {
84  // bind the new one
85  ANativeWindow *wnd = ANativeWindow_fromSurface(jenv, surface);
86  if (!wnd) {
87  LOG_E("Empty surface window got when switching GL display.");
88  return JNI_FALSE;
89  }
90 
92  const bool result = Beatmup::DisplaySwitch::run(*ctx, wnd);
93  ANativeWindow_release(wnd);
94  return result ? JNI_TRUE : JNI_FALSE;
95  });
96  }
97 
98  // just removing the old one
99  else {
100  BEATMUP_CATCH({
101  return Beatmup::DisplaySwitch::run(*ctx, nullptr) ? JNI_TRUE : JNI_FALSE;
102  });
103  }
104 
105  return JNI_FALSE; // never happens
106 }
107 
108 /////////////////////////////////////////////////////////////////////////////////////////////
109 // CONTEXT
110 /////////////////////////////////////////////////////////////////////////////////////////////
111 
112 JNIMETHOD(jlong, attachEventListener, Java_Beatmup_Context, attachEventListener)(JNIEnv * jenv, jclass, jlong hCtx) {
116  if (listener)
117  delete listener;
120  return (jlong) (listener);
121 }
122 
123 JNIMETHOD(void, detachEventListener, Java_Beatmup_Context, detachEventListener)(JNIEnv * jenv, jclass, jlong h) {
126  delete listener;
127 }
128 
129 JNIMETHOD(jlong, getTotalRam, Java_Beatmup_Context, getTotalRam)(JNIEnv * jenv, jclass) {
132 }
133 
134 JNIMETHOD(jfloat, performTask, Java_Beatmup_Context, performTask)
135  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx, jobject jTask)
136 {
140  BEATMUP_CATCH({
142  });
143  return -1;
144 }
145 
146 JNIMETHOD(jint, submitTask, Java_Beatmup_Context, submitTask)
147  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx, jobject jTask)
148 {
153  return (jint)ctx->submitTask(*task, (Beatmup::PoolIndex)poolIdx);
154  });
155  return 0;
156 }
157 
158 JNIMETHOD(jint, submitPersistentTask, Java_Beatmup_Context, submitPersistentTask)
159  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx, jobject jTask)
160 {
166  });
167  return 0;
168 }
169 
170 JNIMETHOD(void, repeatTask, Java_Beatmup_Context, repeatTask)
171  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx, jobject jTask, jboolean abort)
172 {
178  });
179 }
180 
181 JNIMETHOD(void, waitForJob, Java_Beatmup_Context, waitForJob)
182  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx, jint job)
183 {
188  });
189 }
190 
191 JNIMETHOD(jboolean, abortJob, Java_Beatmup_Context, abortJob)
192  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx, jint job)
193 {
197  return ctx->abortJob(job, (Beatmup::PoolIndex)poolIdx) ? JNI_TRUE : JNI_FALSE;
198  });
199  return JNI_FALSE;
200 }
201 
202 JNIMETHOD(void, waitForAllJobs, Java_Beatmup_Context, waitForAllJobs)
203  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx)
204 {
209  });
210 }
211 
212 JNIMETHOD(jboolean, busy, Java_Beatmup_Context, busy)
213  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx)
214 {
218  return ctx->busy((Beatmup::PoolIndex)poolIdx) ? JNI_TRUE : JNI_FALSE;
219  });
220  return JNI_FALSE;
221 }
222 
223 JNIMETHOD(void, check, Java_Beatmup_Context, check)
224  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx)
225 {
230  });
231 }
232 
233 
234 JNIMETHOD(jlong, renderChessboard, Java_Beatmup_Context, renderChessboard)(JNIEnv * jenv, jobject, jlong hCtx,
235  jint width, jint height, jint cell, jint pixelFormat)
236 {
240 }
241 
242 
243 JNIMETHOD(jlong, copyBitmap, Java_Beatmup_Context, copyBitmap)(JNIEnv * jenv, jobject jCtx, jobject jBitmap, jint pixelFormat) {
247  // ctx is used in internal bitmap destructor, so add an internal ref
249  return (jlong) copy;
250 }
251 
252 
253 JNIMETHOD(jobject, scanlineSearchInt, Java_Beatmup_Context, scanlineSearchInt)(JNIEnv * jenv, jobject jCtx, jlong hBitmap, jint x, jint y, jint r, jint g, jint b, jint a) {
257  *bitmap,
258  Beatmup::pixint4(r, g, b, a),
260  );
262 }
263 
264 
265 JNIMETHOD(jobject, scanlineSearchFloat, Java_Beatmup_Context, scanlineSearchFloat)(JNIEnv * jenv, jobject jCtx, jlong hBitmap, jint x, jint y, jfloat r, jfloat g, jfloat b, jfloat a) {
269  *bitmap,
270  Beatmup::pixfloat4(r, g, b, a),
272  );
274 }
275 
276 
277 JNIMETHOD(jint, maxAllowedWorkerCount, Java_Beatmup_Context, maxAllowedWorkerCount)
278  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx)
279 {
283 }
284 
285 
286 JNIMETHOD(void, limitWorkerCount, Java_Beatmup_Context, limitWorkerCount)
287  (JNIEnv * jenv, jobject, jlong hCtx, jint poolIdx, jint count)
288 {
292 }
293 
294 
295 JNIMETHOD(jboolean, isGpuQueried, Java_Beatmup_Context, isGpuQueried)(JNIEnv * jenv, jobject, jlong hCtx) {
298  return (jboolean) ctx->isGpuQueried();
299 }
300 
301 
302 JNIMETHOD(jboolean, isGpuReady, Java_Beatmup_Context, isGpuReady)(JNIEnv * jenv, jobject, jlong hCtx) {
305  return (jboolean) ctx->isGpuReady();
306 }
307 
308 
309 JNIMETHOD(void, recycleGPUGarbage, Java_Beatmup_Context, recycleGPUGarbage)(JNIEnv * jenv, jobject, jlong hCtx) {
313 }
314 
315 
316 /////////////////////////////////////////////////////////////////////////////////////////////
317 // ANDROID CONTEXT
318 /////////////////////////////////////////////////////////////////////////////////////////////
319 
320 JNIMETHOD(jlong, newContext, Java_Beatmup_Android_Context, newContext)(JNIEnv * jenv, jclass, jint poolCount)
321 {
322  LOG_I("Beatmup is starting up...");
325 }
326 
327 /////////////////////////////////////////////////////////////////////////////////////////////
328 // VARIABLES BUNDLE
329 /////////////////////////////////////////////////////////////////////////////////////////////
330 
331 JNIMETHOD(void, setInteger1, Java_Beatmup_Utils_VariablesBundle, setInteger1)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jint val) {
335  vars->setInteger(nameStr, val);
336 }
337 
338 
339 JNIMETHOD(void, setInteger2, Java_Beatmup_Utils_VariablesBundle, setInteger2)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jint x, jint y) {
343  vars->setInteger(nameStr, x, y);
344 }
345 
346 
347 JNIMETHOD(void, setInteger3, Java_Beatmup_Utils_VariablesBundle, setInteger3)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jint x, jint y, jint z) {
351  vars->setInteger(nameStr, x, y, z);
352 }
353 
354 
355 JNIMETHOD(void, setInteger4, Java_Beatmup_Utils_VariablesBundle, setInteger4)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jint x, jint y, jint z, jint w) {
359  vars->setInteger(nameStr, x, y, z, w);
360 }
361 
362 
363 JNIMETHOD(void, setFloat1, Java_Beatmup_Utils_VariablesBundle, setFloat1)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jfloat val) {
367  vars->setFloat(nameStr, val);
368 }
369 
370 
371 JNIMETHOD(void, setFloat2, Java_Beatmup_Utils_VariablesBundle, setFloat2)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jfloat x, jfloat y) {
375  vars->setFloat(nameStr, x, y);
376 }
377 
378 
379 JNIMETHOD(void, setFloat3, Java_Beatmup_Utils_VariablesBundle, setFloat3)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jfloat x, jfloat y, jfloat z) {
383  vars->setFloat(nameStr, x, y, z);
384 }
385 
386 
387 JNIMETHOD(void, setFloat4, Java_Beatmup_Utils_VariablesBundle, setFloat4)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jfloat x, jfloat y, jfloat z, jfloat w) {
391  vars->setFloat(nameStr, x, y, z, w);
392 }
393 
394 
395 JNIMETHOD(void, setFloatMatrix, Java_Beatmup_Utils_VariablesBundle, setFloatMatrix)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jfloatArray array) {
399  jfloat* arrayData = jenv->GetFloatArrayElements(array, JNI_FALSE);
400  int count = (int)jenv->GetArrayLength(array);
401  switch (count) {
402  case 9:
403  vars->setFloatMatrix3(nameStr, arrayData);
404  break;
405  case 16:
406  vars->setFloatMatrix4(nameStr, arrayData);
407  break;
408  default:
409  $pool.throwToJava(jenv, "Invalid matrix size");
410  }
411  jenv->ReleaseFloatArrayElements(array, arrayData, JNI_ABORT);
412 }
413 
414 
415 JNIMETHOD(void, setFloatMatrixFromColorMatrix, Java_Beatmup_Utils_VariablesBundle, setFloatMatrixFromColorMatrix)(JNIEnv * jenv, jobject, jlong hInstance, jstring name, jobject jMat) {
420  vars->setFloatMatrix4(nameStr, *mat);
421 }
422 
423 /////////////////////////////////////////////////////////////////////////////////////////////
424 // CUSTOM PIPELINE
425 /////////////////////////////////////////////////////////////////////////////////////////////
426 
427 JNIMETHOD(jint, getTaskCount, Java_Beatmup_Pipelining_CustomPipeline, getTaskCount)(JNIEnv * jenv, jobject, jlong hInst) {
430  return (jint)pipeline->getTaskCount();
431 }
432 
433 
434 JNIMETHOD(jobject, getTask, Java_Beatmup_Pipelining_CustomPipeline, getTask)(JNIEnv * jenv, jobject, jlong hInst, jint index) {
437  return $pool.getJavaReference(&pipeline->getTask(index));
438 }
439 
440 
441 JNIMETHOD(jint, getTaskIndex, Java_Beatmup_Pipelining_CustomPipeline, getTaskIndex)(JNIEnv * jenv, jobject, jlong hInst, jlong hHolder) {
445  return pipeline->getTaskIndex(*taskHolder);
446 }
447 
448 
449 JNIMETHOD(jlong, addTask, Java_Beatmup_Pipelining_CustomPipeline, addTask)(JNIEnv * jenv, jobject, jlong hInst, jobject jHolder, jobject jTask) {
455  return (jlong)(newbie);
456 }
457 
458 
459 JNIMETHOD(jlong, insertTask, Java_Beatmup_Pipelining_CustomPipeline, insertTask)
461 {
466  Beatmup::CustomPipeline::TaskHolder* newbie = &pipeline->insertTask(*task, *where);
468  return (jlong)(newbie);
469 }
470 
471 
472 JNIMETHOD(jboolean, removeTask, Java_Beatmup_Pipelining_CustomPipeline, removeTask)(JNIEnv * jenv, jobject, jlong hInst, jlong hHolder) {
476  bool result = pipeline->removeTask(*what);
477  if (result)
479  return result;
480 }
481 
482 JNIMETHOD(void, measure, Java_Beatmup_Pipelining_CustomPipeline, measure)(JNIEnv * jenv, jobject, jlong hInst) {
485  pipeline->measure();
486 }
487 
488 /////////////////////////////////////////////////////////////////////////////////////////////
489 // MULTITASK
490 /////////////////////////////////////////////////////////////////////////////////////////////
491 
492 JNIMETHOD(jlong, newMultitask, Java_Beatmup_Pipelining_Multitask, newMultitask)(JNIEnv * jenv, jclass, jobject jCtx) {
494  return (jlong)(new Beatmup::Multitask());
495 }
496 
497 
498 JNIMETHOD(jint, getRepetitionPolicy, Java_Beatmup_Pipelining_Multitask, getRepetitionPolicy)(JNIEnv * jenv, jobject, jlong hInst, jlong hHolder) {
503  return static_cast<jint>(multitask->getRepetitionPolicy(*taskHolder));
504  });
505  return 0;
506 }
507 
508 
509 JNIMETHOD(void, setRepetitionPolicy, Java_Beatmup_Pipelining_Multitask, setRepetitionPolicy)(JNIEnv * jenv, jobject, jlong hInst, jlong hHolder, jint policy) {
511  BEATMUP_OBJ(Beatmup::Multitask, multitask, hInst);
514  multitask->setRepetitionPolicy(*taskHolder, static_cast<Beatmup::Multitask::RepetitionPolicy>(policy));
515  });
516 }
517 
518 /////////////////////////////////////////////////////////////////////////////////////////////
519 // TASK HOLDER
520 /////////////////////////////////////////////////////////////////////////////////////////////
521 
522 JNIMETHOD(jfloat, getRunTime, Java_Beatmup_Pipelining_TaskHolder, getRunTime) (JNIEnv * jenv, jobject, jlong hHolder) {
525  return (jfloat) taskHolder->getRunTime();
526 }
527 
528 /////////////////////////////////////////////////////////////////////////////////////////////
529 // SEQUENCE
530 /////////////////////////////////////////////////////////////////////////////////////////////
531 
532 #if !defined(BEATMUP_PROFILE_NOAUDIO) || !defined(BEATMUP_PROFILE_NOVIDEO)
533 
534 JNIMETHOD(jlong, copy, Java_Beatmup_Sequence, copy)(JNIEnv * jenv, jobject, jlong hSeq, jint start, jint end) {
537  return (jlong) seq->copy(start, end);
538 }
539 
540 JNIMETHOD(void, insert, Java_Beatmup_Sequence, insert)(JNIEnv * jenv, jobject, jlong hDestSeq, jlong hInsertSeq, jint time) {
544  destSeq->insert(*insSeq, time);
545 }
546 
547 JNIMETHOD(void, remove, Java_Beatmup_Sequence, remove)(JNIEnv * jenv, jobject, jlong hSeq, jint start, jint end) {
550  seq->remove(start, end);
551 }
552 
553 JNIMETHOD(void, shrink, Java_Beatmup_Sequence, shrink)(JNIEnv * jenv, jobject, jlong hSeq, jint start, jint end) {
556  seq->shrink(start, end);
557 }
558 
559 #endif
560 
561 /////////////////////////////////////////////////////////////////////////////////////////////
562 // CHUNK COLLECTION
563 /////////////////////////////////////////////////////////////////////////////////////////////
564 
565 JNIMETHOD(void, open, Java_Beatmup_Utils_ChunkCollection, open)
567 {
570  try {
571  collection->open();
572  }
573  catch (Beatmup::Exception& ex) { $pool.throwToJava(jenv, "java/io/IOError", ex.what()); }
574 }
575 
576 
577 JNIMETHOD(void, close, Java_Beatmup_Utils_ChunkCollection, close)
578  (JNIEnv * jenv, jobject, jlong hCollection)
579 {
582  collection->close();
583 }
584 
585 
586 JNIMETHOD(jlong, size, Java_Beatmup_Utils_ChunkCollection, size)
587  (JNIEnv * jenv, jobject, jlong hCollection)
588 {
591  return (jlong)collection->size();
592 }
593 
594 
595 JNIMETHOD(jboolean, chunkExists, Java_Beatmup_Utils_ChunkCollection, chunkExists)
596  (JNIEnv * jenv, jobject, jlong hCollection, jstring id)
597 {
601  return collection->chunkExists(idStr) ? JNI_TRUE : JNI_FALSE;
602 }
603 
604 
605 JNIMETHOD(jlong, chunkSize, Java_Beatmup_Utils_ChunkCollection, chunkSize)
606  (JNIEnv * jenv, jobject, jlong hCollection, jstring id)
607 {
610  BEATMUP_STRING(id);
611  return (jlong)collection->chunkSize(idStr);
612 }
613 
614 
615 JNIMETHOD(void, save, Java_Beatmup_Utils_ChunkCollection, save)
616  (JNIEnv * jenv, jobject, jlong hCollection, jstring filename, jboolean append)
617 {
621  collection->save(filenameStr, append == JNI_TRUE);
622 }
623 
624 
625 JNIMETHOD(jstring, read, Java_Beatmup_Utils_ChunkCollection, read)
626  (JNIEnv * jenv, jobject, jlong hCollection, jstring id)
627 {
630  BEATMUP_STRING(id);
631  std::string content = collection->template read<std::string>(idStr);
632  return jenv->NewStringUTF(content.c_str());
633 }
634 
635 /////////////////////////////////////////////////////////////////////////////////////////////
636 // CHUNK ASSET
637 /////////////////////////////////////////////////////////////////////////////////////////////
638 
639 JNIMETHOD(jlong, newChunkAsset, Java_Beatmup_Utils_ChunkAsset, newChunkAsset)
640  (JNIEnv * jenv, jclass, jobject jAssetManager, jstring filename)
641 {
642  AAssetManager *assetManager = AAssetManager_fromJava(jenv, jAssetManager);
645  try {
646  Beatmup::Android::ChunkAsset* instance = new Beatmup::Android::ChunkAsset(assetManager, filenameStr);
648  return (jlong)instance;
649  }
650  catch (Beatmup::Exception& ex) { $pool.throwToJava(jenv, "java/io/IOError", ex.what()); }
652 }
653 
654 /////////////////////////////////////////////////////////////////////////////////////////////
655 // CHUNK FILE
656 /////////////////////////////////////////////////////////////////////////////////////////////
657 
658 JNIMETHOD(jlong, newChunkfile, Java_Beatmup_Utils_ChunkFile, newChunkfile)
659  (JNIEnv * jenv, jclass, jstring filename, jboolean openNow)
660 {
663  try {
664  return (jlong)new Beatmup::ChunkFile(filenameStr, openNow == JNI_TRUE);
665  }
666  catch (Beatmup::Exception& ex) { $pool.throwToJava(jenv, "java/io/IOError", ex.what()); }
668 }
669 
670 /////////////////////////////////////////////////////////////////////////////////////////////
671 // CALLBACK
672 /////////////////////////////////////////////////////////////////////////////////////////////
673 
674 JNIMETHOD(jlong, newCallbackTask, Java_Beatmup_Utils_Callback, newCallbackTask)
675  (JNIEnv * jenv, jclass)
676 {
679 }
680 
681 JNIMETHOD(void, updateCallback, Java_Beatmup_Utils_Callback, updateCallback)
682  (JNIEnv * jenv, jobject jTask)
683 {
686  task->setCallbackObject(jenv, jTask);
687 }
688 
689 
690 // A handy regexp to transform generated JNI declarations into dummy definitions:
691 // search for (/\*\n(\s\*.*\n)+\s\*/\n)?JNIEXPORT ([^\s]+) JNICALL ([^\s]+)_([^\s]+)\n\s+\‍(JNIEnv \*,([^\‍)]+)\‍);
692 // replace with JNIMETHOD(\3, \5, \4, \5)\n (JNIEnv * jenv,\6)\n{\n BEATMUP_ENTER;\n}\n
Handles all Java binding-related static data.
Definition: objectpool.h:34
void nullifyHandle(JNIEnv *jenv, jobject obj)
Sets a handle of a java object to null.
Definition: objectpool.h:97
static void throwToJava(JNIEnv *jenv, const char *exceptionClass, const char *message)
Throws a specific exception.
Definition: objectpool.h:156
void removeAllJavaReferences(JNIEnv *jenv, const Beatmup::Object *bobj)
Removes all Java references to depending objects.
Definition: objectpool.h:127
static const jlong INVALID_HANDLE
Definition: objectpool.h:61
jobject getJavaReference(const Beatmup::Object *bobj) const
Returns a reference to the Java object which a given object depends on.
Definition: objectpool.h:142
JavaFactory factory
Definition: objectpool.h:63
Object * getObject(JNIEnv *jenv, jlong handle)
Retrieves native object by its handle.
Definition: objectpool.h:68
A very basic class for any image.
Task: an operation that can be executed by multiple threads in parallel.
Definition: parallelism.h:90
static ThreadIndex validThreadCount(int number)
Valid thread count from a given integer value.
Definition: parallelism.cpp:45
static uint64_t total()
Returns the size of total operating memory in bytes.
Definition: memory.cpp:56
Asset containing chunks.
Definition: asset.h:80
Android context.
Definition: context.h:32
Task calling method of a Java object.
Definition: callback_task.h:28
A key-value pair set storing pieces of arbitrary data (chunks) under string keys.
Definition: chunkfile.h:36
File containing chunks.
Definition: chunkfile.h:167
RGBA color mapping.
Definition: matrix.h:29
Needed for correct functioning of JNI.
An event listener (bunch of callbacks)
Definition: context.h:72
Basic class: task and memory management, any kind of static data.
Definition: context.h:59
const ThreadIndex maxAllowedWorkerCount(const PoolIndex pool=DEFAULT_POOL) const
Definition: context.cpp:276
bool isGpuReady() const
Definition: context.cpp:296
float performTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Performs a given task.
Definition: context.cpp:240
void wait(const PoolIndex pool=DEFAULT_POOL)
Blocks until all the submitted jobs are executed.
Definition: context.cpp:264
Job submitTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Adds a new task to the jobs queue.
Definition: context.cpp:248
bool abortJob(Job job, const PoolIndex pool=DEFAULT_POOL)
Aborts a given submitted job.
Definition: context.cpp:260
GL::RecycleBin * getGpuRecycleBin() const
Definition: context.cpp:340
Job submitPersistentTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Adds a new persistent task to the jobs queue.
Definition: context.cpp:252
void check(const PoolIndex pool=DEFAULT_POOL)
Checks if a specific thread pool is doing great: rethrows exceptions occurred during tasks execution,...
Definition: context.cpp:272
EventListener * getEventListener() const
Returns current event listener (or NULL)
Definition: context.cpp:288
bool busy(const PoolIndex pool=DEFAULT_POOL)
Queries whether a given thread pool is busy with a task.
Definition: context.cpp:268
void repeatTask(AbstractTask &task, bool abortCurrent, const PoolIndex pool=DEFAULT_POOL)
Ensures a given task executed at least once.
Definition: context.cpp:244
bool isGpuQueried() const
Definition: context.cpp:292
void limitWorkerCount(ThreadIndex maxValue, const PoolIndex pool=DEFAULT_POOL)
Limits maximum number of threads (workers) when performing tasks in a given pool.
Definition: context.cpp:280
void setEventListener(EventListener *eventListener)
Installs new event listener.
Definition: context.cpp:284
void waitForJob(Job job, const PoolIndex pool=DEFAULT_POOL)
Waits until a given job finishes.
Definition: context.cpp:256
A task within a pipeline.
Custom pipeline: a sequence of tasks to be executed as a whole.
static bool run(Context &ctx, void *switchingData=nullptr)
Base class for all exceptions.
Definition: exception.h:37
virtual const char * what() const NOEXCEPT override
Definition: exception.h:56
Fragmented signal in time domain.
Definition: sequence.h:33
void emptyBin()
Empty the bin destroying all the items in a GPU-aware thread.
Definition: recycle_bin.cpp:91
Conditional multiple tasks execution.
Definition: multitask.h:48
RepetitionPolicy
Determines when a specific task in the sequence is run when the whole sequence is invoked.
Definition: multitask.h:60
Beatmup object base class
Definition: basic_types.h:67
jobject makeIntPoint(JNIEnv *jenv, const Beatmup::IntPoint)
#define LOG_E(...)
Definition: log.h:24
#define LOG_I(...)
Definition: log.h:23
void read(Bitmap &bitmap, Args &&... args)
Calls a Func< ReaderClass >::process(access, params), where.
Definition: processing.h:49
IntPoint scanlineSearch(AbstractBitmap &source, pixint4 val, const IntPoint &startFrom)
Goes through a bitmap in scanline order (left to right, top to bottom) until a pixel of a given color...
Definition: tools.cpp:195
InternalBitmap * makeCopy(AbstractBitmap &bitmap)
Makes a copy of a bitmap.
Definition: tools.cpp:72
InternalBitmap * chessboard(Context &context, int width, int height, int cellSize, PixelFormat pixelFormat=BinaryMask)
Renders a chessboard image.
Definition: tools.cpp:91
unsigned char PoolIndex
number of tread pools or a pool index
Definition: parallelism.h:67
4-channel floating point arithmetic
4-channel integer arithmetic
#define BEATMUP_DELETE_REFERENCE(obj)
Definition: wrapper.h:57
Beatmup::AbstractBitmap * copy
jint poolCount
jlong jstring jobject jMat
return(jlong) new Beatmup jlong jstring name
jobject jCtx
jobject jObj
JNIEnv jlong jobject jobject jlong hWhere
JNIEnv * jenv
jclass
JNIEnv jlong jstring id
jobject jlong jint jint jint jint g
jobject jlong jint jint jint jint jint b
JNIEnv jlong jint jobject jTask
return() jlong(listener)
jlong jint jint jint jint pixelFormat
jlong jstring jint jint jint z
return collection chunkExists(JNIEnv *jenv, jobject, jlong hCollection, jstring id)
collection save(filenameStr, append==JNI_TRUE)
jlong hSeq
jlong jobject jHolder
BEATMUP_REFERENCE(jCtx, copy)
jobject jlong hBitmap
jlong jint index
seq shrink(start, end)
return JNI_FALSE
jobject jobject surface
JNIEnv jstring jboolean openNow
jlong jint jint jint cell
jobject jlong jint jint y
return pipeline getTaskIndex * taskHolder
pipeline measure()
jlong h
Beatmup::CustomPipeline::TaskHolder * newbie
jlong hCtx
return(jlong) Beatmup jobject jobject jBitmap
Beatmup::Context * ctx
JNIEnv jlong jint poolIdx
collection close()
JNIEnv jlong jint jint job
jlong jstring jint jint jint jint w
JNIEnv jlong jint jobject jboolean abort
BEATMUP_ENTER
JNIEnv jlong hCollection
jlong hDestSeq
JNIEnv jlong jstring filename
jobject jlong jint jint jint r
jobject
jlong jlong hInsertSeq
jlong jlong jint policy
BEATMUP_CATCH({ return(jint) ctx->submitTask(*task,(Beatmup::PoolIndex) poolIdx);})
destSeq insert * insSeq
jlong jint jint end
jlong hInst
return $pool getJavaReference & pipeline(index)
jobject jlong jint jint jint jint jint jint a
std::string content
Beatmup::Context::EventListener * listener
JNIMETHOD(void, disposeNative, Java_Beatmup_Object, disposeNative)(JNIEnv *jenv
JNIEnv jlong jint jint count
jfloat * arrayData
jlong jint width
BeatmupJavaObjectPool $pool
JNIEnv jobject jAssetManager
Beatmup::IntPoint result
jlong jint jint height
ctx limitWorkerCount(Beatmup::AbstractTask::validThreadCount(count),(Beatmup::PoolIndex) poolIdx)
return ctx maxAllowedWorkerCount((Beatmup::PoolIndex) poolIdx)
jlong jstring jfloatArray array
seq remove(start, end)
JNIEnv jlong jstring jboolean append
jlong jlong hHolder
jlong jint start
jlong jlong jint time
jobject jlong jint x
return(jlong) new Beatmup jlong jstring jint val
return(jlong) new Beatmup jlong hInstance
BEATMUP_OBJ(Beatmup::Context, ctx, hCtx)
BEATMUP_STRING(name)
Beatmup::InternalBitmap * bitmap
* mat
jlong jobject size
Beatmup::NNets::InferenceTask * task