summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2012-05-15 11:31:54 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-05-15 11:31:54 -0700
commitd5cfec8d34a59f2a4e98b655b5e49775d69ad64c (patch)
tree930da53f20eb9016dc4f4791ad7bdea213912ed3 /libs
parentaebfdc231aadab63e51d740a8f3abf97953fd9f2 (diff)
parent7b8523aaed11a3b5ee286776023233036ac0759d (diff)
downloadframeworks_base-d5cfec8d34a59f2a4e98b655b5e49775d69ad64c.zip
frameworks_base-d5cfec8d34a59f2a4e98b655b5e49775d69ad64c.tar.gz
frameworks_base-d5cfec8d34a59f2a4e98b655b5e49775d69ad64c.tar.bz2
am 7b8523aa: Merge "Remove all Dalvik allocations from Cavnas.drawBitmap(int[], ...)" into jb-dev
* commit '7b8523aaed11a3b5ee286776023233036ac0759d': Remove all Dalvik allocations from Cavnas.drawBitmap(int[], ...)
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/DisplayListRenderer.cpp31
-rw-r--r--libs/hwui/DisplayListRenderer.h38
-rw-r--r--libs/hwui/OpenGLRenderer.cpp15
-rw-r--r--libs/hwui/OpenGLRenderer.h1
-rw-r--r--libs/hwui/TextureCache.cpp10
-rw-r--r--libs/hwui/TextureCache.h5
6 files changed, 91 insertions, 9 deletions
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index f6ca77c..d2a6a7a 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -49,6 +49,7 @@ const char* DisplayList::OP_NAMES[] = {
"DrawBitmap",
"DrawBitmapMatrix",
"DrawBitmapRect",
+ "DrawBitmapData",
"DrawBitmapMesh",
"DrawPatch",
"DrawColor",
@@ -434,6 +435,14 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
(char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
}
break;
+ case DrawBitmapData: {
+ SkBitmap* bitmap = getBitmapData();
+ float x = getFloat();
+ float y = getFloat();
+ SkPaint* paint = getPaint(renderer);
+ ALOGD("%s%s %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], x, y, paint);
+ }
+ break;
case DrawBitmapMesh: {
int verticesCount = 0;
uint32_t colorsCount = 0;
@@ -1020,6 +1029,19 @@ status_t DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flag
renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
}
break;
+ case DrawBitmapData: {
+ SkBitmap* bitmap = getBitmapData();
+ float x = getFloat();
+ float y = getFloat();
+ SkPaint* paint = getPaint(renderer);
+ DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
+ bitmap, x, y, paint);
+ if (bitmap) {
+ renderer.drawBitmap(bitmap, x, y, paint);
+ delete bitmap;
+ }
+ }
+ break;
case DrawBitmapMesh: {
int32_t verticesCount = 0;
uint32_t colorsCount = 0;
@@ -1487,6 +1509,15 @@ void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcT
addSkip(location);
}
+void DisplayListRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
+ const bool reject = quickReject(left, top, left + bitmap->width(), bitmap->height());
+ uint32_t* location = addOp(DisplayList::DrawBitmapData, reject);
+ addBitmapData(bitmap);
+ addPoint(left, top);
+ addPaint(paint);
+ addSkip(location);
+}
+
void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
float* vertices, int* colors, SkPaint* paint) {
addOp(DisplayList::DrawBitmapMesh);
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index 5ce770d..2f74f5b 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -91,6 +91,7 @@ public:
DrawBitmap,
DrawBitmapMatrix,
DrawBitmapRect,
+ DrawBitmapData,
DrawBitmapMesh,
DrawPatch,
DrawColor,
@@ -422,6 +423,19 @@ private:
return (SkBitmap*) getInt();
}
+ SkBitmap* getBitmapData() {
+ SkBitmap* bitmap = new SkBitmap;
+ bitmap->setConfig((SkBitmap::Config) getInt(), getInt(), getInt());
+ if (!bitmap->allocPixels()) {
+ delete bitmap;
+ return NULL;
+ }
+
+ bitmap->setPixels((void*) mReader.skip(bitmap->height() * bitmap->rowBytes()));
+
+ return bitmap;
+ }
+
SkiaShader* getShader() {
return (SkiaShader*) getInt();
}
@@ -574,6 +588,7 @@ public:
virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
float srcRight, float srcBottom, float dstLeft, float dstTop,
float dstRight, float dstBottom, SkPaint* paint);
+ virtual void drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint);
virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
float* vertices, int* colors, SkPaint* paint);
virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
@@ -701,16 +716,23 @@ private:
void addInts(const int32_t* values, uint32_t count) {
mWriter.writeInt(count);
- for (uint32_t i = 0; i < count; i++) {
- mWriter.writeInt(values[i]);
- }
+ mWriter.write(values, count * sizeof(int32_t));
+ }
+
+ void addBitmapData(SkBitmap* bitmap) {
+ mWriter.writeInt(bitmap->config());
+ mWriter.writeInt(bitmap->width());
+ mWriter.writeInt(bitmap->height());
+
+ SkAutoLockPixels alp(*bitmap);
+ void* src = bitmap->getPixels();
+
+ mWriter.write(src, bitmap->rowBytes() * bitmap->height());
}
void addUInts(const uint32_t* values, int8_t count) {
mWriter.writeInt(count);
- for (int8_t i = 0; i < count; i++) {
- mWriter.writeInt(values[i]);
- }
+ mWriter.write(values, count * sizeof(uint32_t));
}
inline void addFloat(float value) {
@@ -719,9 +741,7 @@ private:
void addFloats(const float* values, int32_t count) {
mWriter.writeInt(count);
- for (int32_t i = 0; i < count; i++) {
- mWriter.writeScalar(values[i]);
- }
+ mWriter.write(values, count * sizeof(float));
}
inline void addPoint(float x, float y) {
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index da2192f..7f242c3 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1502,6 +1502,21 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* pai
restore();
}
+void OpenGLRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
+ const float right = left + bitmap->width();
+ const float bottom = top + bitmap->height();
+
+ if (quickReject(left, top, right, bottom)) {
+ return;
+ }
+
+ mCaches.activeTexture(0);
+ Texture* texture = mCaches.textureCache.getTransient(bitmap);
+ const AutoTexture autoCleanup(texture);
+
+ drawTextureRect(left, top, right, bottom, texture, paint);
+}
+
void OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
float* vertices, int* colors, SkPaint* paint) {
// TODO: Do a quickReject
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 18a6923..0ea0db7 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -115,6 +115,7 @@ public:
virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
float srcRight, float srcBottom, float dstLeft, float dstTop,
float dstRight, float dstBottom, SkPaint* paint);
+ virtual void drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint);
virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
float* vertices, int* colors, SkPaint* paint);
virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index cc09aae..9fb61e4 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -160,6 +160,16 @@ Texture* TextureCache::get(SkBitmap* bitmap) {
return texture;
}
+Texture* TextureCache::getTransient(SkBitmap* bitmap) {
+ Texture* texture = new Texture;
+ texture->bitmapSize = bitmap->rowBytes() * bitmap->height();
+ texture->cleanup = true;
+
+ generateTexture(bitmap, texture, false);
+
+ return texture;
+}
+
void TextureCache::remove(SkBitmap* bitmap) {
mCache.remove(bitmap);
}
diff --git a/libs/hwui/TextureCache.h b/libs/hwui/TextureCache.h
index 10a05e0..31a2e3d 100644
--- a/libs/hwui/TextureCache.h
+++ b/libs/hwui/TextureCache.h
@@ -67,6 +67,11 @@ public:
*/
Texture* get(SkBitmap* bitmap);
/**
+ * Returns the texture associated with the specified bitmap. The generated
+ * texture is not kept in the cache. The caller must destroy the texture.
+ */
+ Texture* getTransient(SkBitmap* bitmap);
+ /**
* Removes the texture associated with the specified bitmap.
* Upon remove the texture is freed.
*/