7. Dépréciation "Render" (Android 4.1)
Deprecation Notice:
Earlier versions of Renderscript included an
experimental graphics engine component.
This component is now deprecated as of
Android 4.1 [...] If you have apps that render
graphics with Renderscript, we highly
recommend you convert your code to
another Android graphics rendering option.
8. Pourquoi ?
● Les développeurs préfèrent OpenGL
● OpenGL plus utilisé en interne aussi
9. Renderscript, c'est ...
● Un outil pour les calculs
● Ne remplace ni SDK, ni NDK.
● Problématiques spécifiques
○ calculs
○ performances
10. Les 3 piliers de Renderscript
● Portabilité
○ Android 3.0+
○ ≈45%
● Performances
○ CPU (architectures, coeurs, instructions)
○ GPU
● Simplicité d'utilisation
○ Génération de "glue code"
11. MAIS QU'EST CE QUE C'EST ?
● C99 : le langage
● API de calcul
● Outils SDK pour la génération de code
12. Au coeur de RS
APK Appareil
bytecode binaire
code.rs RS
Renderscript
GPU
CPU CPU
#1 #2
20. Filter.java - Création - 1/7
// Création du script
mRS = RenderScript.create(mContext);
mScript = new ScriptC_filter(mRS,
mContext.getResources(),
R.raw.filter);
21. Filter.java - Allocations - 2/7
// Allocation de la mémoire
// contenant le bitmap
mInAllocation =
Allocation.createFromBitmap(
mRS,
inputBitmap,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
22. Filter.java - Allocations - 3/7
// Allocation de la mémoire pour
// récupérer l'image générée
mOutAllocation = Allocation.createTyped(
mRS,
mInAllocation.getType());
23. Filter.java - Paramètre - 4/7
// Mise en place des paramètres
Matrix3f sepiaMatrix =
new Matrix3f(mMatrix);
mScript.set_filter(sepiaMatrix);
25. Filter.java - Résultat - 6/7
// Copie du résultat dans
// le bitmap de sortie
mOutAllocation.copyTo(outputBitmap);
26. Filter.java - Complet - 7/7
// Création du script
mRS = RenderScript.create(mContext);
mScript = new ScriptC_filter(mRS, mContext.getResources(), R.raw.filter);
// Allocation de la mémoire contenant le bitmap
mInAllocation = Allocation.createFromBitmap(mRS, inputBitmap,
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
// Allocation de la mémoire pour récupérer l'image générée
mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
// Mise en place des paramètres
Matrix3f sepiaMatrix = new Matrix3f(mMatrix);
mScript.set_filter(sepiaMatrix);
// Appel du script (rsForEach)
mScript.forEach_root(mInAllocation, mOutAllocation);
// Copie du résultat dans le bitmap de sortie
mOutAllocation.copyTo(outputBitmap);
29. Résultats
Appareil (matériel) Java RS Gain
Nexus S
960 ms 280 ms x 3.4
(Exynos 1 GHz Cortex A8)
Galaxy Nexus
360 ms 80 ms x 4.5
(OMAP 4460 1,2 GHz dual-core)
Samsung Galaxy S2
340 ms 48 ms x 7.0
(1.2 GHz dual-core ARM Cortex-A9)
Samsung Galaxy S3
325 ms 49 ms x 6.6
(1.4 GHz quad-core ARM Cortex-A9)
Motorola Xoom
210 ms 26 ms x 8.0
(Tegra 2: 1GHz dual-core)
Nexus 7
180 ms 22 ms x 8.2
(Tegra 3: 1.3 GHz quad-core)
Intel AZ210 - Intel Orange San Diego
293 ms 59 ms x 4.9
(Intel Atom 1.6 Ghz Z2460 with HT - x86)
30. RS en Bref
● Solution pour les calculs
● Intégration simplifiée & portabilitée
● à vous de jouer !