diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 18 | ||||
-rw-r--r-- | libs/hwui/PatchCache.h | 1 | ||||
-rw-r--r-- | libs/hwui/Properties.h | 3 | ||||
-rw-r--r-- | libs/hwui/Snapshot.h | 17 | ||||
-rw-r--r-- | libs/hwui/TextDropShadowCache.cpp | 21 | ||||
-rw-r--r-- | libs/hwui/TextDropShadowCache.h | 35 | ||||
-rw-r--r-- | libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java | 16 | ||||
-rw-r--r-- | libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java | 1 | ||||
-rw-r--r-- | libs/rs/java/tests/src/com/android/rs/test/UT_vector_array.java | 40 | ||||
-rw-r--r-- | libs/rs/java/tests/src/com/android/rs/test/vector_array.rs | 49 | ||||
-rw-r--r-- | libs/rs/rs.spec | 10 | ||||
-rw-r--r-- | libs/rs/rsAllocation.cpp | 54 | ||||
-rw-r--r-- | libs/ui/InputDispatcher.cpp | 16 |
13 files changed, 123 insertions, 158 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index b357973..17b9e83 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -268,7 +268,7 @@ int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom, const GLuint previousFbo = mSnapshot->fbo; const int count = saveSnapshot(flags); - if (!mSnapshot->invisible) { + if (!mSnapshot->isIgnored()) { int alpha = 255; SkXfermode::Mode mode; @@ -385,13 +385,13 @@ bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top, if (bounds.isEmpty() || bounds.getWidth() > mCaches.maxTextureSize || bounds.getHeight() > mCaches.maxTextureSize) { - snapshot->invisible = true; + snapshot->empty = fboLayer; } else { snapshot->invisible = snapshot->invisible || (alpha <= ALPHA_THRESHOLD && fboLayer); } // Bail out if we won't draw in this snapshot - if (snapshot->invisible) { + if (snapshot->invisible || snapshot->empty) { return false; } @@ -731,7 +731,7 @@ void OpenGLRenderer::setupDraw() { } void OpenGLRenderer::clearLayerRegions() { - if (mLayers.size() == 0 || mSnapshot->invisible) return; + if (mLayers.size() == 0 || mSnapshot->isIgnored()) return; Rect clipRect(*mSnapshot->clipRect); clipRect.snapToPixelBoundaries(); @@ -809,7 +809,7 @@ const Rect& OpenGLRenderer::getClipBounds() { } bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) { - if (mSnapshot->invisible) { + if (mSnapshot->isIgnored()) { return true; } @@ -988,7 +988,7 @@ void OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) { // TODO: Should do quickReject for each line - if (mSnapshot->invisible) return; + if (mSnapshot->isIgnored()) return; const bool isAA = paint->isAntiAlias(); const float strokeWidth = paint->getStrokeWidth() * 0.5f; @@ -1112,7 +1112,7 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) { void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) { // No need to check against the clip, we fill the clip region - if (mSnapshot->invisible) return; + if (mSnapshot->isIgnored()) return; Rect& clip(*mSnapshot->clipRect); clip.snapToPixelBoundaries(); @@ -1150,7 +1150,7 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, if (text == NULL || count == 0 || (paint->getAlpha() == 0 && paint->getXfermode() == NULL)) { return; } - if (mSnapshot->invisible) return; + if (mSnapshot->isIgnored()) return; paint->setAntiAlias(true); @@ -1253,7 +1253,7 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, } void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) { - if (mSnapshot->invisible) return; + if (mSnapshot->isIgnored()) return; GLuint textureUnit = 0; glActiveTexture(gTextureUnits[textureUnit]); diff --git a/libs/hwui/PatchCache.h b/libs/hwui/PatchCache.h index 951fba3..62d0ce1 100644 --- a/libs/hwui/PatchCache.h +++ b/libs/hwui/PatchCache.h @@ -19,6 +19,7 @@ #include <utils/KeyedVector.h> +#include "utils/Compare.h" #include "Debug.h" #include "Patch.h" diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h index ac91769..c474936 100644 --- a/libs/hwui/Properties.h +++ b/libs/hwui/Properties.h @@ -39,7 +39,8 @@ enum DebugLevel { kDebugDisabled = 0, kDebugMemory = 1, - kDebugCaches = 2 + kDebugCaches = 2, + kDebugMoreCaches = 3 }; // These properties are defined in mega-bytes diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h index 9f78063..9898df4 100644 --- a/libs/hwui/Snapshot.h +++ b/libs/hwui/Snapshot.h @@ -43,7 +43,7 @@ namespace uirenderer { */ class Snapshot: public LightRefBase<Snapshot> { public: - Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0), invisible(false) { + Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0), invisible(false), empty(false) { transform = &mTransformRoot; clipRect = &mClipRectRoot; region = NULL; @@ -55,7 +55,7 @@ public: */ Snapshot(const sp<Snapshot>& s, int saveFlags): flags(0), previous(s), layer(NULL), fbo(s->fbo), - invisible(s->invisible), viewport(s->viewport), height(s->height) { + invisible(s->invisible), empty(false), viewport(s->viewport), height(s->height) { if (saveFlags & SkCanvas::kMatrix_SaveFlag) { mTransformRoot.load(*s->transform); transform = &mTransformRoot; @@ -203,6 +203,10 @@ public: flags |= Snapshot::kFlagClipSet | Snapshot::kFlagDirtyLocalClip; } + bool isIgnored() const { + return invisible || empty; + } + /** * Dirty flags. */ @@ -225,11 +229,18 @@ public: /** * Indicates that this snapshot is invisible and nothing should be drawn - * inside it. + * inside it. This flag is set only when the layer clips drawing to its + * bounds and is passed to subsequent snapshots. */ bool invisible; /** + * If set to true, the layer will not be composited. This is similar to + * invisible but this flag is not passed to subsequent snapshots. + */ + bool empty; + + /** * Current viewport. */ Rect viewport; diff --git a/libs/hwui/TextDropShadowCache.cpp b/libs/hwui/TextDropShadowCache.cpp index 2f7c7be..d96a7f5 100644 --- a/libs/hwui/TextDropShadowCache.cpp +++ b/libs/hwui/TextDropShadowCache.cpp @@ -37,19 +37,24 @@ TextDropShadowCache::TextDropShadowCache(): LOGD(" Using default drop shadow cache size of %.2fMB", DEFAULT_DROP_SHADOW_CACHE_SIZE); } - mCache.setOnEntryRemovedListener(this); + init(); } TextDropShadowCache::TextDropShadowCache(uint32_t maxByteSize): mCache(GenerationCache<ShadowText, ShadowTexture*>::kUnlimitedCapacity), mSize(0), mMaxSize(maxByteSize) { - mCache.setOnEntryRemovedListener(this); + init(); } TextDropShadowCache::~TextDropShadowCache() { mCache.clear(); } +void TextDropShadowCache::init() { + mCache.setOnEntryRemovedListener(this); + mDebugEnabled = readDebugLevel() & kDebugMoreCaches; +} + /////////////////////////////////////////////////////////////////////////////// // Size management /////////////////////////////////////////////////////////////////////////////// @@ -75,8 +80,11 @@ void TextDropShadowCache::setMaxSize(uint32_t maxSize) { void TextDropShadowCache::operator()(ShadowText& text, ShadowTexture*& texture) { if (texture) { - const uint32_t size = texture->width * texture->height; - mSize -= size; + mSize -= texture->bitmapSize; + + if (mDebugEnabled) { + LOGD("Shadow texture deleted, size = %d", texture->bitmapSize); + } glDeleteTextures(1, &texture->id); delete texture; @@ -109,6 +117,8 @@ ShadowTexture* TextDropShadowCache::get(SkPaint* paint, const char* text, uint32 texture->blend = true; const uint32_t size = shadow.width * shadow.height; + texture->bitmapSize = size; + // Don't even try to cache a bitmap that's bigger than the cache if (size < mMaxSize) { while (mSize + size > mMaxSize) { @@ -132,6 +142,9 @@ ShadowTexture* TextDropShadowCache::get(SkPaint* paint, const char* text, uint32 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (size < mMaxSize) { + if (mDebugEnabled) { + LOGD("Shadow texture created, size = %d", texture->bitmapSize); + } mSize += size; mCache.put(entry, texture); } else { diff --git a/libs/hwui/TextDropShadowCache.h b/libs/hwui/TextDropShadowCache.h index adf09e2..8cefc8c 100644 --- a/libs/hwui/TextDropShadowCache.h +++ b/libs/hwui/TextDropShadowCache.h @@ -21,6 +21,9 @@ #include <SkPaint.h> +#include <utils/String8.h> + +#include "utils/Compare.h" #include "utils/GenerationCache.h" #include "FontRenderer.h" #include "Texture.h" @@ -29,20 +32,20 @@ namespace android { namespace uirenderer { struct ShadowText { - ShadowText() { - text = NULL; + ShadowText(): radius(0), len(0), hash(0), textSize(0.0f), typeface(NULL) { } ShadowText(SkPaint* paint, uint32_t radius, uint32_t len, const char* srcText): radius(radius), len(len) { - text = new char[len]; - memcpy(text, srcText, len); + // The source text we receive is in UTF-16, convert to UTF-8 + str.setTo((const char16_t*) srcText, len >> 1); textSize = paint->getTextSize(); typeface = paint->getTypeface(); hash = 0; uint32_t multiplier = 1; + const char* text = str.string(); for (uint32_t i = 0; i < len; i++) { hash += text[i] * multiplier; uint32_t shifted = multiplier << 5; @@ -52,13 +55,10 @@ struct ShadowText { ShadowText(const ShadowText& shadow): radius(shadow.radius), len(shadow.len), hash(shadow.hash), - textSize(shadow.textSize), typeface(shadow.typeface) { - text = new char[shadow.len]; - memcpy(text, shadow.text, shadow.len); + textSize(shadow.textSize), typeface(shadow.typeface), str(shadow.str) { } ~ShadowText() { - delete[] text; } uint32_t radius; @@ -66,20 +66,16 @@ struct ShadowText { uint32_t hash; float textSize; SkTypeface* typeface; - char *text; + String8 str; bool operator<(const ShadowText& rhs) const { - if (hash < rhs.hash) return true; - else if (hash == rhs.hash) { - if (len < rhs.len) return true; - else if (len == rhs.len) { - if (radius < rhs.radius) return true; - else if (radius == rhs.radius) { - if (textSize < rhs.textSize) return true; - else if (textSize == rhs.textSize) { + LTE_INT(hash) { + LTE_INT(len) { + LTE_INT(radius) { + LTE_FLOAT(textSize) { if (typeface < rhs.typeface) return true; else if (typeface == rhs.typeface) { - return strncmp(text, rhs.text, len) < 0; + return str.compare(rhs.str) < 0; } } } @@ -138,11 +134,14 @@ public: uint32_t getSize(); private: + void init(); + GenerationCache<ShadowText, ShadowTexture*> mCache; uint32_t mSize; uint32_t mMaxSize; FontRenderer* mRenderer; + bool mDebugEnabled; }; // class TextDropShadowCache }; // namespace uirenderer diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java index e935fa9..09654ab 100644 --- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java @@ -283,7 +283,7 @@ public class ImageProcessingActivity extends Activity long t = java.lang.System.currentTimeMillis(); if (true) { mScript.invoke_filter(); - mRS.finish(); + mOutPixelsAllocation.copyTo(mBitmapOut); } else { javaFilter(); mDisplayView.invalidate(); @@ -352,7 +352,7 @@ public class ImageProcessingActivity extends Activity public void surfaceCreated(SurfaceHolder holder) { createScript(); mScript.invoke_filter(); - mRS.finish(); + mOutPixelsAllocation.copyTo(mBitmapOut); } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { @@ -365,8 +365,12 @@ public class ImageProcessingActivity extends Activity mRS = RenderScript.create(); mRS.setMessageHandler(new FilterCallback()); - mInPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapIn); - mOutPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapOut); + mInPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapIn, + Allocation.MipmapControl.MIPMAP_NONE, + Allocation.USAGE_SCRIPT); + mOutPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapOut, + Allocation.MipmapControl.MIPMAP_NONE, + Allocation.USAGE_SCRIPT); Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS)); tb.setX(mBitmapIn.getWidth()); @@ -419,7 +423,7 @@ public class ImageProcessingActivity extends Activity long t = java.lang.System.currentTimeMillis(); mScript.invoke_filter(); - mRS.finish(); + mOutPixelsAllocation.copyTo(mBitmapOut); t = java.lang.System.currentTimeMillis() - t; android.util.Log.v("Img", "Renderscript frame time core ms " + t); @@ -432,6 +436,6 @@ public class ImageProcessingActivity extends Activity mScript.set_radius(mRadius); mScript.invoke_filter(); - mRS.finish(); + mOutPixelsAllocation.copyTo(mBitmapOut); } } diff --git a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java index 11b0fcd..c1f652f 100644 --- a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java +++ b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java @@ -64,7 +64,6 @@ public class RSTestCore { unitTests.add(new UT_primitives(this, mRes)); unitTests.add(new UT_rsdebug(this, mRes)); unitTests.add(new UT_rstypes(this, mRes)); - unitTests.add(new UT_vector_array(this, mRes)); unitTests.add(new UT_fp_mad(this, mRes)); /* unitTests.add(new UnitTest(null, "<Pass>", 1)); diff --git a/libs/rs/java/tests/src/com/android/rs/test/UT_vector_array.java b/libs/rs/java/tests/src/com/android/rs/test/UT_vector_array.java deleted file mode 100644 index 6798781..0000000 --- a/libs/rs/java/tests/src/com/android/rs/test/UT_vector_array.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.rs.test; - -import android.content.res.Resources; -import android.renderscript.*; - -public class UT_vector_array extends UnitTest { - private Resources mRes; - - protected UT_vector_array(RSTestCore rstc, Resources res) { - super(rstc, "Vector Array"); - mRes = res; - } - - public void run() { - RenderScript pRS = RenderScript.create(); - ScriptC_vector_array s = new ScriptC_vector_array(pRS, mRes, R.raw.vector_array); - pRS.setMessageHandler(mRsMessage); - s.invoke_vector_array_test(); - pRS.finish(); - waitForMessage(); - pRS.destroy(); - } -} - diff --git a/libs/rs/java/tests/src/com/android/rs/test/vector_array.rs b/libs/rs/java/tests/src/com/android/rs/test/vector_array.rs deleted file mode 100644 index 49e38c1..0000000 --- a/libs/rs/java/tests/src/com/android/rs/test/vector_array.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2009 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "shared.rsh" - -typedef struct float3Struct{ - float3 arr[2]; -} float3Struct; - -float3Struct f; - -bool size_test() { - bool failed = false; - int expectedSize = 2 * 3 * (int) sizeof(float); - int actualSize = (int) sizeof(f); - - rsDebug("Size of struct { float3 arr[2]; } (expected):", expectedSize); - rsDebug("Size of struct { float3 arr[2]; } (actual) :", actualSize); - - if (expectedSize != actualSize) { - failed = true; - } - - return failed; -} - -void vector_array_test() { - bool failed = false; - failed |= size_test(); - - if (failed) { - rsSendToClientBlocking(RS_MSG_TEST_FAILED); - } - else { - rsSendToClientBlocking(RS_MSG_TEST_PASSED); - } -} - diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 97ecca0..14094c4 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -77,10 +77,16 @@ ElementCreate2 { ret RsElement } -AllocationUpdateFromBitmap { +AllocationCopyFromBitmap { param RsAllocation alloc - param RsElement srcFmt param const void * data + param size_t dataLen + } + +AllocationCopyToBitmap { + param RsAllocation alloc + param void * data + param size_t dataLen } AllocationCreateBitmapRef { diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index f42be0e..10a5caf 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -763,32 +763,44 @@ RsAllocation rsi_AllocationCreateBitmapRef(Context *rsc, RsType vtype, return alloc; } -void rsi_AllocationUpdateFromBitmap(Context *rsc, RsAllocation va, - RsElement _src, const void *data) { +void rsi_AllocationCopyFromBitmap(Context *rsc, RsAllocation va, const void *data, size_t dataLen) { Allocation *texAlloc = static_cast<Allocation *>(va); - const Element *src = static_cast<const Element *>(_src); - const Element *dst = texAlloc->getType()->getElement(); - uint32_t w = texAlloc->getType()->getDimX(); - uint32_t h = texAlloc->getType()->getDimY(); - bool genMips = texAlloc->getType()->getDimLOD(); - - ElementConverter_t cvt = pickConverter(dst, src); - if (cvt) { - cvt(texAlloc->getPtr(), data, w * h); - if (genMips) { - Adapter2D adapt(rsc, texAlloc); - Adapter2D adapt2(rsc, texAlloc); - for (uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) { - adapt.setLOD(lod); - adapt2.setLOD(lod + 1); - mip(adapt2, adapt); - } + const Type * t = texAlloc->getType(); + + uint32_t w = t->getDimX(); + uint32_t h = t->getDimY(); + bool genMips = t->getDimLOD(); + size_t s = w * h * t->getElementSizeBytes(); + if (s != dataLen) { + rsc->setError(RS_ERROR_BAD_VALUE, "Bitmap size didn't match allocation size"); + return; + } + + memcpy(texAlloc->getPtr(), data, s); + if (genMips) { + Adapter2D adapt(rsc, texAlloc); + Adapter2D adapt2(rsc, texAlloc); + for (uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) { + adapt.setLOD(lod); + adapt2.setLOD(lod + 1); + mip(adapt2, adapt); } - } else { - rsc->setError(RS_ERROR_BAD_VALUE, "Unsupported bitmap format"); } } +void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t dataLen) { + Allocation *texAlloc = static_cast<Allocation *>(va); + const Type * t = texAlloc->getType(); + + size_t s = t->getDimX() * t->getDimY() * t->getElementSizeBytes(); + if (s != dataLen) { + rsc->setError(RS_ERROR_BAD_VALUE, "Bitmap size didn't match allocation size"); + return; + } + + memcpy(data, texAlloc->getPtr(), s); +} + void rsi_AllocationData(Context *rsc, RsAllocation va, const void *data, uint32_t sizeBytes) { Allocation *a = static_cast<Allocation *>(va); a->data(rsc, data, sizeBytes); diff --git a/libs/ui/InputDispatcher.cpp b/libs/ui/InputDispatcher.cpp index 1f6a920..ed0cb8e 100644 --- a/libs/ui/InputDispatcher.cpp +++ b/libs/ui/InputDispatcher.cpp @@ -908,9 +908,11 @@ void InputDispatcher::resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout ssize_t connectionIndex = getConnectionIndexLocked(inputChannel); if (connectionIndex >= 0) { sp<Connection> connection = mConnectionsByReceiveFd.valueAt(connectionIndex); - synthesizeCancelationEventsForConnectionLocked( - connection, InputState::CANCEL_ALL_EVENTS, - "application not responding"); + if (connection->status == Connection::STATUS_NORMAL) { + synthesizeCancelationEventsForConnectionLocked( + connection, InputState::CANCEL_ALL_EVENTS, + "application not responding"); + } } } } @@ -3056,7 +3058,7 @@ void InputDispatcher::doDispatchCycleFinishedLockedInterruptible( // the original UP in which case we would not generate the fallback UP. synthesizeCancelationEventsForConnectionLocked(connection, InputState::CANCEL_FALLBACK_EVENTS, - "Application handled a non-fallback event."); + "application handled a non-fallback event, canceling all fallback events"); } else { // If the application did not handle a non-fallback key, then ask // the policy what to do with it. We might generate a fallback key @@ -3071,6 +3073,12 @@ void InputDispatcher::doDispatchCycleFinishedLockedInterruptible( mLock.lock(); + if (connection->status != Connection::STATUS_NORMAL) { + return; + } + + assert(connection->outboundQueue.headSentinel.next == dispatchEntry); + if (fallback) { // Restart the dispatch cycle using the fallback key. keyEntry->eventTime = event.getEventTime(); |