diff options
Diffstat (limited to 'libs')
42 files changed, 836 insertions, 374 deletions
diff --git a/libs/binder/CursorWindow.cpp b/libs/binder/CursorWindow.cpp index 1b85a71ca8ff..bf8d7a6f8f8e 100644 --- a/libs/binder/CursorWindow.cpp +++ b/libs/binder/CursorWindow.cpp @@ -40,11 +40,9 @@ CursorWindow::~CursorWindow() { ::close(mAshmemFd); } -status_t CursorWindow::create(const String8& name, size_t size, bool localOnly, - CursorWindow** outCursorWindow) { +status_t CursorWindow::create(const String8& name, size_t size, CursorWindow** outCursorWindow) { String8 ashmemName("CursorWindow: "); ashmemName.append(name); - ashmemName.append(localOnly ? " (local)" : " (remote)"); status_t result; int ashmemFd = ashmem_create_region(ashmemName.string(), size); diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index eb90147ac593..86bc62aa2806 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -79,7 +79,7 @@ public: } virtual void setTransactionState(const Vector<ComposerState>& state, - int orientation) + int orientation, uint32_t flags) { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -90,6 +90,7 @@ public: b->write(data); } data.writeInt32(orientation); + data.writeInt32(flags); remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply); } @@ -204,7 +205,8 @@ status_t BnSurfaceComposer::onTransact( state.add(s); } int orientation = data.readInt32(); - setTransactionState(state, orientation); + uint32_t flags = data.readInt32(); + setTransactionState(state, orientation, flags); } break; case BOOT_FINISHED: { CHECK_INTERFACE(ISurfaceComposer, data, reply); diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 5f3d608a5563..4ad6c22c0dae 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -92,11 +92,14 @@ class Composer : public Singleton<Composer> mutable Mutex mLock; SortedVector<ComposerState> mStates; int mOrientation; + uint32_t mForceSynchronous; Composer() : Singleton<Composer>(), - mOrientation(ISurfaceComposer::eOrientationUnchanged) { } + mOrientation(ISurfaceComposer::eOrientationUnchanged), + mForceSynchronous(0) + { } - void closeGlobalTransactionImpl(); + void closeGlobalTransactionImpl(bool synchronous); layer_state_t* getLayerStateLocked( const sp<SurfaceComposerClient>& client, SurfaceID id); @@ -123,8 +126,8 @@ public: uint32_t tint); status_t setOrientation(int orientation); - static void closeGlobalTransaction() { - Composer::getInstance().closeGlobalTransactionImpl(); + static void closeGlobalTransaction(bool synchronous) { + Composer::getInstance().closeGlobalTransactionImpl(synchronous); } }; @@ -132,11 +135,12 @@ ANDROID_SINGLETON_STATIC_INSTANCE(Composer); // --------------------------------------------------------------------------- -void Composer::closeGlobalTransactionImpl() { +void Composer::closeGlobalTransactionImpl(bool synchronous) { sp<ISurfaceComposer> sm(getComposerService()); Vector<ComposerState> transaction; int orientation; + uint32_t flags = 0; { // scope for the lock Mutex::Autolock _l(mLock); @@ -145,9 +149,14 @@ void Composer::closeGlobalTransactionImpl() { orientation = mOrientation; mOrientation = ISurfaceComposer::eOrientationUnchanged; + + if (synchronous || mForceSynchronous) { + flags |= ISurfaceComposer::eSynchronous; + } + mForceSynchronous = false; } - sm->setTransactionState(transaction, orientation); + sm->setTransactionState(transaction, orientation, flags); } layer_state_t* Composer::getLayerStateLocked( @@ -188,6 +197,10 @@ status_t Composer::setSize(const sp<SurfaceComposerClient>& client, s->what |= ISurfaceComposer::eSizeChanged; s->w = w; s->h = h; + + // Resizing a surface makes the transaction synchronous. + mForceSynchronous = true; + return NO_ERROR; } @@ -270,6 +283,10 @@ status_t Composer::setFreezeTint(const sp<SurfaceComposerClient>& client, status_t Composer::setOrientation(int orientation) { Mutex::Autolock _l(mLock); mOrientation = orientation; + + // Changing the orientation makes the transaction synchronous. + mForceSynchronous = true; + return NO_ERROR; } @@ -375,8 +392,8 @@ void SurfaceComposerClient::openGlobalTransaction() { // Currently a no-op } -void SurfaceComposerClient::closeGlobalTransaction() { - Composer::closeGlobalTransaction(); +void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) { + Composer::closeGlobalTransaction(synchronous); } // ---------------------------------------------------------------------------- diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp index b8bc454782e8..5daafd5581aa 100644 --- a/libs/gui/tests/SurfaceTexture_test.cpp +++ b/libs/gui/tests/SurfaceTexture_test.cpp @@ -334,7 +334,7 @@ protected: class SurfaceTextureGLTest : public GLTest { protected: - static const GLint TEX_ID = 123; + enum { TEX_ID = 123 }; virtual void SetUp() { GLTest::SetUp(); @@ -1438,4 +1438,86 @@ TEST_F(SurfaceTextureGLToGLTest, DISABLED_RepeatedSwapBuffersWhileDequeueStalled } } +TEST_F(SurfaceTextureGLTest, EglDestroySurfaceUnrefsBuffers) { + EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig, + mANW.get(), NULL); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + ASSERT_NE(EGL_NO_SURFACE, stcEglSurface); + + sp<GraphicBuffer> buffers[3]; + + for (int i = 0; i < 3; i++) { + // Produce a frame + EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface, + mEglContext)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + glClear(GL_COLOR_BUFFER_BIT); + eglSwapBuffers(mEglDisplay, stcEglSurface); + + // Consume a frame + EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, + mEglContext)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + mST->updateTexImage(); + buffers[i] = mST->getCurrentBuffer(); + } + + // Destroy the GL texture object to release its ref on buffers[2]. + GLuint texID = TEX_ID; + glDeleteTextures(1, &texID); + + // Destroy the EGLSurface + EXPECT_TRUE(eglDestroySurface(mEglDisplay, stcEglSurface)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + + // Release the ref that the SurfaceTexture has on buffers[2]. + mST->abandon(); + + EXPECT_EQ(1, buffers[0]->getStrongCount()); + EXPECT_EQ(1, buffers[1]->getStrongCount()); + EXPECT_EQ(1, buffers[2]->getStrongCount()); +} + +TEST_F(SurfaceTextureGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) { + EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig, + mANW.get(), NULL); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + ASSERT_NE(EGL_NO_SURFACE, stcEglSurface); + + sp<GraphicBuffer> buffers[3]; + + for (int i = 0; i < 3; i++) { + // Produce a frame + EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface, + mEglContext)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + glClear(GL_COLOR_BUFFER_BIT); + EXPECT_TRUE(eglSwapBuffers(mEglDisplay, stcEglSurface)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + + // Consume a frame + EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, + mEglContext)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + ASSERT_EQ(NO_ERROR, mST->updateTexImage()); + buffers[i] = mST->getCurrentBuffer(); + } + + // Abandon the SurfaceTexture, releasing the ref that the SurfaceTexture has + // on buffers[2]. + mST->abandon(); + + // Destroy the GL texture object to release its ref on buffers[2]. + GLuint texID = TEX_ID; + glDeleteTextures(1, &texID); + + // Destroy the EGLSurface. + EXPECT_TRUE(eglDestroySurface(mEglDisplay, stcEglSurface)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + + EXPECT_EQ(1, buffers[0]->getStrongCount()); + EXPECT_EQ(1, buffers[1]->getStrongCount()); + EXPECT_EQ(1, buffers[2]->getStrongCount()); +} + } // namespace android diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index a98e4cd30235..9bfc94cb11fd 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -39,6 +39,7 @@ ifeq ($(USE_OPENGL_RENDERER),true) external/skia/include/utils LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER + LOCAL_CFLAGS += -fvisibility=hidden LOCAL_MODULE_CLASS := SHARED_LIBRARIES LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia libui LOCAL_MODULE := libhwui diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h index cdcbf2188532..9b0d7c6e6009 100644 --- a/libs/hwui/Caches.h +++ b/libs/hwui/Caches.h @@ -23,6 +23,8 @@ #include <utils/Singleton.h> +#include <cutils/compiler.h> + #include "Extensions.h" #include "FontRenderer.h" #include "GammaFontRenderer.h" @@ -82,7 +84,7 @@ struct CacheLogger { // Caches /////////////////////////////////////////////////////////////////////////////// -class Caches: public Singleton<Caches> { +class ANDROID_API Caches: public Singleton<Caches> { Caches(); ~Caches(); diff --git a/libs/hwui/DisplayListLogBuffer.h b/libs/hwui/DisplayListLogBuffer.h index bf16f297fb9b..5d689bb82363 100644 --- a/libs/hwui/DisplayListLogBuffer.h +++ b/libs/hwui/DisplayListLogBuffer.h @@ -18,6 +18,7 @@ #define ANDROID_HWUI_DISPLAY_LIST_LOG_BUFFER_H #include <utils/Singleton.h> + #include <stdio.h> namespace android { diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp index cedf456e22c3..3372d1c249bf 100644 --- a/libs/hwui/DisplayListRenderer.cpp +++ b/libs/hwui/DisplayListRenderer.cpp @@ -382,12 +382,13 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { xDivs = getInts(xDivsCount); yDivs = getInts(yDivsCount); colors = getUInts(numColors); - DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); - getFloat(); - getFloat(); - getFloat(); - getFloat(); - getPaint(); + float left = getFloat(); + float top = getFloat(); + float right = getFloat(); + float bottom = getFloat(); + SkPaint* paint = getPaint(); + LOGD("%s%s %.2f, %.2f, %.2f, %.2f", (char*) indent, OP_NAMES[op], + left, top, right, bottom); } break; case DrawColor: { diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h index 8cd7fea07d01..ab475bf53beb 100644 --- a/libs/hwui/DisplayListRenderer.h +++ b/libs/hwui/DisplayListRenderer.h @@ -26,6 +26,8 @@ #include <SkTDArray.h> #include <SkTSearch.h> +#include <cutils/compiler.h> + #include "DisplayListLogBuffer.h" #include "OpenGLRenderer.h" #include "utils/Functor.h" @@ -58,7 +60,7 @@ class DisplayListRenderer; class DisplayList { public: DisplayList(const DisplayListRenderer& recorder); - ~DisplayList(); + ANDROID_API ~DisplayList(); // IMPORTANT: Update the intialization of OP_NAMES in the .cpp file // when modifying this file @@ -107,13 +109,13 @@ public: void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false); - size_t getSize(); + ANDROID_API size_t getSize(); bool replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level = 0); void output(OpenGLRenderer& renderer, uint32_t level = 0); - static void outputLogBuffer(int fd); + ANDROID_API static void outputLogBuffer(int fd); void setRenderable(bool renderable) { mIsRenderable = renderable; @@ -230,75 +232,76 @@ private: */ class DisplayListRenderer: public OpenGLRenderer { public: - DisplayListRenderer(); - ~DisplayListRenderer(); + ANDROID_API DisplayListRenderer(); + virtual ~DisplayListRenderer(); - DisplayList* getDisplayList(DisplayList* displayList); + ANDROID_API DisplayList* getDisplayList(DisplayList* displayList); - void setViewport(int width, int height); - void prepareDirty(float left, float top, float right, float bottom, bool opaque); - void finish(); + virtual void setViewport(int width, int height); + virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque); + virtual void finish(); - bool callDrawGLFunction(Functor *functor, Rect& dirty); + virtual bool callDrawGLFunction(Functor *functor, Rect& dirty); - void interrupt(); - void resume(); + virtual void interrupt(); + virtual void resume(); - int save(int flags); - void restore(); - void restoreToCount(int saveCount); + virtual int save(int flags); + virtual void restore(); + virtual void restoreToCount(int saveCount); - int saveLayer(float left, float top, float right, float bottom, + virtual int saveLayer(float left, float top, float right, float bottom, SkPaint* p, int flags); - int saveLayerAlpha(float left, float top, float right, float bottom, + virtual int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int flags); - void translate(float dx, float dy); - void rotate(float degrees); - void scale(float sx, float sy); - void skew(float sx, float sy); + virtual void translate(float dx, float dy); + virtual void rotate(float degrees); + virtual void scale(float sx, float sy); + virtual void skew(float sx, float sy); - void setMatrix(SkMatrix* matrix); - void concatMatrix(SkMatrix* matrix); + virtual void setMatrix(SkMatrix* matrix); + virtual void concatMatrix(SkMatrix* matrix); - bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); + virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); - bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height, + virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height, Rect& dirty, uint32_t level = 0); - void drawLayer(Layer* layer, float x, float y, SkPaint* paint); - void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint); - void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint); - void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, + virtual void drawLayer(Layer* layer, float x, float y, SkPaint* paint); + virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint); + virtual void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint); + virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, float dstLeft, float dstTop, float dstRight, float dstBottom, SkPaint* paint); - void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, + virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, float* vertices, int* colors, SkPaint* paint); - void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, + virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, float left, float top, float right, float bottom, SkPaint* paint); - void drawColor(int color, SkXfermode::Mode mode); - void drawRect(float left, float top, float right, float bottom, SkPaint* paint); - void drawRoundRect(float left, float top, float right, float bottom, + virtual void drawColor(int color, SkXfermode::Mode mode); + virtual void drawRect(float left, float top, float right, float bottom, SkPaint* paint); + virtual void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, SkPaint* paint); - void drawCircle(float x, float y, float radius, SkPaint* paint); - void drawOval(float left, float top, float right, float bottom, SkPaint* paint); - void drawArc(float left, float top, float right, float bottom, + virtual void drawCircle(float x, float y, float radius, SkPaint* paint); + virtual void drawOval(float left, float top, float right, float bottom, SkPaint* paint); + virtual void drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, bool useCenter, SkPaint* paint); - void drawPath(SkPath* path, SkPaint* paint); - void drawLines(float* points, int count, SkPaint* paint); - void drawPoints(float* points, int count, SkPaint* paint); - void drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint); + virtual void drawPath(SkPath* path, SkPaint* paint); + virtual void drawLines(float* points, int count, SkPaint* paint); + 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); - void resetShader(); - void setupShader(SkiaShader* shader); + virtual void resetShader(); + virtual void setupShader(SkiaShader* shader); - void resetColorFilter(); - void setupColorFilter(SkiaColorFilter* filter); + virtual void resetColorFilter(); + virtual void setupColorFilter(SkiaColorFilter* filter); - void resetShadow(); - void setupShadow(float radius, float dx, float dy, int color); + virtual void resetShadow(); + virtual void setupShadow(float radius, float dx, float dy, int color); - void reset(); + ANDROID_API void reset(); const SkWriter32& writeStream() const { return mWriter; diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp index 349b9e32268d..e38b4794bcae 100644 --- a/libs/hwui/LayerRenderer.cpp +++ b/libs/hwui/LayerRenderer.cpp @@ -31,6 +31,12 @@ namespace uirenderer { // Rendering /////////////////////////////////////////////////////////////////////////////// +LayerRenderer::LayerRenderer(Layer* layer): mLayer(layer) { +} + +LayerRenderer::~LayerRenderer() { +} + void LayerRenderer::prepareDirty(float left, float top, float right, float bottom, bool opaque) { LAYER_RENDERER_LOGD("Rendering into layer, fbo = %d", mLayer->getFbo()); @@ -210,7 +216,8 @@ Layer* LayerRenderer::createLayer(uint32_t width, uint32_t height, bool isOpaque layer->allocateTexture(GL_RGBA, GL_UNSIGNED_BYTE); if (glGetError() != GL_NO_ERROR) { - LOGD("Could not allocate texture"); + LOGD("Could not allocate texture for layer (fbo=%d %dx%d)", + fbo, width, height); glBindFramebuffer(GL_FRAMEBUFFER, previousFbo); Caches::getInstance().fboCache.put(fbo); @@ -264,7 +271,7 @@ Layer* LayerRenderer::createTextureLayer(bool isOpaque) { layer->setFbo(0); layer->setAlpha(255, SkXfermode::kSrcOver_Mode); layer->layer.set(0.0f, 0.0f, 0.0f, 0.0f); - layer->texCoords.set(0.0f, 1.0f, 0.0f, 1.0f); + layer->texCoords.set(0.0f, 1.0f, 1.0f, 0.0f); layer->region.clear(); layer->setRenderTarget(GL_NONE); // see ::updateTextureLayer() @@ -400,6 +407,18 @@ bool LayerRenderer::copyLayer(Layer* layer, SkBitmap* bitmap) { renderer.setViewport(bitmap->width(), bitmap->height()); renderer.OpenGLRenderer::prepareDirty(0.0f, 0.0f, bitmap->width(), bitmap->height(), !layer->isBlend()); + + glDisable(GL_SCISSOR_TEST); + renderer.translate(0.0f, bitmap->height()); + renderer.scale(1.0f, -1.0f); + + mat4 texTransform(layer->getTexTransform()); + + mat4 invert; + invert.translate(0.0f, 1.0f, 0.0f); + invert.scale(1.0f, -1.0f, 1.0f); + layer->getTexTransform().multiply(invert); + if ((error = glGetError()) != GL_NO_ERROR) goto error; { @@ -413,6 +432,7 @@ bool LayerRenderer::copyLayer(Layer* layer, SkBitmap* bitmap) { if ((error = glGetError()) != GL_NO_ERROR) goto error; } + layer->getTexTransform().load(texTransform); status = true; } diff --git a/libs/hwui/LayerRenderer.h b/libs/hwui/LayerRenderer.h index 224657397dd1..61043015f768 100644 --- a/libs/hwui/LayerRenderer.h +++ b/libs/hwui/LayerRenderer.h @@ -17,6 +17,8 @@ #ifndef ANDROID_HWUI_LAYER_RENDERER_H #define ANDROID_HWUI_LAYER_RENDERER_H +#include <cutils/compiler.h> + #include "OpenGLRenderer.h" #include "Layer.h" @@ -42,27 +44,24 @@ namespace uirenderer { class LayerRenderer: public OpenGLRenderer { public: - LayerRenderer(Layer* layer): mLayer(layer) { - } - - ~LayerRenderer() { - } + ANDROID_API LayerRenderer(Layer* layer); + virtual ~LayerRenderer(); - void prepareDirty(float left, float top, float right, float bottom, bool opaque); - void finish(); + virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque); + virtual void finish(); - bool hasLayer(); - Region* getRegion(); - GLint getTargetFbo(); + virtual bool hasLayer(); + virtual Region* getRegion(); + virtual GLint getTargetFbo(); - static Layer* createTextureLayer(bool isOpaque); - static Layer* createLayer(uint32_t width, uint32_t height, bool isOpaque = false); - static bool resizeLayer(Layer* layer, uint32_t width, uint32_t height); - static void updateTextureLayer(Layer* layer, uint32_t width, uint32_t height, + ANDROID_API static Layer* createTextureLayer(bool isOpaque); + ANDROID_API static Layer* createLayer(uint32_t width, uint32_t height, bool isOpaque = false); + ANDROID_API static bool resizeLayer(Layer* layer, uint32_t width, uint32_t height); + ANDROID_API static void updateTextureLayer(Layer* layer, uint32_t width, uint32_t height, bool isOpaque, GLenum renderTarget, float* transform); - static void destroyLayer(Layer* layer); - static void destroyLayerDeferred(Layer* layer); - static bool copyLayer(Layer* layer, SkBitmap* bitmap); + ANDROID_API static void destroyLayer(Layer* layer); + ANDROID_API static void destroyLayerDeferred(Layer* layer); + ANDROID_API static bool copyLayer(Layer* layer, SkBitmap* bitmap); private: void generateMesh(); diff --git a/libs/hwui/Matrix.h b/libs/hwui/Matrix.h index 56fd37de813b..22220a93c0ad 100644 --- a/libs/hwui/Matrix.h +++ b/libs/hwui/Matrix.h @@ -19,6 +19,8 @@ #include <SkMatrix.h> +#include <cutils/compiler.h> + #include "Rect.h" namespace android { @@ -28,7 +30,7 @@ namespace uirenderer { // Classes /////////////////////////////////////////////////////////////////////////////// -class Matrix4 { +class ANDROID_API Matrix4 { public: float data[16]; diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index 14b22b39cfdb..2fc88e1d9674 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -31,6 +31,8 @@ #include <utils/RefBase.h> #include <utils/Vector.h> +#include <cutils/compiler.h> + #include "Debug.h" #include "Extensions.h" #include "Matrix.h" @@ -57,12 +59,12 @@ class DisplayList; */ class OpenGLRenderer { public: - OpenGLRenderer(); + ANDROID_API OpenGLRenderer(); virtual ~OpenGLRenderer(); virtual void setViewport(int width, int height); - void prepare(bool opaque); + ANDROID_API void prepare(bool opaque); virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque); virtual void finish(); @@ -72,7 +74,7 @@ public: virtual bool callDrawGLFunction(Functor *functor, Rect& dirty); - int getSaveCount() const; + ANDROID_API int getSaveCount() const; virtual int save(int flags); virtual void restore(); virtual void restoreToCount(int saveCount); @@ -87,12 +89,12 @@ public: virtual void scale(float sx, float sy); virtual void skew(float sx, float sy); - void getMatrix(SkMatrix* matrix); + ANDROID_API void getMatrix(SkMatrix* matrix); virtual void setMatrix(SkMatrix* matrix); virtual void concatMatrix(SkMatrix* matrix); - const Rect& getClipBounds(); - bool quickReject(float left, float top, float right, float bottom); + ANDROID_API const Rect& getClipBounds(); + ANDROID_API bool quickReject(float left, float top, float right, float bottom); virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height, diff --git a/libs/hwui/Patch.cpp b/libs/hwui/Patch.cpp index f7dacaea1c3f..47a2c99dd60a 100644 --- a/libs/hwui/Patch.cpp +++ b/libs/hwui/Patch.cpp @@ -157,14 +157,17 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight, for (uint32_t i = 0; i < mYCount; i++) { float stepY = mYDivs[i]; + const float segment = stepY - previousStepY; if (i & 1) { - const float segment = stepY - previousStepY; y2 = y1 + floorf(segment * stretchY + 0.5f); } else { - y2 = y1 + stepY - previousStepY; + y2 = y1 + segment; } - float v2 = fmax(0.0f, stepY - 0.5f) / bitmapHeight; + + float vOffset = y1 == y2 ? 0.0f : 0.5 - (0.5 * segment / (y2 - y1)); + float v2 = fmax(0.0f, stepY - vOffset) / bitmapHeight; + v1 += vOffset / bitmapHeight; if (stepY > 0.0f) { #if DEBUG_EXPLODE_PATCHES @@ -179,7 +182,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight, } y1 = y2; - v1 = (stepY + 0.5f) / bitmapHeight; + v1 = stepY / bitmapHeight; previousStepY = stepY; } @@ -190,8 +193,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight, y1 += mYCount * EXPLODE_GAP; y2 += mYCount * EXPLODE_GAP; #endif - generateRow(vertex, y1, y2, v1, 1.0f, stretchX, right - left, - bitmapWidth, quadCount); + generateRow(vertex, y1, y2, v1, 1.0f, stretchX, right - left, bitmapWidth, quadCount); } if (verticesCount > 0) { @@ -220,14 +222,17 @@ void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, fl // Generate the row quad by quad for (uint32_t i = 0; i < mXCount; i++) { float stepX = mXDivs[i]; + const float segment = stepX - previousStepX; if (i & 1) { - const float segment = stepX - previousStepX; x2 = x1 + floorf(segment * stretchX + 0.5f); } else { - x2 = x1 + stepX - previousStepX; + x2 = x1 + segment; } - float u2 = fmax(0.0f, stepX - 0.5f) / bitmapWidth; + + float uOffset = x1 == x2 ? 0.0f : 0.5 - (0.5 * segment / (x2 - x1)); + float u2 = fmax(0.0f, stepX - uOffset) / bitmapWidth; + u1 += uOffset / bitmapWidth; if (stepX > 0.0f) { #if DEBUG_EXPLODE_PATCHES @@ -241,7 +246,7 @@ void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, fl } x1 = x2; - u1 = (stepX + 0.5f) / bitmapWidth; + u1 = stepX / bitmapWidth; previousStepX = stepX; } @@ -265,8 +270,8 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f if ((mColorKey >> oldQuadCount) & 0x1) { #if DEBUG_PATCHES_EMPTY_VERTICES PATCH_LOGD(" quad %d (empty)", oldQuadCount); - PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.2f, %.2f", x1, y1, u1, v1); - PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.2f, %.2f", x2, y2, u2, v2); + PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1); + PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.4f, %.4f", x2, y2, u2, v2); #endif return; } @@ -294,8 +299,8 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f #if DEBUG_PATCHES_VERTICES PATCH_LOGD(" quad %d", oldQuadCount); - PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.2f, %.2f", x1, y1, u1, v1); - PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.2f, %.2f", x2, y2, u2, v2); + PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1); + PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.4f, %.4f", x2, y2, u2, v2); #endif } diff --git a/libs/hwui/ResourceCache.h b/libs/hwui/ResourceCache.h index 2a38910951c4..8cf466baa4e8 100644 --- a/libs/hwui/ResourceCache.h +++ b/libs/hwui/ResourceCache.h @@ -17,6 +17,8 @@ #ifndef ANDROID_HWUI_RESOURCE_CACHE_H #define ANDROID_HWUI_RESOURCE_CACHE_H +#include <cutils/compiler.h> + #include <SkBitmap.h> #include <SkiaColorFilter.h> #include <SkiaShader.h> @@ -49,7 +51,7 @@ public: ResourceType resourceType; }; -class ResourceCache { +class ANDROID_API ResourceCache { KeyedVector<void *, ResourceReference *>* mCache; public: ResourceCache(); diff --git a/libs/hwui/SkiaColorFilter.h b/libs/hwui/SkiaColorFilter.h index 1bf475c2268e..2feb834e540c 100644 --- a/libs/hwui/SkiaColorFilter.h +++ b/libs/hwui/SkiaColorFilter.h @@ -20,6 +20,8 @@ #include <GLES2/gl2.h> #include <SkColorFilter.h> +#include <cutils/compiler.h> + #include "ProgramCache.h" #include "Extensions.h" @@ -45,7 +47,7 @@ struct SkiaColorFilter { kBlend, }; - SkiaColorFilter(SkColorFilter *skFilter, Type type, bool blend); + ANDROID_API SkiaColorFilter(SkColorFilter *skFilter, Type type, bool blend); virtual ~SkiaColorFilter(); virtual void describe(ProgramDescription& description, const Extensions& extensions) = 0; @@ -79,7 +81,7 @@ private: * A color filter that multiplies the source color with a matrix and adds a vector. */ struct SkiaColorMatrixFilter: public SkiaColorFilter { - SkiaColorMatrixFilter(SkColorFilter *skFilter, float* matrix, float* vector); + ANDROID_API SkiaColorMatrixFilter(SkColorFilter *skFilter, float* matrix, float* vector); ~SkiaColorMatrixFilter(); void describe(ProgramDescription& description, const Extensions& extensions); @@ -95,7 +97,7 @@ private: * another fixed value. Ignores the alpha channel of both arguments. */ struct SkiaLightingFilter: public SkiaColorFilter { - SkiaLightingFilter(SkColorFilter *skFilter, int multiply, int add); + ANDROID_API SkiaLightingFilter(SkColorFilter *skFilter, int multiply, int add); void describe(ProgramDescription& description, const Extensions& extensions); void setupProgram(Program* program); @@ -110,7 +112,7 @@ private: * and PorterDuff blending mode. */ struct SkiaBlendFilter: public SkiaColorFilter { - SkiaBlendFilter(SkColorFilter *skFilter, int color, SkXfermode::Mode mode); + ANDROID_API SkiaBlendFilter(SkColorFilter *skFilter, int color, SkXfermode::Mode mode); void describe(ProgramDescription& description, const Extensions& extensions); void setupProgram(Program* program); diff --git a/libs/hwui/SkiaShader.h b/libs/hwui/SkiaShader.h index 89dd131f8ab2..2de9a93bd136 100644 --- a/libs/hwui/SkiaShader.h +++ b/libs/hwui/SkiaShader.h @@ -22,6 +22,8 @@ #include <GLES2/gl2.h> +#include <cutils/compiler.h> + #include "Extensions.h" #include "ProgramCache.h" #include "TextureCache.h" @@ -52,8 +54,8 @@ struct SkiaShader { kCompose }; - SkiaShader(Type type, SkShader* key, SkShader::TileMode tileX, SkShader::TileMode tileY, - SkMatrix* matrix, bool blend); + ANDROID_API SkiaShader(Type type, SkShader* key, SkShader::TileMode tileX, + SkShader::TileMode tileY, SkMatrix* matrix, bool blend); virtual ~SkiaShader(); virtual SkiaShader* copy() = 0; @@ -139,7 +141,7 @@ private: * A shader that draws a bitmap. */ struct SkiaBitmapShader: public SkiaShader { - SkiaBitmapShader(SkBitmap* bitmap, SkShader* key, SkShader::TileMode tileX, + ANDROID_API SkiaBitmapShader(SkBitmap* bitmap, SkShader* key, SkShader::TileMode tileX, SkShader::TileMode tileY, SkMatrix* matrix, bool blend); SkiaShader* copy(); @@ -169,8 +171,8 @@ private: * A shader that draws a linear gradient. */ struct SkiaLinearGradientShader: public SkiaShader { - SkiaLinearGradientShader(float* bounds, uint32_t* colors, float* positions, int count, - SkShader* key, SkShader::TileMode tileMode, SkMatrix* matrix, bool blend); + ANDROID_API SkiaLinearGradientShader(float* bounds, uint32_t* colors, float* positions, + int count, SkShader* key, SkShader::TileMode tileMode, SkMatrix* matrix, bool blend); ~SkiaLinearGradientShader(); SkiaShader* copy(); @@ -193,8 +195,8 @@ private: * A shader that draws a sweep gradient. */ struct SkiaSweepGradientShader: public SkiaShader { - SkiaSweepGradientShader(float x, float y, uint32_t* colors, float* positions, int count, - SkShader* key, SkMatrix* matrix, bool blend); + ANDROID_API SkiaSweepGradientShader(float x, float y, uint32_t* colors, float* positions, + int count, SkShader* key, SkMatrix* matrix, bool blend); ~SkiaSweepGradientShader(); SkiaShader* copy(); @@ -218,8 +220,9 @@ protected: * A shader that draws a circular gradient. */ struct SkiaCircularGradientShader: public SkiaSweepGradientShader { - SkiaCircularGradientShader(float x, float y, float radius, uint32_t* colors, float* positions, - int count, SkShader* key,SkShader::TileMode tileMode, SkMatrix* matrix, bool blend); + ANDROID_API SkiaCircularGradientShader(float x, float y, float radius, uint32_t* colors, + float* positions, int count, SkShader* key,SkShader::TileMode tileMode, + SkMatrix* matrix, bool blend); SkiaShader* copy(); void describe(ProgramDescription& description, const Extensions& extensions); @@ -233,7 +236,8 @@ private: * A shader that draws two shaders, composited with an xfermode. */ struct SkiaComposeShader: public SkiaShader { - SkiaComposeShader(SkiaShader* first, SkiaShader* second, SkXfermode::Mode mode, SkShader* key); + ANDROID_API SkiaComposeShader(SkiaShader* first, SkiaShader* second, SkXfermode::Mode mode, + SkShader* key); ~SkiaComposeShader(); SkiaShader* copy(); diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h index 3ba012353ca7..6d5426882bda 100644 --- a/libs/rs/RenderScript.h +++ b/libs/rs/RenderScript.h @@ -34,26 +34,30 @@ RsFile rsaFileA3DCreateFromMemory(RsContext, const void *data, uint32_t len); RsFile rsaFileA3DCreateFromAsset(RsContext, void *asset); RsFile rsaFileA3DCreateFromFile(RsContext, const char *path); void rsaFileA3DGetNumIndexEntries(RsContext, int32_t *numEntries, RsFile); -void rsaFileA3DGetIndexEntries(RsContext, RsFileIndexEntry *fileEntries,uint32_t numEntries, RsFile); +void rsaFileA3DGetIndexEntries(RsContext, RsFileIndexEntry *fileEntries, + uint32_t numEntries, RsFile); void rsaGetName(RsContext, void * obj, const char **name); // Mesh update functions void rsaMeshGetVertexBufferCount(RsContext, RsMesh, int32_t *vtxCount); void rsaMeshGetIndexCount(RsContext, RsMesh, int32_t *idxCount); void rsaMeshGetVertices(RsContext, RsMesh, RsAllocation *vtxData, uint32_t vtxDataCount); -void rsaMeshGetIndices(RsContext, RsMesh, RsAllocation *va, uint32_t *primType, uint32_t idxDataCount); +void rsaMeshGetIndices(RsContext, RsMesh, RsAllocation *va, + uint32_t *primType, uint32_t idxDataCount); // Allocation update const void* rsaAllocationGetType(RsContext con, RsAllocation va); // Type update void rsaTypeGetNativeData(RsContext, RsType, uint32_t *typeData, uint32_t typeDataSize); // Element update void rsaElementGetNativeData(RsContext, RsElement, uint32_t *elemData, uint32_t elemDataSize); -void rsaElementGetSubElements(RsContext, RsElement, uint32_t *ids, const char **names, uint32_t dataSize); +void rsaElementGetSubElements(RsContext, RsElement, uint32_t *ids, const char **names, + uint32_t *arraySizes, uint32_t dataSize); RsDevice rsDeviceCreate(); void rsDeviceDestroy(RsDevice dev); void rsDeviceSetConfig(RsDevice dev, RsDeviceParam p, int32_t value); RsContext rsContextCreate(RsDevice dev, uint32_t version, uint32_t sdkVersion); -RsContext rsContextCreateGL(RsDevice dev, uint32_t version, uint32_t sdkVersion, RsSurfaceConfig sc, uint32_t dpi); +RsContext rsContextCreateGL(RsDevice dev, uint32_t version, uint32_t sdkVersion, + RsSurfaceConfig sc, uint32_t dpi); #include "rsgApiFuncDecl.h" diff --git a/libs/rs/driver/rsdBcc.cpp b/libs/rs/driver/rsdBcc.cpp index 5fd5c35168c7..4ecf8e84a4df 100644 --- a/libs/rs/driver/rsdBcc.cpp +++ b/libs/rs/driver/rsdBcc.cpp @@ -226,6 +226,7 @@ static void wc_xy(void *usr, uint32_t idx) { RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv; uint32_t sig = mtls->sig; + outer_foreach_t fn = dc->mForEachLaunch[sig]; while (1) { uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize; @@ -239,16 +240,10 @@ static void wc_xy(void *usr, uint32_t idx) { //LOGE("usr ptr in %p, out %p", mtls->ptrIn, mtls->ptrOut); for (p.y = yStart; p.y < yEnd; p.y++) { uint32_t offset = mtls->dimX * p.y; - uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * offset); - const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * offset); - - for (p.x = mtls->xStart; p.x < mtls->xEnd; p.x++) { - p.in = xPtrIn; - p.out = xPtrOut; - dc->mForEachLaunch[sig](&mtls->script->mHal.info.root, &p); - xPtrIn += mtls->eStrideIn; - xPtrOut += mtls->eStrideOut; - } + p.out = mtls->ptrOut + (mtls->eStrideOut * offset); + p.in = mtls->ptrIn + (mtls->eStrideIn * offset); + fn(&mtls->script->mHal.info.root, &p, mtls->xStart, mtls->xEnd, + mtls->eStrideIn, mtls->eStrideOut); } } } @@ -262,6 +257,7 @@ static void wc_x(void *usr, uint32_t idx) { RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv; uint32_t sig = mtls->sig; + outer_foreach_t fn = dc->mForEachLaunch[sig]; while (1) { uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); uint32_t xStart = mtls->xStart + slice * mtls->mSliceSize; @@ -271,17 +267,12 @@ static void wc_x(void *usr, uint32_t idx) { return; } - //LOGE("usr idx %i, x %i,%i y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd); + //LOGE("usr slice %i idx %i, x %i,%i", slice, idx, xStart, xEnd); //LOGE("usr ptr in %p, out %p", mtls->ptrIn, mtls->ptrOut); - uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * xStart); - const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * xStart); - for (p.x = xStart; p.x < xEnd; p.x++) { - p.in = xPtrIn; - p.out = xPtrOut; - dc->mForEachLaunch[sig](&mtls->script->mHal.info.root, &p); - xPtrIn += mtls->eStrideIn; - xPtrOut += mtls->eStrideOut; - } + + p.out = mtls->ptrOut + (mtls->eStrideOut * xStart); + p.in = mtls->ptrIn + (mtls->eStrideIn * xStart); + fn(&mtls->script->mHal.info.root, &p, xStart, xEnd, mtls->eStrideIn, mtls->eStrideOut); } } @@ -392,22 +383,17 @@ void rsdScriptInvokeForEach(const Context *rsc, uint32_t sig = mtls.sig; //LOGE("launch 3"); + outer_foreach_t fn = dc->mForEachLaunch[sig]; for (p.ar[0] = mtls.arrayStart; p.ar[0] < mtls.arrayEnd; p.ar[0]++) { for (p.z = mtls.zStart; p.z < mtls.zEnd; p.z++) { for (p.y = mtls.yStart; p.y < mtls.yEnd; p.y++) { uint32_t offset = mtls.dimX * mtls.dimY * mtls.dimZ * p.ar[0] + mtls.dimX * mtls.dimY * p.z + mtls.dimX * p.y; - uint8_t *xPtrOut = mtls.ptrOut + (mtls.eStrideOut * offset); - const uint8_t *xPtrIn = mtls.ptrIn + (mtls.eStrideIn * offset); - - for (p.x = mtls.xStart; p.x < mtls.xEnd; p.x++) { - p.in = xPtrIn; - p.out = xPtrOut; - dc->mForEachLaunch[sig](&s->mHal.info.root, &p); - xPtrIn += mtls.eStrideIn; - xPtrOut += mtls.eStrideOut; - } + p.out = mtls.ptrOut + (mtls.eStrideOut * offset); + p.in = mtls.ptrIn + (mtls.eStrideIn * offset); + fn(&mtls.script->mHal.info.root, &p, mtls.xStart, mtls.xEnd, + mtls.eStrideIn, mtls.eStrideOut); } } } diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index f8107d9ff633..247f4dc163af 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -292,75 +292,136 @@ void Shutdown(Context *rsc) { } static void rsdForEach17(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(const void *, uint32_t); (*(fe*)vRoot)(p->in, p->y); } static void rsdForEach18(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(void *, uint32_t); (*(fe*)vRoot)(p->out, p->y); } static void rsdForEach19(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(const void *, void *, uint32_t); (*(fe*)vRoot)(p->in, p->out, p->y); } static void rsdForEach21(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(const void *, const void *, uint32_t); (*(fe*)vRoot)(p->in, p->usr, p->y); } static void rsdForEach22(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(void *, const void *, uint32_t); (*(fe*)vRoot)(p->out, p->usr, p->y); } static void rsdForEach23(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(const void *, void *, const void *, uint32_t); (*(fe*)vRoot)(p->in, p->out, p->usr, p->y); } static void rsdForEach25(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(const void *, uint32_t, uint32_t); - (*(fe*)vRoot)(p->in, p->x, p->y); + const uint8_t *pin = (const uint8_t *)p->in; + uint32_t y = p->y; + for (uint32_t x = x1; x < x2; x++) { + (*(fe*)vRoot)(pin, x, y); + pin += instep; + } } static void rsdForEach26(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(void *, uint32_t, uint32_t); - (*(fe*)vRoot)(p->out, p->x, p->y); + uint8_t *pout = (uint8_t *)p->out; + uint32_t y = p->y; + for (uint32_t x = x1; x < x2; x++) { + (*(fe*)vRoot)(pout, x, y); + pout += outstep; + } } static void rsdForEach27(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(const void *, void *, uint32_t, uint32_t); - (*(fe*)vRoot)(p->in, p->out, p->x, p->y); + uint8_t *pout = (uint8_t *)p->out; + const uint8_t *pin = (const uint8_t *)p->in; + uint32_t y = p->y; + for (uint32_t x = x1; x < x2; x++) { + (*(fe*)vRoot)(pin, pout, x, y); + pin += instep; + pout += outstep; + } } static void rsdForEach29(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(const void *, const void *, uint32_t, uint32_t); - (*(fe*)vRoot)(p->in, p->usr, p->x, p->y); + const uint8_t *pin = (const uint8_t *)p->in; + const void *usr = p->usr; + const uint32_t y = p->y; + for (uint32_t x = x1; x < x2; x++) { + (*(fe*)vRoot)(pin, usr, x, y); + pin += instep; + } } static void rsdForEach30(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(void *, const void *, uint32_t, uint32_t); - (*(fe*)vRoot)(p->out, p->usr, p->x, p->y); + uint8_t *pout = (uint8_t *)p->out; + const void *usr = p->usr; + const uint32_t y = p->y; + for (uint32_t x = x1; x < x2; x++) { + (*(fe*)vRoot)(pout, usr, x, y); + pout += outstep; + } } static void rsdForEach31(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + const android::renderscript::RsForEachStubParamStruct *p, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep) { typedef void (*fe)(const void *, void *, const void *, uint32_t, uint32_t); - (*(fe*)vRoot)(p->in, p->out, p->usr, p->x, p->y); + uint8_t *pout = (uint8_t *)p->out; + const uint8_t *pin = (const uint8_t *)p->in; + const void *usr = p->usr; + const uint32_t y = p->y; + for (uint32_t x = x1; x < x2; x++) { + (*(fe*)vRoot)(pin, pout, usr, x, y); + pin += instep; + pout += outstep; + } } diff --git a/libs/rs/driver/rsdCore.h b/libs/rs/driver/rsdCore.h index 159b72af96c8..ce86d118a8cd 100644 --- a/libs/rs/driver/rsdCore.h +++ b/libs/rs/driver/rsdCore.h @@ -28,7 +28,9 @@ typedef void (* InvokeFunc_t)(void); typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); typedef void (*outer_foreach_t)(const void *, - const android::renderscript::RsForEachStubParamStruct *); + const android::renderscript::RsForEachStubParamStruct *, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep); typedef struct RsdSymbolTableRec { const char * mName; diff --git a/libs/rs/driver/rsdFrameBuffer.cpp b/libs/rs/driver/rsdFrameBuffer.cpp index 8c1b12d7cada..bb07d296c5ee 100644 --- a/libs/rs/driver/rsdFrameBuffer.cpp +++ b/libs/rs/driver/rsdFrameBuffer.cpp @@ -33,11 +33,11 @@ void setDepthAttachment(const Context *rsc, const FBOCache *fb) { RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv; DrvAllocation *depth = NULL; - if (fb->mHal.state.depthTarget.get() != NULL) { + if (fb->mHal.state.depthTarget != NULL) { depth = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv; if (depth->uploadDeferred) { - rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget.get(), + rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget, RS_ALLOCATION_USAGE_SCRIPT); } } @@ -49,11 +49,11 @@ void setColorAttachment(const Context *rsc, const FBOCache *fb) { // Now attach color targets for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) { DrvAllocation *color = NULL; - if (fb->mHal.state.colorTargets[i].get() != NULL) { + if (fb->mHal.state.colorTargets[i] != NULL) { color = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv; if (color->uploadDeferred) { - rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i].get(), + rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i], RS_ALLOCATION_USAGE_SCRIPT); } } @@ -79,10 +79,10 @@ void rsdFrameBufferSetActive(const Context *rsc, const FBOCache *fb) { setColorAttachment(rsc, fb); RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv; - if (fb->mHal.state.colorTargets[0].get()) { + if (fb->mHal.state.colorTargets[0]) { fbo->setDimensions(fb->mHal.state.colorTargets[0]->getType()->getDimX(), fb->mHal.state.colorTargets[0]->getType()->getDimY()); - } else if (fb->mHal.state.depthTarget.get()) { + } else if (fb->mHal.state.depthTarget) { fbo->setDimensions(fb->mHal.state.depthTarget->getType()->getDimX(), fb->mHal.state.depthTarget->getType()->getDimY()); } diff --git a/libs/rs/driver/rsdMeshObj.cpp b/libs/rs/driver/rsdMeshObj.cpp index 019167bd0b2d..24a718331776 100644 --- a/libs/rs/driver/rsdMeshObj.cpp +++ b/libs/rs/driver/rsdMeshObj.cpp @@ -138,7 +138,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, } for (uint32_t ct=0; ct < mRSMesh->mHal.state.vertexBuffersCount; ct++) { - const Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[ct].get(); + const Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[ct]; DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; if (drv->uploadDeferred) { rsdAllocationSyncAll(rsc, alloc, RS_ALLOCATION_USAGE_SCRIPT); @@ -148,7 +148,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, // update attributes with either buffer information or data ptr based on their current state for (uint32_t ct=0; ct < mAttribCount; ct++) { uint32_t allocIndex = mAttribAllocationIndex[ct]; - Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[allocIndex].get(); + Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[allocIndex]; DrvAllocation *drvAlloc = (DrvAllocation *)alloc->mHal.drv; if (drvAlloc->bufferID) { @@ -163,8 +163,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, RsdVertexArray va(mAttribs, mAttribCount); va.setup(rsc); - Mesh::Primitive_t *prim = mRSMesh->mHal.state.primitives[primIndex]; - const Allocation *idxAlloc = prim->mIndexBuffer.get(); + const Allocation *idxAlloc = mRSMesh->mHal.state.indexBuffers[primIndex]; if (idxAlloc) { DrvAllocation *drvAlloc = (DrvAllocation *)idxAlloc->mHal.drv; if (drvAlloc->uploadDeferred) { @@ -190,7 +189,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, void RsdMeshObj::updateGLPrimitives() { mGLPrimitives = new uint32_t[mRSMesh->mHal.state.primitivesCount]; for (uint32_t i = 0; i < mRSMesh->mHal.state.primitivesCount; i ++) { - switch (mRSMesh->mHal.state.primitives[i]->mPrimitive) { + switch (mRSMesh->mHal.state.primitives[i]) { case RS_PRIMITIVE_POINT: mGLPrimitives[i] = GL_POINTS; break; case RS_PRIMITIVE_LINE: mGLPrimitives[i] = GL_LINES; break; case RS_PRIMITIVE_LINE_STRIP: mGLPrimitives[i] = GL_LINE_STRIP; break; diff --git a/libs/rs/driver/rsdProgram.cpp b/libs/rs/driver/rsdProgram.cpp index 27a66639148b..7556e50a37ec 100644 --- a/libs/rs/driver/rsdProgram.cpp +++ b/libs/rs/driver/rsdProgram.cpp @@ -43,7 +43,7 @@ bool rsdProgramVertexInit(const Context *rsc, const ProgramVertex *pv, static void SyncProgramConstants(const Context *rsc, const Program *p) { for (uint32_t ct=0; ct < p->mHal.state.texturesCount; ct++) { - const Allocation *a = p->mHal.state.textures[ct].get(); + const Allocation *a = p->mHal.state.textures[ct]; if (!a) { continue; } diff --git a/libs/rs/driver/rsdShader.cpp b/libs/rs/driver/rsdShader.cpp index 16ff0634748f..bdb60c24f917 100644 --- a/libs/rs/driver/rsdShader.cpp +++ b/libs/rs/driver/rsdShader.cpp @@ -69,7 +69,7 @@ void RsdShader::init() { uint32_t attribCount = 0; uint32_t uniformCount = 0; for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { - initAddUserElement(mRSProgram->mHal.state.inputElements[ct].get(), mAttribNames, NULL, &attribCount, RS_SHADER_ATTR); + initAddUserElement(mRSProgram->mHal.state.inputElements[ct], mAttribNames, NULL, &attribCount, RS_SHADER_ATTR); } for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) { initAddUserElement(mRSProgram->mHal.state.constantTypes[ct]->getElement(), mUniformNames, mUniformArraySizes, &uniformCount, RS_SHADER_UNI); @@ -89,7 +89,7 @@ void RsdShader::init() { String8 RsdShader::getGLSLInputString() const { String8 s; for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { - const Element *e = mRSProgram->mHal.state.inputElements[ct].get(); + const Element *e = mRSProgram->mHal.state.inputElements[ct]; for (uint32_t field=0; field < e->getFieldCount(); field++) { const Element *f = e->getField(field); @@ -113,7 +113,7 @@ String8 RsdShader::getGLSLInputString() const { void RsdShader::appendAttributes() { for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { - const Element *e = mRSProgram->mHal.state.inputElements[ct].get(); + const Element *e = mRSProgram->mHal.state.inputElements[ct]; for (uint32_t field=0; field < e->getFieldCount(); field++) { const Element *f = e->getField(field); const char *fn = e->getFieldName(field); @@ -414,7 +414,7 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) { RSD_CALL_GL(glActiveTexture, GL_TEXTURE0 + ct); RSD_CALL_GL(glUniform1i, sc->fragUniformSlot(mTextureUniformIndexStart + ct), ct); - if (!mRSProgram->mHal.state.textures[ct].get()) { + if (!mRSProgram->mHal.state.textures[ct]) { // if nothing is bound, reset to default GL texture RSD_CALL_GL(glBindTexture, mTextureTargets[ct], 0); continue; @@ -427,9 +427,9 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) { } RSD_CALL_GL(glBindTexture, drvTex->glTarget, drvTex->textureID); rsdGLCheckError(rsc, "ProgramFragment::setup tex bind"); - if (mRSProgram->mHal.state.samplers[ct].get()) { - setupSampler(rsc, mRSProgram->mHal.state.samplers[ct].get(), - mRSProgram->mHal.state.textures[ct].get()); + if (mRSProgram->mHal.state.samplers[ct]) { + setupSampler(rsc, mRSProgram->mHal.state.samplers[ct], + mRSProgram->mHal.state.textures[ct]); } else { RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -448,7 +448,7 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) { void RsdShader::setupUserConstants(const Context *rsc, RsdShaderCache *sc, bool isFragment) { uint32_t uidx = 0; for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) { - Allocation *alloc = mRSProgram->mHal.state.constants[ct].get(); + Allocation *alloc = mRSProgram->mHal.state.constants[ct]; if (!alloc) { LOGE("Attempting to set constants on shader id %u, but alloc at slot %u is not set", (uint32_t)this, ct); @@ -504,7 +504,7 @@ void RsdShader::setup(const android::renderscript::Context *rsc, RsdShaderCache void RsdShader::initAttribAndUniformArray() { mAttribCount = 0; for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { - const Element *elem = mRSProgram->mHal.state.inputElements[ct].get(); + const Element *elem = mRSProgram->mHal.state.inputElements[ct]; for (uint32_t field=0; field < elem->getFieldCount(); field++) { if (elem->getFieldName(field)[0] != '#') { mAttribCount ++; diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index 4359d957193a..e73263009fc6 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -30,7 +30,7 @@ Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages, mHal.state.usageFlags = usages; mHal.state.mipmapControl = mc; - mHal.state.type.set(type); + setType(type); updateCache(); } @@ -47,7 +47,7 @@ Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32 } void Allocation::updateCache() { - const Type *type = mHal.state.type.get(); + const Type *type = mHal.state.type; mHal.state.dimensionX = type->getDimX(); mHal.state.dimensionY = type->getDimY(); mHal.state.dimensionZ = type->getDimZ(); @@ -187,7 +187,7 @@ void Allocation::dumpLOGV(const char *prefix) const { String8 s(prefix); s.append(" type "); - if (mHal.state.type.get()) { + if (mHal.state.type) { mHal.state.type->dumpLOGV(s.string()); } @@ -314,7 +314,7 @@ void Allocation::resize1D(Context *rsc, uint32_t dimX) { decRefs(getPtr(), oldDimX - dimX, dimX); } rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences); - mHal.state.type.set(t.get()); + setType(t.get()); updateCache(); } diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h index 67fc3b5e0777..714798aa1e0c 100644 --- a/libs/rs/rsAllocation.h +++ b/libs/rs/rsAllocation.h @@ -41,7 +41,7 @@ public: void * drv; struct State { - ObjectBaseRef<const Type> type; + const Type * type; uint32_t usageFlags; RsAllocationMipmapControl mipmapControl; @@ -71,7 +71,7 @@ public: void updateCache(); void * getPtr() const {return mHal.drvState.mallocPtr;} - const Type * getType() const {return mHal.state.type.get();} + const Type * getType() const {return mHal.state.type;} void syncAll(Context *rsc, RsAllocationUsageType src); @@ -126,6 +126,11 @@ public: protected: Vector<const Program *> mToDirtyList; + ObjectBaseRef<const Type> mType; + void setType(const Type *t) { + mType.set(t); + mHal.state.type = t; + } private: void freeChildrenUnlocked(); diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp index d6ab0dac064c..71e1b91c6371 100644 --- a/libs/rs/rsElement.cpp +++ b/libs/rs/rsElement.cpp @@ -364,7 +364,7 @@ void rsaElementGetNativeData(RsContext con, RsElement elem, } void rsaElementGetSubElements(RsContext con, RsElement elem, uint32_t *ids, - const char **names, uint32_t dataSize) { + const char **names, uint32_t *arraySizes, uint32_t dataSize) { Element *e = static_cast<Element *>(elem); rsAssert(e->getFieldCount() == dataSize); @@ -372,5 +372,6 @@ void rsaElementGetSubElements(RsContext con, RsElement elem, uint32_t *ids, e->getField(i)->incUserRef(); ids[i] = (uint32_t)e->getField(i); names[i] = e->getFieldName(i); + arraySizes[i] = e->getFieldArraySize(i); } } diff --git a/libs/rs/rsFBOCache.cpp b/libs/rs/rsFBOCache.cpp index c5c64c27b602..f4a8bc6d7b30 100644 --- a/libs/rs/rsFBOCache.cpp +++ b/libs/rs/rsFBOCache.cpp @@ -26,11 +26,14 @@ using namespace android::renderscript; FBOCache::FBOCache() { mDirty = true; mHal.state.colorTargetsCount = 1; - mHal.state.colorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount]; + mHal.state.colorTargets = new Allocation*[mHal.state.colorTargetsCount]; + mColorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount]; + resetAll(NULL); } FBOCache::~FBOCache() { delete[] mHal.state.colorTargets; + delete[] mColorTargets; } void FBOCache::init(Context *rsc) { @@ -52,7 +55,8 @@ void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) { return; } } - mHal.state.colorTargets[slot].set(a); + mColorTargets[slot].set(a); + mHal.state.colorTargets[slot] = a; mDirty = true; } @@ -63,15 +67,18 @@ void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) { return; } } - mHal.state.depthTarget.set(a); + mDepthTarget.set(a); + mHal.state.depthTarget = a; mDirty = true; } void FBOCache::resetAll(Context *) { for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) { - mHal.state.colorTargets[i].set(NULL); + mColorTargets[i].set(NULL); + mHal.state.colorTargets[i] = NULL; } - mHal.state.depthTarget.set(NULL); + mDepthTarget.set(NULL); + mHal.state.depthTarget = NULL; mDirty = true; } diff --git a/libs/rs/rsFBOCache.h b/libs/rs/rsFBOCache.h index 5d58ba405416..abb84de0c83f 100644 --- a/libs/rs/rsFBOCache.h +++ b/libs/rs/rsFBOCache.h @@ -44,15 +44,17 @@ public: mutable void *drv; struct State { - ObjectBaseRef<Allocation> *colorTargets; + Allocation **colorTargets; uint32_t colorTargetsCount; - ObjectBaseRef<Allocation> depthTarget; + Allocation *depthTarget; }; State state; }; Hal mHal; protected: + ObjectBaseRef<Allocation> *mColorTargets; + ObjectBaseRef<Allocation> mDepthTarget; bool mDirty; void checkError(Context *); void setColorAttachment(Context *rsc); diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp index 359d09fdcd86..bf9284f56aaf 100644 --- a/libs/rs/rsMesh.cpp +++ b/libs/rs/rsMesh.cpp @@ -23,9 +23,14 @@ Mesh::Mesh(Context *rsc) : ObjectBase(rsc) { mHal.drv = NULL; mHal.state.primitives = NULL; mHal.state.primitivesCount = 0; + mHal.state.indexBuffers = NULL; + mHal.state.indexBuffersCount = 0; mHal.state.vertexBuffers = NULL; mHal.state.vertexBuffersCount = 0; mInitialized = false; + + mVertexBuffers = NULL; + mIndexBuffers = NULL; } Mesh::Mesh(Context *rsc, @@ -33,12 +38,23 @@ Mesh::Mesh(Context *rsc, uint32_t primitivesCount) : ObjectBase(rsc) { mHal.drv = NULL; mHal.state.primitivesCount = primitivesCount; - mHal.state.primitives = new Primitive_t *[mHal.state.primitivesCount]; + mHal.state.indexBuffersCount = primitivesCount; + mHal.state.primitives = new RsPrimitive[mHal.state.primitivesCount]; + mHal.state.indexBuffers = new Allocation *[mHal.state.indexBuffersCount]; for (uint32_t i = 0; i < mHal.state.primitivesCount; i ++) { - mHal.state.primitives[i] = new Primitive_t; + mHal.state.primitives[i] = RS_PRIMITIVE_POINT; + } + for (uint32_t i = 0; i < mHal.state.indexBuffersCount; i ++) { + mHal.state.indexBuffers[i] = NULL; } mHal.state.vertexBuffersCount = vertexBuffersCount; - mHal.state.vertexBuffers = new ObjectBaseRef<Allocation>[mHal.state.vertexBuffersCount]; + mHal.state.vertexBuffers = new Allocation *[mHal.state.vertexBuffersCount]; + for (uint32_t i = 0; i < mHal.state.vertexBuffersCount; i ++) { + mHal.state.vertexBuffers[i] = NULL; + } + + mVertexBuffers = new ObjectBaseRef<Allocation>[mHal.state.vertexBuffersCount]; + mIndexBuffers = new ObjectBaseRef<Allocation>[mHal.state.primitivesCount]; } Mesh::~Mesh() { @@ -46,17 +62,12 @@ Mesh::~Mesh() { mRSC->mHal.funcs.mesh.destroy(mRSC, this); #endif - if (mHal.state.vertexBuffers) { - delete[] mHal.state.vertexBuffers; - } + delete[] mHal.state.vertexBuffers; + delete[] mHal.state.primitives; + delete[] mHal.state.indexBuffers; - if (mHal.state.primitives) { - for (uint32_t i = 0; i < mHal.state.primitivesCount; i ++) { - mHal.state.primitives[i]->mIndexBuffer.clear(); - delete mHal.state.primitives[i]; - } - delete[] mHal.state.primitives; - } + delete[] mVertexBuffers; + delete[] mIndexBuffers; } void Mesh::init() { @@ -81,13 +92,11 @@ void Mesh::serialize(OStream *stream) const { stream->addU32(mHal.state.primitivesCount); // Store the primitives for (uint32_t pCount = 0; pCount < mHal.state.primitivesCount; pCount ++) { - Primitive_t * prim = mHal.state.primitives[pCount]; + stream->addU8((uint8_t)mHal.state.primitives[pCount]); - stream->addU8((uint8_t)prim->mPrimitive); - - if (prim->mIndexBuffer.get()) { + if (mHal.state.indexBuffers[pCount]) { stream->addU32(1); - prim->mIndexBuffer->serialize(stream); + mHal.state.indexBuffers[pCount]->serialize(stream); } else { stream->addU32(0); } @@ -173,10 +182,8 @@ void Mesh::renderPrimitive(Context *rsc, uint32_t primIndex) const { return; } - Primitive_t *prim = mHal.state.primitives[primIndex]; - - if (prim->mIndexBuffer.get()) { - renderPrimitiveRange(rsc, primIndex, 0, prim->mIndexBuffer->getType()->getDimX()); + if (mHal.state.indexBuffers[primIndex]) { + renderPrimitiveRange(rsc, primIndex, 0, mHal.state.indexBuffers[primIndex]->getType()->getDimX()); return; } @@ -194,14 +201,14 @@ void Mesh::renderPrimitiveRange(Context *rsc, uint32_t primIndex, uint32_t start void Mesh::uploadAll(Context *rsc) { for (uint32_t ct = 0; ct < mHal.state.vertexBuffersCount; ct ++) { - if (mHal.state.vertexBuffers[ct].get()) { - rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.vertexBuffers[ct].get()); + if (mHal.state.vertexBuffers[ct]) { + rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.vertexBuffers[ct]); } } for (uint32_t ct = 0; ct < mHal.state.primitivesCount; ct ++) { - if (mHal.state.primitives[ct]->mIndexBuffer.get()) { - rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.primitives[ct]->mIndexBuffer.get()); + if (mHal.state.indexBuffers[ct]) { + rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.indexBuffers[ct]); } } } @@ -290,7 +297,7 @@ void rsaMeshGetVertices(RsContext con, RsMesh mv, RsAllocation *vtxData, uint32_ rsAssert(vtxDataCount == sm->mHal.state.vertexBuffersCount); for (uint32_t ct = 0; ct < vtxDataCount; ct ++) { - vtxData[ct] = sm->mHal.state.vertexBuffers[ct].get(); + vtxData[ct] = sm->mHal.state.vertexBuffers[ct]; sm->mHal.state.vertexBuffers[ct]->incUserRef(); } } @@ -300,10 +307,10 @@ void rsaMeshGetIndices(RsContext con, RsMesh mv, RsAllocation *va, uint32_t *pri rsAssert(idxDataCount == sm->mHal.state.primitivesCount); for (uint32_t ct = 0; ct < idxDataCount; ct ++) { - va[ct] = sm->mHal.state.primitives[ct]->mIndexBuffer.get(); - primType[ct] = sm->mHal.state.primitives[ct]->mPrimitive; - if (sm->mHal.state.primitives[ct]->mIndexBuffer.get()) { - sm->mHal.state.primitives[ct]->mIndexBuffer->incUserRef(); + va[ct] = sm->mHal.state.indexBuffers[ct]; + primType[ct] = sm->mHal.state.primitives[ct]; + if (sm->mHal.state.indexBuffers[ct]) { + sm->mHal.state.indexBuffers[ct]->incUserRef(); } } } diff --git a/libs/rs/rsMesh.h b/libs/rs/rsMesh.h index ed1e93d63954..0fc73fba5c95 100644 --- a/libs/rs/rsMesh.h +++ b/libs/rs/rsMesh.h @@ -32,13 +32,6 @@ public: Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount); ~Mesh(); - // Either mIndexBuffer, mPrimitiveBuffer or both could have a NULL reference - // If both are null, mPrimitive only would be used to render the mesh - struct Primitive_t { - ObjectBaseRef<Allocation> mIndexBuffer; - RsPrimitive mPrimitive; - }; - virtual void serialize(OStream *stream) const; virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; } static Mesh *createFromStream(Context *rsc, IStream *stream); @@ -51,10 +44,13 @@ public: // Contains vertex data // Position, normal, texcoord, etc could either be strided in one allocation // of provided separetely in multiple ones - ObjectBaseRef<Allocation> *vertexBuffers; + Allocation **vertexBuffers; uint32_t vertexBuffersCount; - Primitive_t ** primitives; + // indexBuffers[i] could be NULL, in which case only primitives[i] is used + Allocation **indexBuffers; + uint32_t indexBuffersCount; + RsPrimitive *primitives; uint32_t primitivesCount; }; State state; @@ -62,12 +58,14 @@ public: Hal mHal; void setVertexBuffer(Allocation *vb, uint32_t index) { - mHal.state.vertexBuffers[index].set(vb); + mVertexBuffers[index].set(vb); + mHal.state.vertexBuffers[index] = vb; } void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) { - mHal.state.primitives[index]->mIndexBuffer.set(idx); - mHal.state.primitives[index]->mPrimitive = prim; + mIndexBuffers[index].set(idx); + mHal.state.indexBuffers[index] = idx; + mHal.state.primitives[index] = prim; } void render(Context *) const; @@ -80,6 +78,8 @@ public: float mBBoxMax[3]; void computeBBox(); protected: + ObjectBaseRef<Allocation> *mVertexBuffers; + ObjectBaseRef<Allocation> *mIndexBuffers; bool mInitialized; }; diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp index 4178aa5b547e..a9fd8776e5fd 100644 --- a/libs/rs/rsProgram.cpp +++ b/libs/rs/rsProgram.cpp @@ -37,22 +37,33 @@ Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, } } - mHal.state.textures = new ObjectBaseRef<Allocation>[mHal.state.texturesCount]; - mHal.state.samplers = new ObjectBaseRef<Sampler>[mHal.state.texturesCount]; + mTextures = new ObjectBaseRef<Allocation>[mHal.state.texturesCount]; + mSamplers = new ObjectBaseRef<Sampler>[mHal.state.texturesCount]; + mInputElements = new ObjectBaseRef<Element>[mHal.state.inputElementsCount]; + mConstantTypes = new ObjectBaseRef<Type>[mHal.state.constantsCount]; + mConstants = new ObjectBaseRef<Allocation>[mHal.state.constantsCount]; + + mHal.state.textures = new Allocation*[mHal.state.texturesCount]; + mHal.state.samplers = new Sampler*[mHal.state.texturesCount]; mHal.state.textureTargets = new RsTextureTarget[mHal.state.texturesCount]; - mHal.state.inputElements = new ObjectBaseRef<Element>[mHal.state.inputElementsCount]; - mHal.state.constantTypes = new ObjectBaseRef<Type>[mHal.state.constantsCount]; - mHal.state.constants = new ObjectBaseRef<Allocation>[mHal.state.constantsCount]; + mHal.state.inputElements = new Element*[mHal.state.inputElementsCount]; + mHal.state.constantTypes = new Type*[mHal.state.constantsCount]; + mHal.state.constants = new Allocation*[mHal.state.constantsCount]; + + // Will initialize everything + freeChildren(); uint32_t input = 0; uint32_t constant = 0; uint32_t texture = 0; for (uint32_t ct=0; ct < paramLength; ct+=2) { if (params[ct] == RS_PROGRAM_PARAM_INPUT) { - mHal.state.inputElements[input++].set(reinterpret_cast<Element *>(params[ct+1])); + mInputElements[input].set(reinterpret_cast<Element *>(params[ct+1])); + mHal.state.inputElements[input++] = reinterpret_cast<Element *>(params[ct+1]); } if (params[ct] == RS_PROGRAM_PARAM_CONSTANT) { - mHal.state.constantTypes[constant++].set(reinterpret_cast<Type *>(params[ct+1])); + mConstantTypes[constant].set(reinterpret_cast<Type *>(params[ct+1])); + mHal.state.constantTypes[constant++] = reinterpret_cast<Type *>(params[ct+1]); } if (params[ct] == RS_PROGRAM_PARAM_TEXTURE_TYPE) { mHal.state.textureTargets[texture++] = (RsTextureTarget)params[ct+1]; @@ -72,6 +83,12 @@ Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, Program::~Program() { freeChildren(); + delete[] mTextures; + delete[] mSamplers; + delete[] mInputElements; + delete[] mConstantTypes; + delete[] mConstants; + delete[] mHal.state.textures; delete[] mHal.state.samplers; delete[] mHal.state.textureTargets; @@ -110,6 +127,12 @@ void Program::initMemberVars() { mHal.state.constantsCount = 0; mHal.state.texturesCount = 0; + mTextures = NULL; + mSamplers = NULL; + mInputElements = NULL; + mConstantTypes = NULL; + mConstants = NULL; + mIsInternal = false; } @@ -121,20 +144,21 @@ void Program::bindAllocation(Context *rsc, Allocation *alloc, uint32_t slot) { rsc->setError(RS_ERROR_BAD_SHADER, "Cannot bind allocation"); return; } - if (alloc->getType() != mHal.state.constantTypes[slot].get()) { + if (alloc->getType() != mConstantTypes[slot].get()) { LOGE("Attempt to bind alloc at slot %u, on shader id %u, but types mismatch", slot, (uint32_t)this); rsc->setError(RS_ERROR_BAD_SHADER, "Cannot bind allocation"); return; } } - if (mHal.state.constants[slot].get() == alloc) { + if (mConstants[slot].get() == alloc) { return; } - if (mHal.state.constants[slot].get()) { - mHal.state.constants[slot].get()->removeProgramToDirty(this); + if (mConstants[slot].get()) { + mConstants[slot]->removeProgramToDirty(this); } - mHal.state.constants[slot].set(alloc); + mConstants[slot].set(alloc); + mHal.state.constants[slot] = alloc; if (alloc) { alloc->addProgramToDirty(this); } @@ -154,7 +178,9 @@ void Program::bindTexture(Context *rsc, uint32_t slot, Allocation *a) { return; } - mHal.state.textures[slot].set(a); + mTextures[slot].set(a); + mHal.state.textures[slot] = a; + mDirty = true; } @@ -165,7 +191,8 @@ void Program::bindSampler(Context *rsc, uint32_t slot, Sampler *s) { return; } - mHal.state.samplers[slot].set(s); + mSamplers[slot].set(s); + mHal.state.samplers[slot] = s; mDirty = true; } diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h index 3237a7295eca..06fc3eca71ab 100644 --- a/libs/rs/rsProgram.h +++ b/libs/rs/rsProgram.h @@ -30,19 +30,6 @@ namespace renderscript { class Program : public ProgramBase { public: - - Program(Context *, const char * shaderText, uint32_t shaderLength, - const uint32_t * params, uint32_t paramLength); - virtual ~Program(); - virtual bool freeChildren(); - - void bindAllocation(Context *, Allocation *, uint32_t slot); - - bool isUserProgram() const {return !mIsInternal;} - - void bindTexture(Context *, uint32_t slot, Allocation *); - void bindSampler(Context *, uint32_t slot, Sampler *); - struct Hal { mutable void *drv; @@ -53,25 +40,43 @@ public: // and filtered. // // Constants are strictly accessed by the shader code - ObjectBaseRef<Allocation> *textures; + Allocation **textures; RsTextureTarget *textureTargets; uint32_t texturesCount; - ObjectBaseRef<Sampler> *samplers; + Sampler **samplers; uint32_t samplersCount; - ObjectBaseRef<Allocation> *constants; - ObjectBaseRef<Type> *constantTypes; + Allocation **constants; + Type **constantTypes; uint32_t constantsCount; - ObjectBaseRef<Element> *inputElements; + Element **inputElements; uint32_t inputElementsCount; }; State state; }; Hal mHal; + Program(Context *, const char * shaderText, uint32_t shaderLength, + const uint32_t * params, uint32_t paramLength); + virtual ~Program(); + virtual bool freeChildren(); + + void bindAllocation(Context *, Allocation *, uint32_t slot); + + bool isUserProgram() const {return !mIsInternal;} + + void bindTexture(Context *, uint32_t slot, Allocation *); + void bindSampler(Context *, uint32_t slot, Sampler *); + protected: + ObjectBaseRef<Allocation> *mTextures; + ObjectBaseRef<Sampler> *mSamplers; + ObjectBaseRef<Allocation> *mConstants; + ObjectBaseRef<Type> *mConstantTypes; + ObjectBaseRef<Element> *mInputElements; + bool mIsInternal; String8 mUserShader; void initMemberVars(); diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp index ff2952051162..81eedc424994 100644 --- a/libs/rs/rsProgramFragment.cpp +++ b/libs/rs/rsProgramFragment.cpp @@ -42,7 +42,7 @@ void ProgramFragment::setConstantColor(Context *rsc, float r, float g, float b, rsc->setError(RS_ERROR_BAD_SHADER, "Cannot set fixed function emulation color on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { LOGE("Unable to set fixed function emulation color because allocation is missing"); rsc->setError(RS_ERROR_BAD_SHADER, "Unable to set fixed function emulation color because allocation is missing"); return; @@ -62,7 +62,7 @@ void ProgramFragment::setup(Context *rsc, ProgramFragmentState *state) { state->mLast.set(this); for (uint32_t ct=0; ct < mHal.state.texturesCount; ct++) { - if (!mHal.state.textures[ct].get()) { + if (!mHal.state.textures[ct]) { LOGE("No texture bound for shader id %u, texture unit %u", (uint)this, ct); rsc->setError(RS_ERROR_BAD_SHADER, "No texture bound"); continue; diff --git a/libs/rs/rsProgramRaster.h b/libs/rs/rsProgramRaster.h index 20af30a1b90b..c552ea3004d6 100644 --- a/libs/rs/rsProgramRaster.h +++ b/libs/rs/rsProgramRaster.h @@ -24,17 +24,16 @@ namespace android { namespace renderscript { class ProgramRasterState; - +/***************************************************************************** + * CAUTION + * + * Any layout changes for this class may require a corresponding change to be + * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains + * a partial copy of the information below. + * + *****************************************************************************/ class ProgramRaster : public ProgramBase { public: - virtual void setup(const Context *, ProgramRasterState *); - virtual void serialize(OStream *stream) const; - virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_RASTER; } - static ProgramRaster *createFromStream(Context *rsc, IStream *stream); - - static ObjectBaseRef<ProgramRaster> getProgramRaster(Context *rsc, - bool pointSprite, - RsCullMode cull); struct Hal { mutable void *drv; @@ -46,6 +45,14 @@ public: }; Hal mHal; + virtual void setup(const Context *, ProgramRasterState *); + virtual void serialize(OStream *stream) const; + virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_RASTER; } + static ProgramRaster *createFromStream(Context *rsc, IStream *stream); + + static ObjectBaseRef<ProgramRaster> getProgramRaster(Context *rsc, + bool pointSprite, + RsCullMode cull); protected: virtual void preDestroy() const; virtual ~ProgramRaster(); diff --git a/libs/rs/rsProgramStore.h b/libs/rs/rsProgramStore.h index e21f039678b3..9bb2795cba5d 100644 --- a/libs/rs/rsProgramStore.h +++ b/libs/rs/rsProgramStore.h @@ -25,23 +25,16 @@ namespace android { namespace renderscript { class ProgramStoreState; - +/***************************************************************************** + * CAUTION + * + * Any layout changes for this class may require a corresponding change to be + * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains + * a partial copy of the information below. + * + *****************************************************************************/ class ProgramStore : public ProgramBase { public: - virtual void setup(const Context *, ProgramStoreState *); - - virtual void serialize(OStream *stream) const; - virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; } - static ProgramStore *createFromStream(Context *rsc, IStream *stream); - static ObjectBaseRef<ProgramStore> getProgramStore(Context *, - bool colorMaskR, bool colorMaskG, - bool colorMaskB, bool colorMaskA, - bool depthMask, bool ditherEnable, - RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, - RsDepthFunc depthFunc); - - void init(); - struct Hal { mutable void *drv; @@ -64,6 +57,18 @@ public: }; Hal mHal; + virtual void setup(const Context *, ProgramStoreState *); + + virtual void serialize(OStream *stream) const; + virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; } + static ProgramStore *createFromStream(Context *rsc, IStream *stream); + static ObjectBaseRef<ProgramStore> getProgramStore(Context *, + bool colorMaskR, bool colorMaskG, + bool colorMaskB, bool colorMaskA, + bool depthMask, bool ditherEnable, + RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, + RsDepthFunc depthFunc); + void init(); protected: virtual void preDestroy() const; virtual ~ProgramStore(); diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp index 51cb2a8ad490..4a1362254b0b 100644 --- a/libs/rs/rsProgramVertex.cpp +++ b/libs/rs/rsProgramVertex.cpp @@ -38,7 +38,7 @@ void ProgramVertex::setup(Context *rsc, ProgramVertexState *state) { } if (!isUserProgram()) { - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to set fixed function emulation matrices because allocation is missing"); return; @@ -65,7 +65,7 @@ void ProgramVertex::setProjectionMatrix(Context *rsc, const rsc_Matrix *m) const "Attempting to set fixed function emulation matrix projection on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to set fixed function emulation matrix projection because allocation is missing"); return; @@ -81,7 +81,7 @@ void ProgramVertex::setModelviewMatrix(Context *rsc, const rsc_Matrix *m) const "Attempting to set fixed function emulation matrix modelview on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to set fixed function emulation matrix modelview because allocation is missing"); return; @@ -97,7 +97,7 @@ void ProgramVertex::setTextureMatrix(Context *rsc, const rsc_Matrix *m) const { "Attempting to set fixed function emulation matrix texture on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to set fixed function emulation matrix texture because allocation is missing"); return; @@ -113,7 +113,7 @@ void ProgramVertex::getProjectionMatrix(Context *rsc, rsc_Matrix *m) const { "Attempting to get fixed function emulation matrix projection on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to get fixed function emulation matrix projection because allocation is missing"); return; diff --git a/libs/rs/rsSampler.h b/libs/rs/rsSampler.h index e698132d0f70..654cd9ce1a06 100644 --- a/libs/rs/rsSampler.h +++ b/libs/rs/rsSampler.h @@ -27,23 +27,16 @@ namespace renderscript { const static uint32_t RS_MAX_SAMPLER_SLOT = 16; class SamplerState; - +/***************************************************************************** + * CAUTION + * + * Any layout changes for this class may require a corresponding change to be + * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains + * a partial copy of the information below. + * + *****************************************************************************/ class Sampler : public ObjectBase { public: - static ObjectBaseRef<Sampler> getSampler(Context *, - RsSamplerValue magFilter, - RsSamplerValue minFilter, - RsSamplerValue wrapS, - RsSamplerValue wrapT, - RsSamplerValue wrapR, - float aniso = 1.0f); - void bindToContext(SamplerState *, uint32_t slot); - void unbindFromContext(SamplerState *); - - virtual void serialize(OStream *stream) const; - virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; } - static Sampler *createFromStream(Context *rsc, IStream *stream); - struct Hal { mutable void *drv; @@ -59,6 +52,20 @@ public: }; Hal mHal; + static ObjectBaseRef<Sampler> getSampler(Context *, + RsSamplerValue magFilter, + RsSamplerValue minFilter, + RsSamplerValue wrapS, + RsSamplerValue wrapT, + RsSamplerValue wrapR, + float aniso = 1.0f); + void bindToContext(SamplerState *, uint32_t slot); + void unbindFromContext(SamplerState *); + + virtual void serialize(OStream *stream) const; + virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; } + static Sampler *createFromStream(Context *rsc, IStream *stream); + protected: int32_t mBoundSlot; diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh index 3e9339e07619..80267c773b47 100644 --- a/libs/rs/scriptc/rs_graphics.rsh +++ b/libs/rs/scriptc/rs_graphics.rsh @@ -23,6 +23,55 @@ #ifndef __RS_GRAPHICS_RSH__ #define __RS_GRAPHICS_RSH__ +// These are API 15 once it get official +typedef enum { + RS_DEPTH_FUNC_ALWAYS, + RS_DEPTH_FUNC_LESS, + RS_DEPTH_FUNC_LEQUAL, + RS_DEPTH_FUNC_GREATER, + RS_DEPTH_FUNC_GEQUAL, + RS_DEPTH_FUNC_EQUAL, + RS_DEPTH_FUNC_NOTEQUAL +} rs_depth_func; + +typedef enum { + RS_BLEND_SRC_ZERO, // 0 + RS_BLEND_SRC_ONE, // 1 + RS_BLEND_SRC_DST_COLOR, // 2 + RS_BLEND_SRC_ONE_MINUS_DST_COLOR, // 3 + RS_BLEND_SRC_SRC_ALPHA, // 4 + RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA, // 5 + RS_BLEND_SRC_DST_ALPHA, // 6 + RS_BLEND_SRC_ONE_MINUS_DST_ALPHA, // 7 + RS_BLEND_SRC_SRC_ALPHA_SATURATE // 8 +} rs_blend_src_func; + +typedef enum { + RS_BLEND_DST_ZERO, // 0 + RS_BLEND_DST_ONE, // 1 + RS_BLEND_DST_SRC_COLOR, // 2 + RS_BLEND_DST_ONE_MINUS_SRC_COLOR, // 3 + RS_BLEND_DST_SRC_ALPHA, // 4 + RS_BLEND_DST_ONE_MINUS_SRC_ALPHA, // 5 + RS_BLEND_DST_DST_ALPHA, // 6 + RS_BLEND_DST_ONE_MINUS_DST_ALPHA // 7 +} rs_blend_dst_func; + +typedef enum { + RS_CULL_BACK, + RS_CULL_FRONT, + RS_CULL_NONE +} rs_cull_mode; + +typedef enum { + RS_SAMPLER_NEAREST, + RS_SAMPLER_LINEAR, + RS_SAMPLER_LINEAR_MIP_LINEAR, + RS_SAMPLER_WRAP, + RS_SAMPLER_CLAMP, + RS_SAMPLER_LINEAR_MIP_NEAREST, +} rs_sampler_value; + #if (defined(RS_VERSION) && (RS_VERSION >= 14)) /** * Set the color target used for all subsequent rendering calls @@ -83,6 +132,88 @@ extern void __attribute__((overloadable)) extern void __attribute__((overloadable)) rsgBindProgramStore(rs_program_store ps); + +/** + * @hide + * Get program store depth function + * + * @param ps + */ +extern rs_depth_func __attribute__((overloadable)) + rsgProgramStoreGetDepthFunc(rs_program_store ps); + +/** + * @hide + * Get program store depth mask + * + * @param ps + */ +extern bool __attribute__((overloadable)) + rsgProgramStoreGetDepthMask(rs_program_store ps); +/** + * @hide + * Get program store red component color mask + * + * @param ps + */ +extern bool __attribute__((overloadable)) + rsgProgramStoreGetColorMaskR(rs_program_store ps); + +/** + * @hide + * Get program store green component color mask + * + * @param ps + */ +extern bool __attribute__((overloadable)) + rsgProgramStoreGetColorMaskG(rs_program_store ps); + +/** + * @hide + * Get program store blur component color mask + * + * @param ps + */ +extern bool __attribute__((overloadable)) + rsgProgramStoreGetColorMaskB(rs_program_store ps); + +/** + * @hide + * Get program store alpha component color mask + * + * @param ps + */ +extern bool __attribute__((overloadable)) + rsgProgramStoreGetColorMaskA(rs_program_store ps); + +/** + * @hide + * Get program store blend source function + * + * @param ps + */ +extern rs_blend_src_func __attribute__((overloadable)) + rsgProgramStoreGetBlendSrcFunc(rs_program_store ps); + +/** + * @hide + * Get program store blend destination function + * + * @param ps + */ +extern rs_blend_dst_func __attribute__((overloadable)) + rsgProgramStoreGetBlendDstFunc(rs_program_store ps); + +/** + * @hide + * Get program store dither state + * + * @param ps + */ +extern bool __attribute__((overloadable)) + rsgProgramStoreGetDitherEnabled(rs_program_store ps); + + /** * Bind a new ProgramVertex to the rendering context. * @@ -100,6 +231,24 @@ extern void __attribute__((overloadable)) rsgBindProgramRaster(rs_program_raster pr); /** + * @hide + * Get program raster point sprite state + * + * @param pr + */ +extern bool __attribute__((overloadable)) + rsgProgramRasterGetPointSpriteEnabled(rs_program_raster pr); + +/** + * @hide + * Get program raster cull mode + * + * @param pr + */ +extern rs_cull_mode __attribute__((overloadable)) + rsgProgramRasterGetCullMode(rs_program_raster pr); + +/** * Bind a new Sampler object to a ProgramFragment. The sampler will * operate on the texture bound at the matching slot. * @@ -109,6 +258,51 @@ extern void __attribute__((overloadable)) rsgBindSampler(rs_program_fragment, uint slot, rs_sampler); /** + * @hide + * Get sampler minification value + * + * @param pr + */ +extern rs_sampler_value __attribute__((overloadable)) + rsgSamplerGetMinification(rs_sampler s); + +/** + * @hide + * Get sampler magnification value + * + * @param pr + */ +extern rs_sampler_value __attribute__((overloadable)) + rsgSamplerGetMagnification(rs_sampler s); + +/** + * @hide + * Get sampler wrap S value + * + * @param pr + */ +extern rs_sampler_value __attribute__((overloadable)) + rsgSamplerGetWrapS(rs_sampler s); + +/** + * @hide + * Get sampler wrap T value + * + * @param pr + */ +extern rs_sampler_value __attribute__((overloadable)) + rsgSamplerGetWrapT(rs_sampler s); + +/** + * @hide + * Get sampler anisotropy + * + * @param pr + */ +extern float __attribute__((overloadable)) + rsgSamplerGetAnisotropy(rs_sampler s); + +/** * Bind a new Allocation object to a ProgramFragment. The * Allocation must be a valid texture for the Program. The sampling * of the texture will be controled by the Sampler bound at the diff --git a/libs/rs/scriptc/rs_quaternion.rsh b/libs/rs/scriptc/rs_quaternion.rsh index 23945ae691df..4e08d2f81b74 100644 --- a/libs/rs/scriptc/rs_quaternion.rsh +++ b/libs/rs/scriptc/rs_quaternion.rsh @@ -66,19 +66,6 @@ rsQuaternionMultiply(rs_quaternion *q, float s) { } /** - * Multiply quaternion by another quaternion - * @param q destination quaternion - * @param rhs right hand side quaternion to multiply by - */ -static void __attribute__((overloadable)) -rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) { - q->w = -q->x*rhs->x - q->y*rhs->y - q->z*rhs->z + q->w*rhs->w; - q->x = q->x*rhs->w + q->y*rhs->z - q->z*rhs->y + q->w*rhs->x; - q->y = -q->x*rhs->z + q->y*rhs->w + q->z*rhs->x + q->w*rhs->y; - q->z = q->x*rhs->y - q->y*rhs->x + q->z*rhs->w + q->w*rhs->z; -} - -/** * Add two quaternions * @param q destination quaternion to add to * @param rsh right hand side quaternion to add @@ -168,6 +155,23 @@ rsQuaternionNormalize(rs_quaternion *q) { } /** + * Multiply quaternion by another quaternion + * @param q destination quaternion + * @param rhs right hand side quaternion to multiply by + */ +static void __attribute__((overloadable)) +rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) { + rs_quaternion qtmp; + rsQuaternionSet(&qtmp, q); + + q->w = qtmp.w*rhs->w - qtmp.x*rhs->x - qtmp.y*rhs->y - qtmp.z*rhs->z; + q->x = qtmp.w*rhs->x + qtmp.x*rhs->w + qtmp.y*rhs->z - qtmp.z*rhs->y; + q->y = qtmp.w*rhs->y + qtmp.y*rhs->w + qtmp.z*rhs->x - qtmp.x*rhs->z; + q->z = qtmp.w*rhs->z + qtmp.z*rhs->w + qtmp.x*rhs->y - qtmp.y*rhs->x; + rsQuaternionNormalize(q); +} + +/** * Performs spherical linear interpolation between two quaternions * @param q result quaternion from interpolation * @param q0 first param @@ -222,34 +226,26 @@ rsQuaternionSlerp(rs_quaternion *q, const rs_quaternion *q0, const rs_quaternion * @param p normalized quaternion */ static void rsQuaternionGetMatrixUnit(rs_matrix4x4 *m, const rs_quaternion *q) { - float x2 = 2.0f * q->x * q->x; - float y2 = 2.0f * q->y * q->y; - float z2 = 2.0f * q->z * q->z; - float xy = 2.0f * q->x * q->y; - float wz = 2.0f * q->w * q->z; - float xz = 2.0f * q->x * q->z; - float wy = 2.0f * q->w * q->y; - float wx = 2.0f * q->w * q->x; - float yz = 2.0f * q->y * q->z; - - m->m[0] = 1.0f - y2 - z2; - m->m[1] = xy - wz; - m->m[2] = xz + wy; - m->m[3] = 0.0f; - - m->m[4] = xy + wz; - m->m[5] = 1.0f - x2 - z2; - m->m[6] = yz - wx; - m->m[7] = 0.0f; - - m->m[8] = xz - wy; - m->m[9] = yz - wx; - m->m[10] = 1.0f - x2 - y2; - m->m[11] = 0.0f; - - m->m[12] = 0.0f; - m->m[13] = 0.0f; - m->m[14] = 0.0f; + float xx = q->x * q->x; + float xy = q->x * q->y; + float xz = q->x * q->z; + float xw = q->x * q->w; + float yy = q->y * q->y; + float yz = q->y * q->z; + float yw = q->y * q->w; + float zz = q->z * q->z; + float zw = q->z * q->w; + + m->m[0] = 1.0f - 2.0f * ( yy + zz ); + m->m[4] = 2.0f * ( xy - zw ); + m->m[8] = 2.0f * ( xz + yw ); + m->m[1] = 2.0f * ( xy + zw ); + m->m[5] = 1.0f - 2.0f * ( xx + zz ); + m->m[9] = 2.0f * ( yz - xw ); + m->m[2] = 2.0f * ( xz - yw ); + m->m[6] = 2.0f * ( yz + xw ); + m->m[10] = 1.0f - 2.0f * ( xx + yy ); + m->m[3] = m->m[7] = m->m[11] = m->m[12] = m->m[13] = m->m[14] = 0.0f; m->m[15] = 1.0f; } diff --git a/libs/utils/Android.mk b/libs/utils/Android.mk index 638f72f0b66a..831d9e37890c 100644 --- a/libs/utils/Android.mk +++ b/libs/utils/Android.mk @@ -71,6 +71,10 @@ LOCAL_CFLAGS += -DMB_CUR_MAX=1 endif endif +ifeq ($(TARGET_OS),linux) +LOCAL_LDLIBS += -lrt -ldl +endif + include $(BUILD_HOST_STATIC_LIBRARY) |