diff options
Diffstat (limited to 'libs')
34 files changed, 364 insertions, 207 deletions
diff --git a/libs/camera/CameraParameters.cpp b/libs/camera/CameraParameters.cpp index c295315..9392cf2 100644 --- a/libs/camera/CameraParameters.cpp +++ b/libs/camera/CameraParameters.cpp @@ -146,6 +146,7 @@ const char CameraParameters::PIXEL_FORMAT_YUV420SP[] = "yuv420sp"; const char CameraParameters::PIXEL_FORMAT_YUV422I[] = "yuv422i-yuyv"; const char CameraParameters::PIXEL_FORMAT_YUV420P[] = "yuv420p"; const char CameraParameters::PIXEL_FORMAT_RGB565[] = "rgb565"; +const char CameraParameters::PIXEL_FORMAT_RGBA8888[] = "rgba8888"; const char CameraParameters::PIXEL_FORMAT_JPEG[] = "jpeg"; // Values for focus mode settings. diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp index f8582d8..afab26a 100644 --- a/libs/hwui/DisplayListRenderer.cpp +++ b/libs/hwui/DisplayListRenderer.cpp @@ -1151,6 +1151,7 @@ void DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) { void DisplayListRenderer::drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint) { + if (count <= 0) return; addOp(DisplayList::DrawText); addText(text, bytesCount); addInt(count); diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index 1ca0a19..9bf3de8 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -35,6 +35,7 @@ namespace uirenderer { #define DEFAULT_TEXT_CACHE_WIDTH 1024 #define DEFAULT_TEXT_CACHE_HEIGHT 256 +// We should query these values from the GL context #define MAX_TEXT_CACHE_WIDTH 2048 #define MAX_TEXT_CACHE_HEIGHT 2048 @@ -58,8 +59,7 @@ Font::~Font() { } for (uint32_t i = 0; i < mCachedGlyphs.size(); i++) { - CachedGlyphInfo* glyph = mCachedGlyphs.valueAt(i); - delete glyph; + delete mCachedGlyphs.valueAt(i); } } @@ -134,48 +134,49 @@ void Font::drawCachedGlyph(CachedGlyphInfo* glyph, int x, int y, } -Font::CachedGlyphInfo* Font::getCachedUTFChar(SkPaint* paint, int32_t utfChar) { +Font::CachedGlyphInfo* Font::getCachedGlyph(SkPaint* paint, glyph_t textUnit) { CachedGlyphInfo* cachedGlyph = NULL; - ssize_t index = mCachedGlyphs.indexOfKey(utfChar); + ssize_t index = mCachedGlyphs.indexOfKey(textUnit); if (index >= 0) { cachedGlyph = mCachedGlyphs.valueAt(index); } else { - cachedGlyph = cacheGlyph(paint, utfChar); + cachedGlyph = cacheGlyph(paint, textUnit); } // Is the glyph still in texture cache? if (!cachedGlyph->mIsValid) { - const SkGlyph& skiaGlyph = paint->getUnicharMetrics(utfChar); + const SkGlyph& skiaGlyph = GET_METRICS(paint, textUnit); updateGlyphCache(paint, skiaGlyph, cachedGlyph); } return cachedGlyph; } -void Font::renderUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t len, +void Font::render(SkPaint* paint, const char* text, uint32_t start, uint32_t len, int numGlyphs, int x, int y, uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH) { if (bitmap != NULL && bitmapW > 0 && bitmapH > 0) { - renderUTF(paint, text, start, len, numGlyphs, x, y, BITMAP, bitmap, + render(paint, text, start, len, numGlyphs, x, y, BITMAP, bitmap, bitmapW, bitmapH, NULL); } else { - renderUTF(paint, text, start, len, numGlyphs, x, y, FRAMEBUFFER, NULL, 0, 0, NULL); + render(paint, text, start, len, numGlyphs, x, y, FRAMEBUFFER, NULL, + 0, 0, NULL); } } -void Font::measureUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t len, +void Font::measure(SkPaint* paint, const char* text, uint32_t start, uint32_t len, int numGlyphs, Rect *bounds) { if (bounds == NULL) { LOGE("No return rectangle provided to measure text"); return; } bounds->set(1e6, -1e6, -1e6, 1e6); - renderUTF(paint, text, start, len, numGlyphs, 0, 0, MEASURE, NULL, 0, 0, bounds); + render(paint, text, start, len, numGlyphs, 0, 0, MEASURE, NULL, 0, 0, bounds); } #define SkAutoKern_AdjustF(prev, next) (((next) - (prev) + 32) >> 6 << 16) -void Font::renderUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t len, +void Font::render(SkPaint* paint, const char* text, uint32_t start, uint32_t len, int numGlyphs, int x, int y, RenderMode mode, uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH,Rect *bounds) { if (numGlyphs == 0 || text == NULL || len == 0) { @@ -195,14 +196,14 @@ void Font::renderUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t text += start; while (glyphsLeft > 0) { - int32_t utfChar = SkUTF16_NextUnichar((const uint16_t**) &text); + glyph_t glyph = GET_GLYPH(text); // Reached the end of the string - if (utfChar < 0) { + if (IS_END_OF_STRING(glyph)) { break; } - CachedGlyphInfo* cachedGlyph = getCachedUTFChar(paint, utfChar); + CachedGlyphInfo* cachedGlyph = getCachedGlyph(paint, glyph); penX += SkAutoKern_AdjustF(prevRsbDelta, cachedGlyph->mLsbDelta); prevRsbDelta = cachedGlyph->mRsbDelta; @@ -268,11 +269,11 @@ void Font::updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyp mState->mUploadTexture = true; } -Font::CachedGlyphInfo* Font::cacheGlyph(SkPaint* paint, int32_t glyph) { +Font::CachedGlyphInfo* Font::cacheGlyph(SkPaint* paint, glyph_t glyph) { CachedGlyphInfo* newGlyph = new CachedGlyphInfo(); mCachedGlyphs.add(glyph, newGlyph); - const SkGlyph& skiaGlyph = paint->getUnicharMetrics(glyph); + const SkGlyph& skiaGlyph = GET_METRICS(paint, glyph); newGlyph->mGlyphIndex = skiaGlyph.fID; newGlyph->mIsValid = false; @@ -672,7 +673,7 @@ void FontRenderer::precacheLatin(SkPaint* paint) { uint32_t remainingCapacity = getRemainingCacheCapacity(); uint32_t precacheIdx = 0; while (remainingCapacity > 25 && precacheIdx < mLatinPrecache.size()) { - mCurrentFont->getCachedUTFChar(paint, (int32_t) mLatinPrecache[precacheIdx]); + mCurrentFont->getCachedGlyph(paint, (int32_t) mLatinPrecache[precacheIdx]); remainingCapacity = getRemainingCacheCapacity(); precacheIdx ++; } @@ -714,7 +715,7 @@ FontRenderer::DropShadow FontRenderer::renderDropShadow(SkPaint* paint, const ch } Rect bounds; - mCurrentFont->measureUTF(paint, text, startIndex, len, numGlyphs, &bounds); + mCurrentFont->measure(paint, text, startIndex, len, numGlyphs, &bounds); uint32_t paddedWidth = (uint32_t) (bounds.right - bounds.left) + 2 * radius; uint32_t paddedHeight = (uint32_t) (bounds.top - bounds.bottom) + 2 * radius; uint8_t* dataBuffer = new uint8_t[paddedWidth * paddedHeight]; @@ -725,7 +726,7 @@ FontRenderer::DropShadow FontRenderer::renderDropShadow(SkPaint* paint, const ch int penX = radius - bounds.left; int penY = radius - bounds.bottom; - mCurrentFont->renderUTF(paint, text, startIndex, len, numGlyphs, penX, penY, + mCurrentFont->render(paint, text, startIndex, len, numGlyphs, penX, penY, dataBuffer, paddedWidth, paddedHeight); blurImage(dataBuffer, paddedWidth, paddedHeight, radius); @@ -755,7 +756,7 @@ bool FontRenderer::renderText(SkPaint* paint, const Rect* clip, const char *text mDrawn = false; mBounds = bounds; mClip = clip; - mCurrentFont->renderUTF(paint, text, startIndex, len, numGlyphs, x, y); + mCurrentFont->render(paint, text, startIndex, len, numGlyphs, x, y); mBounds = NULL; if (mCurrentQuadIndex != 0) { diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h index 95f714f..24ed6fa 100644 --- a/libs/hwui/FontRenderer.h +++ b/libs/hwui/FontRenderer.h @@ -33,8 +33,32 @@ namespace android { namespace uirenderer { +/////////////////////////////////////////////////////////////////////////////// +// Defines +/////////////////////////////////////////////////////////////////////////////// + +#if RENDER_TEXT_AS_GLYPHS + typedef uint16_t glyph_t; + #define GET_METRICS(paint, glyph) paint->getGlyphMetrics(glyph) + #define GET_GLYPH(text) nextGlyph((const uint16_t**) &text) + #define IS_END_OF_STRING(glyph) false +#else + typedef SkUnichar glyph_t; + #define GET_METRICS(paint, glyph) paint->getUnicharMetrics(glyph) + #define GET_GLYPH(text) SkUTF16_NextUnichar((const uint16_t**) &text) + #define IS_END_OF_STRING(glyph) glyph < 0 +#endif + +/////////////////////////////////////////////////////////////////////////////// +// Declarations +/////////////////////////////////////////////////////////////////////////////// + class FontRenderer; +/////////////////////////////////////////////////////////////////////////////// +// Font +/////////////////////////////////////////////////////////////////////////////// + /** * Represents a font, defined by a Skia font id and a font size. A font is used * to generate glyphs and cache them in the FontState. @@ -51,9 +75,9 @@ public: * Renders the specified string of text. * If bitmap is specified, it will be used as the render target */ - void renderUTF(SkPaint* paint, const char *text, uint32_t start, uint32_t len, - int numGlyphs, int x, int y, - uint8_t *bitmap = NULL, uint32_t bitmapW = 0, uint32_t bitmapH = 0); + void render(SkPaint* paint, const char *text, uint32_t start, uint32_t len, + int numGlyphs, int x, int y, uint8_t *bitmap = NULL, + uint32_t bitmapW = 0, uint32_t bitmapH = 0); /** * Creates a new font associated with the specified font state. */ @@ -69,13 +93,12 @@ protected: MEASURE, }; - void renderUTF(SkPaint* paint, const char *text, uint32_t start, uint32_t len, - int numGlyphs, int x, int y, RenderMode mode, - uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH, - Rect *bounds); + void render(SkPaint* paint, const char *text, uint32_t start, uint32_t len, + int numGlyphs, int x, int y, RenderMode mode, uint8_t *bitmap, + uint32_t bitmapW, uint32_t bitmapH, Rect *bounds); - void measureUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t len, - int numGlyphs, Rect *bounds); + void measure(SkPaint* paint, const char* text, uint32_t start, uint32_t len, + int numGlyphs, Rect *bounds); struct CachedGlyphInfo { // Has the cache been invalidated? @@ -107,18 +130,26 @@ protected: Font(FontRenderer* state, uint32_t fontId, float fontSize, int flags, uint32_t italicStyle, uint32_t scaleX); - DefaultKeyedVector<int32_t, CachedGlyphInfo*> mCachedGlyphs; + // Cache of glyphs + DefaultKeyedVector<glyph_t, CachedGlyphInfo*> mCachedGlyphs; void invalidateTextureCache(); - CachedGlyphInfo* cacheGlyph(SkPaint* paint, int32_t glyph); + CachedGlyphInfo* cacheGlyph(SkPaint* paint, glyph_t glyph); void updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyphInfo *glyph); void measureCachedGlyph(CachedGlyphInfo *glyph, int x, int y, Rect *bounds); void drawCachedGlyph(CachedGlyphInfo *glyph, int x, int y); void drawCachedGlyph(CachedGlyphInfo *glyph, int x, int y, - uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH); + uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH); - CachedGlyphInfo* getCachedUTFChar(SkPaint* paint, int32_t utfChar); + CachedGlyphInfo* getCachedGlyph(SkPaint* paint, glyph_t textUnit); + + static glyph_t nextGlyph(const uint16_t** srcPtr) { + const uint16_t* src = *srcPtr; + glyph_t g = *src++; + *srcPtr = src; + return g; + } FontRenderer* mState; uint32_t mFontId; @@ -128,6 +159,10 @@ protected: uint32_t mScaleX; }; +/////////////////////////////////////////////////////////////////////////////// +// Renderer +/////////////////////////////////////////////////////////////////////////////// + class FontRenderer { public: FontRenderer(); diff --git a/libs/hwui/Matrix.cpp b/libs/hwui/Matrix.cpp index e7c0fe3..9fc5131 100644 --- a/libs/hwui/Matrix.cpp +++ b/libs/hwui/Matrix.cpp @@ -67,6 +67,10 @@ bool Matrix4::isPureTranslate() { ALMOST_EQUAL(data[kScaleX], 1.0f) && ALMOST_EQUAL(data[kScaleY], 1.0f); } +bool Matrix4::isSimple() { + return mSimpleMatrix; +} + void Matrix4::load(const float* v) { memcpy(data, v, sizeof(data)); mSimpleMatrix = false; diff --git a/libs/hwui/Matrix.h b/libs/hwui/Matrix.h index 08f5d77..2fa6ab7 100644 --- a/libs/hwui/Matrix.h +++ b/libs/hwui/Matrix.h @@ -111,6 +111,7 @@ public: } bool isPureTranslate(); + bool isSimple(); bool changesBounds(); diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 6243b01..6c9c0eb 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -1478,8 +1478,7 @@ void OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int * within that boundary region and how far into the region it is. */ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom, - int color, SkXfermode::Mode mode) -{ + int color, SkXfermode::Mode mode) { float inverseScaleX = 1.0f; float inverseScaleY = 1.0f; // The quad that we use needs to account for scaling. @@ -1935,7 +1934,7 @@ void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, } int color = p->getColor(); - if (p->isAntiAlias()) { + if (p->isAntiAlias() && !mSnapshot->transform->isSimple()) { drawAARect(left, top, right, bottom, color, mode); } else { drawColorRect(left, top, right, bottom, color, mode); @@ -1949,7 +1948,16 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, } if (mSnapshot->isIgnored()) return; + // TODO: We should probably make a copy of the paint instead of modifying + // it; modifying the paint will change its generationID the first + // time, which might impact caches. More investigation needed to + // see if it matters. + // If we make a copy, then drawTextDecorations() should *not* make + // its own copy as it does right now. paint->setAntiAlias(true); +#if RENDER_TEXT_AS_GLYPHS + paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); +#endif float length = -1.0f; switch (paint->getTextAlign()) { @@ -1983,8 +1991,8 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, if (mHasShadow) { mCaches.dropShadowCache.setFontRenderer(fontRenderer); - const ShadowTexture* shadow = mCaches.dropShadowCache.get(paint, text, bytesCount, - count, mShadowRadius); + const ShadowTexture* shadow = mCaches.dropShadowCache.get( + paint, text, bytesCount, count, mShadowRadius); const AutoTexture autoCleanup(shadow); const float sx = oldX - shadow->left + mShadowDx; @@ -2073,11 +2081,6 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, drawTextDecorations(text, bytesCount, length, oldX, oldY, paint); } -void OpenGLRenderer::drawGlyphs(const char* glyphs, int index, int count, float x, float y, - SkPaint* paint) { - // TODO -} - void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) { if (mSnapshot->isIgnored()) return; @@ -2230,14 +2233,15 @@ void OpenGLRenderer::drawTextDecorations(const char* text, int bytesCount, float // Handle underline and strike-through uint32_t flags = paint->getFlags(); if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) { + SkPaint paintCopy(*paint); float underlineWidth = length; // If length is > 0.0f, we already measured the text for the text alignment if (length <= 0.0f) { - underlineWidth = paint->measureText(text, bytesCount); + underlineWidth = paintCopy.measureText(text, bytesCount); } float offsetX = 0; - switch (paint->getTextAlign()) { + switch (paintCopy.getTextAlign()) { case SkPaint::kCenter_Align: offsetX = underlineWidth * 0.5f; break; @@ -2249,8 +2253,7 @@ void OpenGLRenderer::drawTextDecorations(const char* text, int bytesCount, float } if (underlineWidth > 0.0f) { - const float textSize = paint->getTextSize(); - // TODO: Support stroke width < 1.0f when we have AA lines + const float textSize = paintCopy.getTextSize(); const float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f); const float left = x - offsetX; @@ -2280,10 +2283,9 @@ void OpenGLRenderer::drawTextDecorations(const char* text, int bytesCount, float points[currentPoint++] = top; } - SkPaint linesPaint(*paint); - linesPaint.setStrokeWidth(strokeWidth); + paintCopy.setStrokeWidth(strokeWidth); - drawLines(&points[0], pointsCount, &linesPaint); + drawLines(&points[0], pointsCount, &paintCopy); } } } diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index e2dbba0..549d6e9 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -123,8 +123,6 @@ public: virtual void drawPoints(float* points, int count, SkPaint* paint); virtual void drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint); - virtual void drawGlyphs(const char* glyphs, int index, int count, float x, float y, - SkPaint* paint); virtual void resetShader(); virtual void setupShader(SkiaShader* shader); diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h index 2d8b6f3..7c10518 100644 --- a/libs/hwui/Properties.h +++ b/libs/hwui/Properties.h @@ -28,6 +28,9 @@ // If turned on, layers drawn inside FBOs are optimized with regions #define RENDER_LAYERS_AS_REGIONS 1 +// If turned on, text is interpreted as glyphs instead of UTF-16 +#define RENDER_TEXT_AS_GLYPHS 1 + /** * Debug level for app developers. */ diff --git a/libs/hwui/TextDropShadowCache.h b/libs/hwui/TextDropShadowCache.h index d46686d..28dba13 100644 --- a/libs/hwui/TextDropShadowCache.h +++ b/libs/hwui/TextDropShadowCache.h @@ -73,7 +73,6 @@ struct ShadowText { text = str.string(); } - // TODO: Should take into account fake bold and text skew bool operator<(const ShadowText& rhs) const { LTE_INT(len) { LTE_INT(radius) { diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk index 9c9fae3..9fabf8d 100644 --- a/libs/rs/Android.mk +++ b/libs/rs/Android.mk @@ -149,24 +149,82 @@ include $(BUILD_SHARED_LIBRARY) # Now build a host version for serialization include $(CLEAR_VARS) +LOCAL_MODULE:= libRS +LOCAL_MODULE_TAGS := optional + +intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,HOST,) + +# Generate custom headers + +GEN := $(addprefix $(intermediates)/, \ + rsgApiStructs.h \ + rsgApiFuncDecl.h \ + ) + +$(GEN) : PRIVATE_PATH := $(LOCAL_PATH) +$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(PRIVATE_PATH)/rs.spec +$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec +$(GEN): $(intermediates)/%.h : $(LOCAL_PATH)/%.h.rsg + $(transform-generated-source) + +LOCAL_GENERATED_SOURCES += $(GEN) + +# Generate custom source files + +GEN := $(addprefix $(intermediates)/, \ + rsgApi.cpp \ + rsgApiReplay.cpp \ + ) + +$(GEN) : PRIVATE_PATH := $(LOCAL_PATH) +$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(PRIVATE_PATH)/rs.spec +$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec +$(GEN): $(intermediates)/%.cpp : $(LOCAL_PATH)/%.cpp.rsg + $(transform-generated-source) + +LOCAL_GENERATED_SOURCES += $(GEN) + LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable LOCAL_CFLAGS += -DANDROID_RS_SERIALIZE +LOCAL_CFLAGS += -fPIC LOCAL_SRC_FILES:= \ + rsAdapter.cpp \ rsAllocation.cpp \ + rsAnimation.cpp \ rsComponent.cpp \ + rsContext.cpp \ + rsDevice.cpp \ rsElement.cpp \ + rsFBOCache.cpp \ + rsFifoSocket.cpp \ rsFileA3D.cpp \ + rsFont.cpp \ + rsLocklessFifo.cpp \ rsObjectBase.cpp \ + rsMatrix2x2.cpp \ + rsMatrix3x3.cpp \ + rsMatrix4x4.cpp \ rsMesh.cpp \ + rsMutex.cpp \ + rsProgram.cpp \ + rsProgramFragment.cpp \ + rsProgramStore.cpp \ + rsProgramRaster.cpp \ + rsProgramVertex.cpp \ + rsSampler.cpp \ + rsScript.cpp \ + rsScriptC.cpp \ + rsScriptC_Lib.cpp \ + rsScriptC_LibGL.cpp \ + rsSignal.cpp \ rsStream.cpp \ + rsThreadIO.cpp \ rsType.cpp LOCAL_STATIC_LIBRARIES := libcutils libutils LOCAL_LDLIBS := -lpthread -LOCAL_MODULE:= libRSserialize -LOCAL_MODULE_TAGS := optional include $(BUILD_HOST_STATIC_LIBRARY) diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h index 3f2d67a..535f713 100644 --- a/libs/rs/RenderScript.h +++ b/libs/rs/RenderScript.h @@ -55,15 +55,7 @@ void rsDeviceSetConfig(RsDevice dev, RsDeviceParam p, int32_t value); RsContext rsContextCreate(RsDevice dev, uint32_t version); RsContext rsContextCreateGL(RsDevice dev, uint32_t version, RsSurfaceConfig sc, uint32_t dpi); - - -#ifdef ANDROID_RS_SERIALIZE -#define NO_RS_FUNCS -#endif - -#ifndef NO_RS_FUNCS #include "rsgApiFuncDecl.h" -#endif #ifdef __cplusplus }; diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index 94d55a6..01cc369 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -36,6 +36,7 @@ #include <cutils/sched_policy.h> #include <sys/syscall.h> #include <string.h> +#include <bcc/bcc.h> using namespace android; using namespace android::renderscript; diff --git a/libs/rs/driver/rsdCore.h b/libs/rs/driver/rsdCore.h index 422bb1b..f393b60 100644 --- a/libs/rs/driver/rsdCore.h +++ b/libs/rs/driver/rsdCore.h @@ -18,7 +18,6 @@ #define RSD_CORE_H #include <rs_hal.h> -#include <bcc/bcc.h> #include "rsMutex.h" #include "rsSignal.h" diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index 05412c7..bff3660 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -168,13 +168,10 @@ void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, } void Allocation::addProgramToDirty(const Program *p) { -#ifndef ANDROID_RS_SERIALIZE mToDirtyList.push(p); -#endif //ANDROID_RS_SERIALIZE } void Allocation::removeProgramToDirty(const Program *p) { -#ifndef ANDROID_RS_SERIALIZE for (size_t ct=0; ct < mToDirtyList.size(); ct++) { if (mToDirtyList[ct] == p) { mToDirtyList.removeAt(ct); @@ -182,7 +179,6 @@ void Allocation::removeProgramToDirty(const Program *p) { } } rsAssert(0); -#endif //ANDROID_RS_SERIALIZE } void Allocation::dumpLOGV(const char *prefix) const { @@ -254,11 +250,9 @@ Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) { } void Allocation::sendDirty(const Context *rsc) const { -#ifndef ANDROID_RS_SERIALIZE for (size_t ct=0; ct < mToDirtyList.size(); ct++) { mToDirtyList[ct]->forceDirty(); } -#endif //ANDROID_RS_SERIALIZE mRSC->mHal.funcs.allocation.markDirty(rsc, this); } @@ -312,8 +306,6 @@ void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) { ///////////////// // -#ifndef ANDROID_RS_SERIALIZE - namespace android { namespace renderscript { @@ -413,25 +405,25 @@ void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_ } void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod, - uint32_t count, const void *data, uint32_t sizeBytes) { + uint32_t count, const void *data, size_t sizeBytes) { Allocation *a = static_cast<Allocation *>(va); a->data(rsc, xoff, lod, count, data, sizeBytes); } void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face, - const void *data, uint32_t eoff, uint32_t sizeBytes) { + const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped Allocation *a = static_cast<Allocation *>(va); a->elementData(rsc, x, y, data, eoff, sizeBytes); } void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod, - const void *data, uint32_t eoff, uint32_t sizeBytes) { + const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped Allocation *a = static_cast<Allocation *>(va); a->elementData(rsc, x, data, eoff, sizeBytes); } void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, - uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes) { + uint32_t w, uint32_t h, const void *data, size_t sizeBytes) { Allocation *a = static_cast<Allocation *>(va); a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes); } @@ -549,5 +541,3 @@ const void * rsaAllocationGetType(RsContext con, RsAllocation va) { return a->getType(); } - -#endif //ANDROID_RS_SERIALIZE diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h index 5cf6292..f538dd1 100644 --- a/libs/rs/rsAllocation.h +++ b/libs/rs/rsAllocation.h @@ -59,7 +59,6 @@ public: static Allocation * createAllocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc = RS_ALLOCATION_MIPMAP_NONE); - virtual ~Allocation(); void updateCache(); @@ -121,14 +120,6 @@ protected: private: Allocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc); - - void upload2DTexture(bool isFirstUpload); - void update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff, - uint32_t lod, RsAllocationCubemapFace face, uint32_t w, uint32_t h); - - void allocScriptMemory(); - void freeScriptMemory(); - }; } diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index bab5c58..44e9d89 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -92,9 +92,13 @@ uint32_t Context::runRootScript() { } uint64_t Context::getTime() const { +#ifndef ANDROID_RS_SERIALIZE struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000); +#else + return 0; +#endif //ANDROID_RS_SERIALIZE } void Context::timerReset() { @@ -200,11 +204,11 @@ void Context::displayDebugStats() { void * Context::threadProc(void *vrsc) { Context *rsc = static_cast<Context *>(vrsc); +#ifndef ANDROID_RS_SERIALIZE rsc->mNativeThreadId = gettid(); - setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY); rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY; - +#endif //ANDROID_RS_SERIALIZE rsc->props.mLogTimes = getProp("debug.rs.profile"); rsc->props.mLogScripts = getProp("debug.rs.script"); rsc->props.mLogObjects = getProp("debug.rs.object"); @@ -330,10 +334,16 @@ Context::Context() { mObjHead = NULL; mError = RS_ERROR_NONE; mDPI = 96; + mIsContextLite = false; } Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc) { Context * rsc = new Context(); + + // Temporary to avoid breaking the tools + if (!dev) { + return rsc; + } if (!rsc->initContext(dev, sc)) { delete rsc; return NULL; @@ -341,6 +351,12 @@ Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc) { return rsc; } +Context * Context::createContextLite() { + Context * rsc = new Context(); + rsc->mIsContextLite = true; + return rsc; +} + bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) { pthread_mutex_lock(&gInitMutex); @@ -395,26 +411,28 @@ bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) { Context::~Context() { LOGV("Context::~Context"); - mIO.coreFlush(); - rsAssert(mExit); - mExit = true; - mPaused = false; - void *res; + if (!mIsContextLite) { + mIO.coreFlush(); + rsAssert(mExit); + mExit = true; + mPaused = false; + void *res; - mIO.shutdown(); - int status = pthread_join(mThreadId, &res); + mIO.shutdown(); + int status = pthread_join(mThreadId, &res); - if (mHal.funcs.shutdownDriver) { - mHal.funcs.shutdownDriver(this); - } + if (mHal.funcs.shutdownDriver) { + mHal.funcs.shutdownDriver(this); + } - // Global structure cleanup. - pthread_mutex_lock(&gInitMutex); - if (mDev) { - mDev->removeContext(this); - mDev = NULL; + // Global structure cleanup. + pthread_mutex_lock(&gInitMutex); + if (mDev) { + mDev->removeContext(this); + mDev = NULL; + } + pthread_mutex_unlock(&gInitMutex); } - pthread_mutex_unlock(&gInitMutex); LOGV("Context::~Context done"); } @@ -542,7 +560,7 @@ void Context::dumpDebug() const { LOGE(" RS width %i, height %i", mWidth, mHeight); LOGE(" RS running %i, exit %i, paused %i", mRunning, mExit, mPaused); - LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId); + LOGE(" RS pThreadID %li, nativeThreadID %i", (long int)mThreadId, mNativeThreadId); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -595,7 +613,7 @@ void rsi_ContextBindFont(Context *rsc, RsFont vfont) { rsc->setFont(font); } -void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, uint32_t name_length) { +void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, size_t name_length) { ObjectBase *ob = static_cast<ObjectBase *>(obj); rsc->assignName(ob, name, name_length); } @@ -627,7 +645,7 @@ void rsi_ContextDump(Context *rsc, int32_t bits) { } void rsi_ContextDestroyWorker(Context *rsc) { - rsc->destroyWorkerThreadResources();; + rsc->destroyWorkerThreadResources(); } void rsi_ContextDestroy(Context *rsc) { diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index 4ba00fe..309fe95 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -24,7 +24,6 @@ #include "rs_hal.h" -#ifndef ANDROID_RS_SERIALIZE #include "rsMutex.h" #include "rsThreadIO.h" #include "rsMatrix4x4.h" @@ -42,8 +41,6 @@ #include "rsgApiStructs.h" #include "rsLocklessFifo.h" -#endif // ANDROID_RS_SERIALIZE - // --------------------------------------------------------------------------- namespace android { @@ -67,8 +64,6 @@ namespace renderscript { #define CHECK_OBJ_OR_NULL(o) #endif -#ifndef ANDROID_RS_SERIALIZE - class Context { public: struct Hal { @@ -79,6 +74,7 @@ public: Hal mHal; static Context * createContext(Device *, const RsSurfaceConfig *sc); + static Context * createContextLite(); ~Context(); static pthread_mutex_t gInitMutex; @@ -243,6 +239,7 @@ private: static void * helperThreadProc(void *); bool mHasSurface; + bool mIsContextLite; Vector<ObjectBase *> mNames; @@ -259,46 +256,6 @@ private: uint32_t mAverageFPS; }; -#else - -class Context { -public: - Context() { - mObjHead = NULL; - } - ~Context() { - ObjectBase::zeroAllUserRef(this); - } - - struct Hal { - void * drv; - - RsdHalFunctions funcs; - }; - Hal mHal; - - ElementState mStateElement; - TypeState mStateType; - - struct { - bool mLogTimes; - bool mLogScripts; - bool mLogObjects; - bool mLogShaders; - bool mLogShadersAttr; - bool mLogShadersUniforms; - bool mLogVisual; - } props; - - void setError(RsError e, const char *msg = NULL) { } - - mutable const ObjectBase * mObjHead; - -protected: - -}; -#endif //ANDROID_RS_SERIALIZE - } // renderscript } // android #endif diff --git a/libs/rs/rsFifoSocket.cpp b/libs/rs/rsFifoSocket.cpp index 848bba5..8b8008d 100644 --- a/libs/rs/rsFifoSocket.cpp +++ b/libs/rs/rsFifoSocket.cpp @@ -70,9 +70,9 @@ size_t FifoSocket::read(void *data, size_t bytes) { } void FifoSocket::readReturn(const void *data, size_t bytes) { - LOGE("readReturn %p %i", data, bytes); + LOGE("readReturn %p %Zu", data, bytes); size_t ret = ::send(sv[1], data, bytes, 0); - LOGE("readReturn %i", ret); + LOGE("readReturn %Zu", ret); rsAssert(ret == bytes); } diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp index b625504..ce674f4 100644 --- a/libs/rs/rsFont.cpp +++ b/libs/rs/rsFont.cpp @@ -21,9 +21,11 @@ #include "rsProgramFragment.h" #include <cutils/properties.h> +#ifndef ANDROID_RS_SERIALIZE #include <ft2build.h> #include FT_FREETYPE_H #include FT_BITMAP_H +#endif //ANDROID_RS_SERIALIZE using namespace android; using namespace android::renderscript; @@ -35,6 +37,7 @@ Font::Font(Context *rsc) : ObjectBase(rsc), mCachedGlyphs(NULL) { } bool Font::init(const char *name, float fontSize, uint32_t dpi, const void *data, uint32_t dataLen) { +#ifndef ANDROID_RS_SERIALIZE if (mInitialized) { LOGE("Reinitialization of fonts not supported"); return false; @@ -65,6 +68,7 @@ bool Font::init(const char *name, float fontSize, uint32_t dpi, const void *data mHasKerning = FT_HAS_KERNING(mFace); mInitialized = true; +#endif //ANDROID_RS_SERIALIZE return true; } @@ -230,6 +234,7 @@ Font::CachedGlyphInfo* Font::getCachedUTFChar(int32_t utfChar) { } void Font::updateGlyphCache(CachedGlyphInfo *glyph) { +#ifndef ANDROID_RS_SERIALIZE FT_Error error = FT_Load_Glyph( mFace, glyph->mGlyphIndex, FT_LOAD_RENDER ); if (error) { LOGE("Couldn't load glyph."); @@ -270,15 +275,16 @@ void Font::updateGlyphCache(CachedGlyphInfo *glyph) { glyph->mBitmapMinV = (float)startY / (float)cacheHeight; glyph->mBitmapMaxU = (float)endX / (float)cacheWidth; glyph->mBitmapMaxV = (float)endY / (float)cacheHeight; +#endif //ANDROID_RS_SERIALIZE } Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph) { CachedGlyphInfo *newGlyph = new CachedGlyphInfo(); mCachedGlyphs.add(glyph, newGlyph); - +#ifndef ANDROID_RS_SERIALIZE newGlyph->mGlyphIndex = FT_Get_Char_Index(mFace, glyph); newGlyph->mIsValid = false; - +#endif //ANDROID_RS_SERIALIZE updateGlyphCache(newGlyph); return newGlyph; @@ -309,9 +315,11 @@ Font * Font::create(Context *rsc, const char *name, float fontSize, uint32_t dpi } Font::~Font() { +#ifndef ANDROID_RS_SERIALIZE if (mFace) { FT_Done_Face(mFace); } +#endif for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) { CachedGlyphInfo *glyph = mCachedGlyphs.valueAt(i); @@ -324,7 +332,9 @@ FontState::FontState() { mMaxNumberOfQuads = 1024; mCurrentQuadIndex = 0; mRSC = NULL; +#ifndef ANDROID_RS_SERIALIZE mLibrary = NULL; +#endif //ANDROID_RS_SERIALIZE // Get the renderer properties char property[PROPERTY_VALUE_MAX]; @@ -363,7 +373,7 @@ FontState::~FontState() { rsAssert(!mActiveFonts.size()); } - +#ifndef ANDROID_RS_SERIALIZE FT_Library FontState::getLib() { if (!mLibrary) { FT_Error error = FT_Init_FreeType(&mLibrary); @@ -375,6 +385,8 @@ FT_Library FontState::getLib() { return mLibrary; } +#endif //ANDROID_RS_SERIALIZE + void FontState::init(Context *rsc) { mRSC = rsc; @@ -393,6 +405,7 @@ void FontState::flushAllAndInvalidate() { } } +#ifndef ANDROID_RS_SERIALIZE bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *retOriginY) { // If the glyph is too tall, don't cache it if ((uint32_t)bitmap->rows > mCacheLines[mCacheLines.size()-1]->mMaxHeight) { @@ -466,6 +479,7 @@ bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *r return true; } +#endif //ANDROID_RS_SERIALIZE void FontState::initRenderState() { String8 shaderString("varying vec2 varTex0;\n"); @@ -791,13 +805,15 @@ void FontState::deinit(Context *rsc) { mCacheLines.clear(); mDefault.clear(); - +#ifndef ANDROID_RS_SERIALIZE if (mLibrary) { FT_Done_FreeType( mLibrary ); mLibrary = NULL; } +#endif //ANDROID_RS_SERIALIZE } +#ifndef ANDROID_RS_SERIALIZE bool FontState::CacheTextureLine::fitBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY) { if ((uint32_t)bitmap->rows > mMaxHeight) { return false; @@ -813,6 +829,7 @@ bool FontState::CacheTextureLine::fitBitmap(FT_Bitmap_ *bitmap, uint32_t *retOri return false; } +#endif //ANDROID_RS_SERIALIZE namespace android { namespace renderscript { diff --git a/libs/rs/rsFont.h b/libs/rs/rsFont.h index d18c0d9..b0e1430 100644 --- a/libs/rs/rsFont.h +++ b/libs/rs/rsFont.h @@ -199,8 +199,10 @@ protected: float mWhiteThreshold; // Free type library, we only need one copy +#ifndef ANDROID_RS_SERIALIZE FT_LibraryRec_ *mLibrary; FT_LibraryRec_ *getLib(); +#endif //ANDROID_RS_SERIALIZE Vector<Font*> mActiveFonts; // Render state for the font @@ -217,7 +219,9 @@ protected: return (uint8_t*)mTextTexture->getPtr(); } +#ifndef ANDROID_RS_SERIALIZE bool cacheBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY); +#endif //ANDROID_RS_SERIALIZE const Type* getCacheTextureType() { return mTextTexture->getType(); } diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp index 62e388c..359d09f 100644 --- a/libs/rs/rsMesh.cpp +++ b/libs/rs/rsMesh.cpp @@ -161,8 +161,6 @@ Mesh *Mesh::createFromStream(Context *rsc, IStream *stream) { return mesh; } -#ifndef ANDROID_RS_SERIALIZE - void Mesh::render(Context *rsc) const { for (uint32_t ct = 0; ct < mHal.state.primitivesCount; ct ++) { renderPrimitive(rsc, ct); @@ -255,9 +253,9 @@ namespace android { namespace renderscript { RsMesh rsi_MeshCreate(Context *rsc, - RsAllocation *vtx, uint32_t vtxCount, - RsAllocation *idx, uint32_t idxCount, - uint32_t *primType, uint32_t primTypeCount) { + RsAllocation * vtx, size_t vtxCount, + RsAllocation * idx, size_t idxCount, + uint32_t * primType, size_t primTypeCount) { rsAssert(idxCount == primTypeCount); Mesh *sm = new Mesh(rsc, vtxCount, idxCount); sm->incUserRef(); @@ -309,5 +307,3 @@ void rsaMeshGetIndices(RsContext con, RsMesh mv, RsAllocation *va, uint32_t *pri } } } - -#endif diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp index 0823d82..356ff77 100644 --- a/libs/rs/rsProgramFragment.cpp +++ b/libs/rs/rsProgramFragment.cpp @@ -127,8 +127,8 @@ namespace android { namespace renderscript { RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc, const char * shaderText, - uint32_t shaderLength, const uint32_t * params, - uint32_t paramLength) { + size_t shaderLength, const uint32_t * params, + size_t paramLength) { ProgramFragment *pf = new ProgramFragment(rsc, shaderText, shaderLength, params, paramLength); pf->incUserRef(); //LOGE("rsi_ProgramFragmentCreate %p", pf); diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp index e6790cb..058a456 100644 --- a/libs/rs/rsProgramVertex.cpp +++ b/libs/rs/rsProgramVertex.cpp @@ -223,8 +223,8 @@ namespace android { namespace renderscript { RsProgramVertex rsi_ProgramVertexCreate(Context *rsc, const char * shaderText, - uint32_t shaderLength, const uint32_t * params, - uint32_t paramLength) { + size_t shaderLength, const uint32_t * params, + size_t paramLength) { ProgramVertex *pv = new ProgramVertex(rsc, shaderText, shaderLength, params, paramLength); pv->incUserRef(); return pv; diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp index 7641cab..f62c72e 100644 --- a/libs/rs/rsScript.cpp +++ b/libs/rs/rsScript.cpp @@ -53,7 +53,7 @@ void Script::setSlot(uint32_t slot, Allocation *a) { } } -void Script::setVar(uint32_t slot, const void *val, uint32_t len) { +void Script::setVar(uint32_t slot, const void *val, size_t len) { //LOGE("setVar %i %p %i", slot, val, len); if (slot >= mHal.info.exportedVariableCount) { LOGE("Script::setVar unable to set allocation, invalid slot index"); @@ -82,14 +82,14 @@ void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint3 //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr()); } -void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length) { +void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) { Script *s = static_cast<Script *>(vs); s->mEnviroment.mTimeZone = timeZone; } void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot, RsAllocation vain, RsAllocation vaout, - const void *params, uint32_t paramLen) { + const void *params, size_t paramLen) { Script *s = static_cast<Script *>(vs); s->runForEach(rsc, static_cast<const Allocation *>(vain), static_cast<Allocation *>(vaout), @@ -108,7 +108,7 @@ void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) s->Invoke(rsc, slot, NULL, 0); } -void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) { +void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) { Script *s = static_cast<Script *>(vs); s->Invoke(rsc, slot, data, len); } @@ -139,7 +139,7 @@ void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) { s->setVar(slot, &value, sizeof(value)); } -void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) { +void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) { Script *s = static_cast<Script *>(vs); s->setVar(slot, data, len); } diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h index 088c8d1..c0324dd 100644 --- a/libs/rs/rsScript.h +++ b/libs/rs/rsScript.h @@ -70,7 +70,7 @@ public: void initSlots(); void setSlot(uint32_t slot, Allocation *a); - void setVar(uint32_t slot, const void *val, uint32_t len); + void setVar(uint32_t slot, const void *val, size_t len); void setVarObj(uint32_t slot, ObjectBase *val); virtual void runForEach(Context *rsc, @@ -80,7 +80,7 @@ public: size_t usrBytes, const RsScriptCall *sc = NULL) = 0; - virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) = 0; + virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0; virtual void setupScript(Context *rsc) = 0; virtual uint32_t run(Context *) = 0; protected: diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index 6d0701d..b230bb5 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -19,11 +19,6 @@ #include "utils/Timers.h" #include "utils/StopWatch.h" -#include <GLES/gl.h> -#include <GLES/glext.h> - -#include <bcc/bcc.h> - using namespace android; using namespace android::renderscript; @@ -129,7 +124,7 @@ void ScriptC::runForEach(Context *rsc, rsc->mHal.funcs.script.invokeForEach(rsc, this, ain, aout, usr, usrBytes, sc); } -void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) { +void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) { if (slot >= mHal.info.exportedFunctionCount) { rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script"); return; @@ -269,7 +264,7 @@ namespace renderscript { RsScript rsi_ScriptCCreate(Context *rsc, const char *resName, size_t resName_length, const char *cacheDir, size_t cacheDir_length, - const char *text, uint32_t text_length) + const char *text, size_t text_length) { ScriptC *s = new ScriptC(rsc); diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h index 4c85745..5c191d9 100644 --- a/libs/rs/rsScriptC.h +++ b/libs/rs/rsScriptC.h @@ -39,7 +39,7 @@ public: const Allocation *ptrToAllocation(const void *) const; - virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len); + virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len); virtual uint32_t run(Context *); diff --git a/libs/rs/rsThreadIO.cpp b/libs/rs/rsThreadIO.cpp index 4429556..ab164c3 100644 --- a/libs/rs/rsThreadIO.cpp +++ b/libs/rs/rsThreadIO.cpp @@ -149,7 +149,7 @@ RsMessageToClientType ThreadIO::getClientHeader(size_t *receiveLen, uint32_t *us mToClientSocket.read(&mLastClientHeader, sizeof(mLastClientHeader)); } else { size_t bytesData = 0; - const uint32_t *d = (const uint32_t *)mToClient.get(&mLastClientHeader.cmdID, &bytesData); + const uint32_t *d = (const uint32_t *)mToClient.get(&mLastClientHeader.cmdID, (uint32_t*)&bytesData); if (bytesData >= sizeof(uint32_t)) { mLastClientHeader.userID = d[0]; mLastClientHeader.bytes = bytesData - sizeof(uint32_t); diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h index 44c7e71..7bb09bb 100644 --- a/libs/rs/rs_hal.h +++ b/libs/rs/rs_hal.h @@ -18,7 +18,6 @@ #define RS_HAL_H #include <RenderScriptDefines.h> -#include <ui/egl/android_natives.h> namespace android { namespace renderscript { diff --git a/libs/ui/Input.cpp b/libs/ui/Input.cpp index 1ba38a7..0af7f80 100644 --- a/libs/ui/Input.cpp +++ b/libs/ui/Input.cpp @@ -13,6 +13,10 @@ // Log debug messages about velocity tracking. #define DEBUG_VELOCITY 0 +// Log debug messages about acceleration. +#define DEBUG_ACCELERATION 0 + + #include <stdlib.h> #include <unistd.h> #include <ctype.h> @@ -20,6 +24,7 @@ #include <ui/Input.h> #include <math.h> +#include <limits.h> #ifdef HAVE_ANDROID_OS #include <binder/Parcel.h> @@ -693,6 +698,10 @@ bool MotionEvent::isTouchEvent(int32_t source, int32_t action) { // --- VelocityTracker --- +const uint32_t VelocityTracker::HISTORY_SIZE; +const nsecs_t VelocityTracker::MAX_AGE; +const nsecs_t VelocityTracker::MIN_DURATION; + VelocityTracker::VelocityTracker() { clear(); } @@ -881,14 +890,6 @@ bool VelocityTracker::getVelocity(uint32_t id, float* outVx, float* outVy) const // Make sure we used at least one sample. if (samplesUsed != 0) { - // Scale the velocity linearly if the window of samples is small. - nsecs_t totalDuration = newestMovement.eventTime - oldestMovement.eventTime; - if (totalDuration < MIN_WINDOW) { - float scale = float(totalDuration) / float(MIN_WINDOW); - accumVx *= scale; - accumVy *= scale; - } - *outVx = accumVx; *outVy = accumVy; return true; @@ -902,6 +903,85 @@ bool VelocityTracker::getVelocity(uint32_t id, float* outVx, float* outVy) const } +// --- VelocityControl --- + +const nsecs_t VelocityControl::STOP_TIME; + +VelocityControl::VelocityControl() { + reset(); +} + +void VelocityControl::setParameters(const VelocityControlParameters& parameters) { + mParameters = parameters; + reset(); +} + +void VelocityControl::reset() { + mLastMovementTime = LLONG_MIN; + mRawPosition.x = 0; + mRawPosition.y = 0; + mVelocityTracker.clear(); +} + +void VelocityControl::move(nsecs_t eventTime, float* deltaX, float* deltaY) { + if ((deltaX && *deltaX) || (deltaY && *deltaY)) { + if (eventTime >= mLastMovementTime + STOP_TIME) { +#if DEBUG_ACCELERATION + LOGD("VelocityControl: stopped, last movement was %0.3fms ago", + (eventTime - mLastMovementTime) * 0.000001f); +#endif + reset(); + } + + mLastMovementTime = eventTime; + if (deltaX) { + mRawPosition.x += *deltaX; + } + if (deltaY) { + mRawPosition.y += *deltaY; + } + mVelocityTracker.addMovement(eventTime, BitSet32(BitSet32::valueForBit(0)), &mRawPosition); + + float vx, vy; + float scale = mParameters.scale; + if (mVelocityTracker.getVelocity(0, &vx, &vy)) { + float speed = hypotf(vx, vy) * scale; + if (speed >= mParameters.highThreshold) { + // Apply full acceleration above the high speed threshold. + scale *= mParameters.acceleration; + } else if (speed > mParameters.lowThreshold) { + // Linearly interpolate the acceleration to apply between the low and high + // speed thresholds. + scale *= 1 + (speed - mParameters.lowThreshold) + / (mParameters.highThreshold - mParameters.lowThreshold) + * (mParameters.acceleration - 1); + } + +#if DEBUG_ACCELERATION + LOGD("VelocityControl(%0.3f, %0.3f, %0.3f, %0.3f): " + "vx=%0.3f, vy=%0.3f, speed=%0.3f, accel=%0.3f", + mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold, + mParameters.acceleration, + vx, vy, speed, scale / mParameters.scale); +#endif + } else { +#if DEBUG_ACCELERATION + LOGD("VelocityControl(%0.3f, %0.3f, %0.3f, %0.3f): unknown velocity", + mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold, + mParameters.acceleration); +#endif + } + + if (deltaX) { + *deltaX *= scale; + } + if (deltaY) { + *deltaY *= scale; + } + } +} + + // --- InputDeviceInfo --- InputDeviceInfo::InputDeviceInfo() { diff --git a/libs/utils/BackupHelpers.cpp b/libs/utils/BackupHelpers.cpp index e15875f..87549fe 100644 --- a/libs/utils/BackupHelpers.cpp +++ b/libs/utils/BackupHelpers.cpp @@ -503,6 +503,16 @@ int write_tarfile(const String8& packageName, const String8& domain, needExtended = true; } + // Non-7bit-clean path also means needing pax extended format + if (!needExtended) { + for (size_t i = 0; i < filepath.length(); i++) { + if ((filepath[i] & 0x80) != 0) { + needExtended = true; + break; + } + } + } + int err = 0; struct stat64 s; if (lstat64(filepath.string(), &s) != 0) { @@ -515,6 +525,7 @@ int write_tarfile(const String8& packageName, const String8& domain, String8 prefix; const int isdir = S_ISDIR(s.st_mode); + if (isdir) s.st_size = 0; // directories get no actual data in the tar stream // !!! TODO: use mmap when possible to avoid churning the buffer cache // !!! TODO: this will break with symlinks; need to use readlink(2) diff --git a/libs/utils/RefBase.cpp b/libs/utils/RefBase.cpp index dd0052a..58e0811 100644 --- a/libs/utils/RefBase.cpp +++ b/libs/utils/RefBase.cpp @@ -418,18 +418,20 @@ void RefBase::weakref_type::decWeak(const void* id) if (c != 1) return; if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) { - if (impl->mStrong == INITIAL_STRONG_VALUE) - if (impl->mBase) + if (impl->mStrong == INITIAL_STRONG_VALUE) { + if (impl->mBase) { impl->mBase->destroy(); - else { + } + } else { // LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase); delete impl; } } else { impl->mBase->onLastWeakRef(id); if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) { - if (impl->mBase) + if (impl->mBase) { impl->mBase->destroy(); + } } } } @@ -551,8 +553,10 @@ RefBase::RefBase() RefBase::~RefBase() { - if (mRefs->mWeak == 0) { - delete mRefs; + if ((mRefs->mFlags & OBJECT_LIFETIME_WEAK) == OBJECT_LIFETIME_WEAK) { + if (mRefs->mWeak == 0) { + delete mRefs; + } } } diff --git a/libs/utils/StreamingZipInflater.cpp b/libs/utils/StreamingZipInflater.cpp index 5a162cc..00498bd 100644 --- a/libs/utils/StreamingZipInflater.cpp +++ b/libs/utils/StreamingZipInflater.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_NDEBUG 1 +//#define LOG_NDEBUG 0 #define LOG_TAG "szipinf" #include <utils/Log.h> @@ -77,7 +77,7 @@ StreamingZipInflater::~StreamingZipInflater() { } void StreamingZipInflater::initInflateState() { - LOGD("Initializing inflate state"); + LOGV("Initializing inflate state"); memset(&mInflateState, 0, sizeof(mInflateState)); mInflateState.zalloc = Z_NULL; @@ -152,13 +152,13 @@ ssize_t StreamingZipInflater::read(void* outBuf, size_t count) { mInflateState.avail_out = mOutBufSize; /* - LOGD("Inflating to outbuf: avail_in=%u avail_out=%u next_in=%p next_out=%p", + LOGV("Inflating to outbuf: avail_in=%u avail_out=%u next_in=%p next_out=%p", mInflateState.avail_in, mInflateState.avail_out, mInflateState.next_in, mInflateState.next_out); */ int result = Z_OK; if (mStreamNeedsInit) { - LOGD("Initializing zlib to inflate"); + LOGV("Initializing zlib to inflate"); result = inflateInit2(&mInflateState, -MAX_WBITS); mStreamNeedsInit = false; } @@ -192,7 +192,7 @@ int StreamingZipInflater::readNextChunk() { size_t toRead = min_of(mInBufSize, mInTotalSize - mInNextChunkOffset); if (toRead > 0) { ssize_t didRead = ::read(mFd, mInBuf, toRead); - //LOGD("Reading input chunk, size %08x didread %08x", toRead, didRead); + //LOGV("Reading input chunk, size %08x didread %08x", toRead, didRead); if (didRead < 0) { // TODO: error LOGE("Error reading asset data"); |