diff options
author | John Reck <jreck@google.com> | 2015-04-17 20:45:19 +0000 |
---|---|---|
committer | John Reck <jreck@google.com> | 2015-04-17 20:46:47 +0000 |
commit | 7809f835cae637c12eebdc92103ad88890228d97 (patch) | |
tree | 6e1d18e8b417f76e32a13b22ac9c3ced00b8c083 /services | |
parent | afbeb2c2374bf7b7f7efa120944714fab469173d (diff) | |
download | frameworks_base-7809f835cae637c12eebdc92103ad88890228d97.zip frameworks_base-7809f835cae637c12eebdc92103ad88890228d97.tar.gz frameworks_base-7809f835cae637c12eebdc92103ad88890228d97.tar.bz2 |
Revert "Move AssetAtlas off of SkBitmap*"
This reverts commit 87ffb63d90fb6dd2689fe72dcb24fda9a6156220.
Change-Id: I92adfcee454a0a19020cdd9e96a134be0ee529aa
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/AssetAtlasService.java | 98 |
1 files changed, 58 insertions, 40 deletions
diff --git a/services/core/java/com/android/server/AssetAtlasService.java b/services/core/java/com/android/server/AssetAtlasService.java index 26f4232..9e28b64 100644 --- a/services/core/java/com/android/server/AssetAtlasService.java +++ b/services/core/java/com/android/server/AssetAtlasService.java @@ -199,6 +199,8 @@ public class AssetAtlasService extends IAssetAtlas.Stub { private final ArrayList<Bitmap> mBitmaps; private final int mPixelCount; + private Bitmap mAtlasBitmap; + Renderer(ArrayList<Bitmap> bitmaps, int pixelCount) { mBitmaps = bitmaps; mPixelCount = pixelCount; @@ -253,9 +255,8 @@ public class AssetAtlasService extends IAssetAtlas.Stub { // We always render the atlas into a bitmap. This bitmap is then // uploaded into the GraphicBuffer using OpenGL to swizzle the content - final Bitmap atlasBitmap = Bitmap.createBitmap( - buffer.getWidth(), buffer.getHeight(), Bitmap.Config.ARGB_8888); - final Canvas canvas = new Canvas(atlasBitmap); + final Canvas canvas = acquireCanvas(buffer.getWidth(), buffer.getHeight()); + if (canvas == null) return false; final Atlas.Entry entry = new Atlas.Entry(); @@ -264,58 +265,73 @@ public class AssetAtlasService extends IAssetAtlas.Stub { int mapIndex = 0; boolean result = false; - final long startRender = System.nanoTime(); - final int count = mBitmaps.size(); + try { + final long startRender = System.nanoTime(); + final int count = mBitmaps.size(); + + for (int i = 0; i < count; i++) { + final Bitmap bitmap = mBitmaps.get(i); + if (atlas.pack(bitmap.getWidth(), bitmap.getHeight(), entry) != null) { + // We have more bitmaps to pack than the current configuration + // says, we were most likely not able to detect a change in the + // list of preloaded drawables, abort and delete the configuration + if (mapIndex >= mAtlasMap.length) { + deleteDataFile(); + break; + } - for (int i = 0; i < count; i++) { - final Bitmap bitmap = mBitmaps.get(i); - if (atlas.pack(bitmap.getWidth(), bitmap.getHeight(), entry) != null) { - // We have more bitmaps to pack than the current configuration - // says, we were most likely not able to detect a change in the - // list of preloaded drawables, abort and delete the configuration - if (mapIndex >= mAtlasMap.length) { - deleteDataFile(); - break; + canvas.save(); + canvas.translate(entry.x, entry.y); + if (entry.rotated) { + canvas.translate(bitmap.getHeight(), 0.0f); + canvas.rotate(90.0f); + } + canvas.drawBitmap(bitmap, 0.0f, 0.0f, null); + canvas.restore(); + atlasMap[mapIndex++] = bitmap.getSkBitmap(); + atlasMap[mapIndex++] = entry.x; + atlasMap[mapIndex++] = entry.y; + atlasMap[mapIndex++] = entry.rotated ? 1 : 0; } + } - canvas.save(); - canvas.translate(entry.x, entry.y); - if (entry.rotated) { - canvas.translate(bitmap.getHeight(), 0.0f); - canvas.rotate(90.0f); - } - canvas.drawBitmap(bitmap, 0.0f, 0.0f, null); - canvas.restore(); - atlasMap[mapIndex++] = bitmap.refSkPixelRef(); - atlasMap[mapIndex++] = entry.x; - atlasMap[mapIndex++] = entry.y; - atlasMap[mapIndex++] = entry.rotated ? 1 : 0; + final long endRender = System.nanoTime(); + result = nUploadAtlas(buffer, mAtlasBitmap); + + final long endUpload = System.nanoTime(); + if (DEBUG_ATLAS) { + float renderDuration = (endRender - startRender) / 1000.0f / 1000.0f; + float uploadDuration = (endUpload - endRender) / 1000.0f / 1000.0f; + Log.d(LOG_TAG, String.format("Rendered atlas in %.2fms (%.2f+%.2fms)", + renderDuration + uploadDuration, renderDuration, uploadDuration)); } - } - final long endRender = System.nanoTime(); - releaseCanvas(canvas, atlasBitmap); - result = nUploadAtlas(buffer, atlasBitmap); - atlasBitmap.recycle(); - final long endUpload = System.nanoTime(); - - if (DEBUG_ATLAS) { - float renderDuration = (endRender - startRender) / 1000.0f / 1000.0f; - float uploadDuration = (endUpload - endRender) / 1000.0f / 1000.0f; - Log.d(LOG_TAG, String.format("Rendered atlas in %.2fms (%.2f+%.2fms)", - renderDuration + uploadDuration, renderDuration, uploadDuration)); + } finally { + releaseCanvas(canvas); } return result; } /** + * Returns a Canvas for the specified buffer. If {@link #DEBUG_ATLAS_TEXTURE} + * is turned on, the returned Canvas will render into a local bitmap that + * will then be saved out to disk for debugging purposes. + * @param width + * @param height + */ + private Canvas acquireCanvas(int width, int height) { + mAtlasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + return new Canvas(mAtlasBitmap); + } + + /** * Releases the canvas used to render into the buffer. Calling this method * will release any resource previously acquired. If {@link #DEBUG_ATLAS_TEXTURE} * is turend on, calling this method will write the content of the atlas * to disk in /data/system/atlas.png for debugging. */ - private void releaseCanvas(Canvas canvas, Bitmap atlasBitmap) { + private void releaseCanvas(Canvas canvas) { canvas.setBitmap(null); if (DEBUG_ATLAS_TEXTURE) { @@ -324,7 +340,7 @@ public class AssetAtlasService extends IAssetAtlas.Stub { try { FileOutputStream out = new FileOutputStream(dataFile); - atlasBitmap.compress(Bitmap.CompressFormat.PNG, 100, out); + mAtlasBitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.close(); } catch (FileNotFoundException e) { // Ignore @@ -332,6 +348,8 @@ public class AssetAtlasService extends IAssetAtlas.Stub { // Ignore } } + mAtlasBitmap.recycle(); + mAtlasBitmap = null; } } |