summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorJason Sams <jsams@google.com>2012-03-23 11:47:26 -0700
committerJason Sams <jsams@google.com>2012-03-23 11:47:26 -0700
commitfe1d5ffd1b6c4977a9f301997d2ad90e5b049a3b (patch)
tree7a3135d31e4415a4b6b31c7e44ad15cfa1ccc86f /libs
parent3da5525558ad84757c48907eead66f44f0f5dd32 (diff)
downloadframeworks_base-fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3b.zip
frameworks_base-fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3b.tar.gz
frameworks_base-fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3b.tar.bz2
Implement USAGE_IO_INPUT
Change-Id: Idbf7bb21f5ab673ad77082c5c19921d2b276c04b
Diffstat (limited to 'libs')
-rw-r--r--libs/rs/Allocation.cpp9
-rw-r--r--libs/rs/driver/rsdAllocation.cpp8
-rw-r--r--libs/rs/driver/rsdCore.cpp2
-rw-r--r--libs/rs/driver/rsdProgram.cpp6
-rw-r--r--libs/rs/driver/rsdShader.cpp42
-rw-r--r--libs/rs/driver/rsdShader.h7
-rw-r--r--libs/rs/driver/rsdShaderCache.cpp5
-rw-r--r--libs/rs/driver/rsdShaderCache.h2
-rw-r--r--libs/rs/rs.spec6
-rw-r--r--libs/rs/rsAllocation.cpp19
-rw-r--r--libs/rs/rsAllocation.h4
-rw-r--r--libs/rs/rsDefines.h7
12 files changed, 77 insertions, 40 deletions
diff --git a/libs/rs/Allocation.cpp b/libs/rs/Allocation.cpp
index d69c55f..e37d5de 100644
--- a/libs/rs/Allocation.cpp
+++ b/libs/rs/Allocation.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2012 The Android Open Source Project
+ * Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,17 +51,14 @@ Allocation::Allocation(void *id, RenderScript *rs, const Type *t, uint32_t usage
RS_ALLOCATION_USAGE_GRAPHICS_VERTEX |
RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS |
RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET |
- RS_ALLOCATION_USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE |
RS_ALLOCATION_USAGE_IO_INPUT |
RS_ALLOCATION_USAGE_IO_OUTPUT)) != 0) {
ALOGE("Unknown usage specified.");
}
- if ((usage & (RS_ALLOCATION_USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE |
- RS_ALLOCATION_USAGE_IO_INPUT)) != 0) {
+ if ((usage & RS_ALLOCATION_USAGE_IO_INPUT) != 0) {
mWriteAllowed = false;
- if ((usage & ~(RS_ALLOCATION_USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE |
- RS_ALLOCATION_USAGE_IO_INPUT |
+ if ((usage & ~(RS_ALLOCATION_USAGE_IO_INPUT |
RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE |
RS_ALLOCATION_USAGE_SCRIPT)) != 0) {
ALOGE("Invalid usage combination.");
diff --git a/libs/rs/driver/rsdAllocation.cpp b/libs/rs/driver/rsdAllocation.cpp
index fb93d82..f358f93 100644
--- a/libs/rs/driver/rsdAllocation.cpp
+++ b/libs/rs/driver/rsdAllocation.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2011-2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
#include "hardware/gralloc.h"
#include "ui/Rect.h"
#include "ui/GraphicBufferMapper.h"
+#include "gui/SurfaceTexture.h"
#include <GLES/gl.h>
#include <GLES2/gl2.h>
@@ -139,7 +140,7 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is
static void UploadToTexture(const Context *rsc, const Allocation *alloc) {
DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
- if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE) {
+ if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_INPUT) {
if (!drv->textureID) {
RSD_CALL_GL(glGenTextures, 1, &drv->textureID);
}
@@ -475,7 +476,8 @@ void rsdAllocationIoSend(const Context *rsc, Allocation *alloc) {
}
void rsdAllocationIoReceive(const Context *rsc, Allocation *alloc) {
- ALOGE("not implemented");
+ DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
+ alloc->mHal.state.surfaceTexture->updateTexImage();
}
diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp
index 35a5c08..6a532e9 100644
--- a/libs/rs/driver/rsdCore.cpp
+++ b/libs/rs/driver/rsdCore.cpp
@@ -227,13 +227,13 @@ bool rsdHalInit(Context *rsc, uint32_t version_major, uint32_t version_minor) {
int cpu = sysconf(_SC_NPROCESSORS_ONLN);
- ALOGV("%p Launching thread(s), CPUs %i", rsc, cpu);
if(rsc->props.mDebugMaxThreads && (cpu > (int)rsc->props.mDebugMaxThreads)) {
cpu = rsc->props.mDebugMaxThreads;
}
if (cpu < 2) {
cpu = 0;
}
+ ALOGV("%p Launching thread(s), CPUs %i", rsc, cpu);
dc->mWorkers.mCount = (uint32_t)cpu;
dc->mWorkers.mThreadId = (pthread_t *) calloc(dc->mWorkers.mCount, sizeof(pthread_t));
diff --git a/libs/rs/driver/rsdProgram.cpp b/libs/rs/driver/rsdProgram.cpp
index fa4cb0f..30a4c5f 100644
--- a/libs/rs/driver/rsdProgram.cpp
+++ b/libs/rs/driver/rsdProgram.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2011-2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ bool rsdProgramVertexInit(const Context *rsc, const ProgramVertex *pv,
textureNames, textureNamesCount, textureNamesLength);
pv->mHal.drv = drv;
- return drv->createShader();
+ return true;
}
static void SyncProgramConstants(const Context *rsc, const Program *p) {
@@ -88,7 +88,7 @@ bool rsdProgramFragmentInit(const Context *rsc, const ProgramFragment *pf,
textureNames, textureNamesCount, textureNamesLength);
pf->mHal.drv = drv;
- return drv->createShader();
+ return true;
}
void rsdProgramFragmentSetActive(const Context *rsc, const ProgramFragment *pf) {
diff --git a/libs/rs/driver/rsdShader.cpp b/libs/rs/driver/rsdShader.cpp
index 1e73b95..a386735 100644
--- a/libs/rs/driver/rsdShader.cpp
+++ b/libs/rs/driver/rsdShader.cpp
@@ -39,7 +39,10 @@ RsdShader::RsdShader(const Program *p, uint32_t type,
initMemberVars();
initAttribAndUniformArray();
init(textureNames, textureNamesCount, textureNamesLength);
- createTexturesString(textureNames, textureNamesCount, textureNamesLength);
+
+ for(size_t i=0; i < textureNamesCount; i++) {
+ mTextureNames.push(String8(textureNames[i], textureNamesLength[i]));
+ }
}
RsdShader::~RsdShader() {
@@ -138,37 +141,42 @@ void RsdShader::appendAttributes() {
}
}
-void RsdShader::createTexturesString(const char** textureNames, size_t textureNamesCount,
- const size_t *textureNamesLength) {
- mShaderTextures.setTo("");
+void RsdShader::appendTextures() {
+
+ // TODO: this does not yet handle cases where the texture changes between IO
+ // input and local
+ bool appendUsing = true;
for (uint32_t ct = 0; ct < mRSProgram->mHal.state.texturesCount; ct ++) {
if (mRSProgram->mHal.state.textureTargets[ct] == RS_TEXTURE_2D) {
Allocation *a = mRSProgram->mHal.state.textures[ct];
if (a && a->mHal.state.surfaceTextureID) {
- mShaderTextures.append("uniform samplerExternalOES UNI_");
+ if(appendUsing) {
+ mShader.append("#extension GL_OES_EGL_image_external : require\n");
+ appendUsing = false;
+ }
+ mShader.append("uniform samplerExternalOES UNI_");
+ mTextureTargets[ct] = GL_TEXTURE_EXTERNAL_OES;
} else {
- mShaderTextures.append("uniform sampler2D UNI_");
+ mShader.append("uniform sampler2D UNI_");
+ mTextureTargets[ct] = GL_TEXTURE_2D;
}
- mTextureTargets[ct] = GL_TEXTURE_2D;
} else {
- mShaderTextures.append("uniform samplerCube UNI_");
+ mShader.append("uniform samplerCube UNI_");
mTextureTargets[ct] = GL_TEXTURE_CUBE_MAP;
}
- mShaderTextures.append(textureNames[ct], textureNamesLength[ct]);
- mShaderTextures.append(";\n");
+ mShader.append(mTextureNames[ct]);
+ mShader.append(";\n");
}
}
bool RsdShader::createShader() {
-
if (mType == GL_FRAGMENT_SHADER) {
mShader.append("precision mediump float;\n");
}
appendUserConstants();
appendAttributes();
- mShader.append(mShaderTextures);
-
+ appendTextures();
mShader.append(mUserShader);
return true;
@@ -178,6 +186,10 @@ bool RsdShader::loadShader(const Context *rsc) {
mShaderID = glCreateShader(mType);
rsAssert(mShaderID);
+ if(!mShader.length()) {
+ createShader();
+ }
+
if (rsc->props.mLogShaders) {
ALOGV("Loading shader type %x, ID %i", mType, mShaderID);
ALOGV("%s", mShader.string());
@@ -423,7 +435,9 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) {
}
DrvAllocation *drvTex = (DrvAllocation *)mRSProgram->mHal.state.textures[ct]->mHal.drv;
- if (drvTex->glTarget != GL_TEXTURE_2D && drvTex->glTarget != GL_TEXTURE_CUBE_MAP) {
+ if (drvTex->glTarget != GL_TEXTURE_2D &&
+ drvTex->glTarget != GL_TEXTURE_CUBE_MAP &&
+ drvTex->glTarget != GL_TEXTURE_EXTERNAL_OES) {
ALOGE("Attempting to bind unknown texture to shader id %u, texture unit %u",
(uint)this, ct);
rsc->setError(RS_ERROR_BAD_SHADER, "Non-texture allocation bound to a shader");
diff --git a/libs/rs/driver/rsdShader.h b/libs/rs/driver/rsdShader.h
index e32145f..6c0b616 100644
--- a/libs/rs/driver/rsdShader.h
+++ b/libs/rs/driver/rsdShader.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2011-2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,15 +81,12 @@ protected:
void appendAttributes();
void appendTextures();
- void createTexturesString(const char** textureNames, size_t textureNamesCount,
- const size_t *textureNamesLength);
void initAttribAndUniformArray();
mutable bool mDirty;
android::String8 mShader;
android::String8 mUserShader;
- android::String8 mShaderTextures;
uint32_t mShaderID;
uint32_t mType;
@@ -101,6 +98,8 @@ protected:
android::String8 *mUniformNames;
uint32_t *mUniformArraySizes;
+ android::Vector<android::String8> mTextureNames;
+
int32_t mTextureUniformIndexStart;
void logUniform(const android::renderscript::Element *field,
diff --git a/libs/rs/driver/rsdShaderCache.cpp b/libs/rs/driver/rsdShaderCache.cpp
index 89d3c45..50cb9f9 100644
--- a/libs/rs/driver/rsdShaderCache.cpp
+++ b/libs/rs/driver/rsdShaderCache.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2011-2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -119,7 +119,6 @@ bool RsdShaderCache::link(const Context *rsc) {
if (!vtx->getShaderID() || !frag->getShaderID()) {
return false;
}
- //ALOGV("rsdShaderCache lookup vtx %i, frag %i", vtx->getShaderID(), frag->getShaderID());
uint32_t entryCount = mEntries.size();
for (uint32_t ct = 0; ct < entryCount; ct ++) {
if ((mEntries[ct]->vtx == vtx->getShaderID()) &&
@@ -134,8 +133,6 @@ bool RsdShaderCache::link(const Context *rsc) {
}
}
- //ALOGV("RsdShaderCache miss");
- //ALOGE("e0 %x", glGetError());
ProgramEntry *e = new ProgramEntry(vtx->getAttribCount(),
vtx->getUniformCount(),
frag->getUniformCount());
diff --git a/libs/rs/driver/rsdShaderCache.h b/libs/rs/driver/rsdShaderCache.h
index 0beecae..1192916 100644
--- a/libs/rs/driver/rsdShaderCache.h
+++ b/libs/rs/driver/rsdShaderCache.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2011-2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index cf4a391..b373056 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -69,6 +69,12 @@ AllocationGetSurfaceTextureID {
ret int32_t
}
+AllocationGetSurfaceTextureID2 {
+ param RsAllocation alloc
+ param void *st
+ sync
+}
+
AllocationSetSurface {
param RsAllocation alloc
param RsNativeWindow sur
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index a404c49..cdff49c 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -20,6 +20,7 @@
#include "rs_hal.h"
#include "system/window.h"
+#include "gui/SurfaceTexture.h"
using namespace android;
using namespace android::renderscript;
@@ -64,6 +65,7 @@ void Allocation::updateCache() {
Allocation::~Allocation() {
freeChildrenUnlocked();
+ setSurfaceTexture(mRSC, NULL);
mRSC->mHal.funcs.allocation.destroy(mRSC, this);
}
@@ -424,6 +426,18 @@ int32_t Allocation::getSurfaceTextureID(const Context *rsc) {
return id;
}
+void Allocation::setSurfaceTexture(const Context *rsc, SurfaceTexture *st) {
+ if(st != mHal.state.surfaceTexture) {
+ if(mHal.state.surfaceTexture != NULL) {
+ mHal.state.surfaceTexture->decStrong(NULL);
+ }
+ mHal.state.surfaceTexture = st;
+ if(mHal.state.surfaceTexture != NULL) {
+ mHal.state.surfaceTexture->incStrong(NULL);
+ }
+ }
+}
+
void Allocation::setSurface(const Context *rsc, RsNativeWindow sur) {
ANativeWindow *nw = (ANativeWindow *)sur;
ANativeWindow *old = mHal.state.wndSurface;
@@ -696,6 +710,11 @@ int32_t rsi_AllocationGetSurfaceTextureID(Context *rsc, RsAllocation valloc) {
return alloc->getSurfaceTextureID(rsc);
}
+void rsi_AllocationGetSurfaceTextureID2(Context *rsc, RsAllocation valloc, void *vst, size_t len) {
+ Allocation *alloc = static_cast<Allocation *>(valloc);
+ alloc->setSurfaceTexture(rsc, static_cast<SurfaceTexture *>(vst));
+}
+
void rsi_AllocationSetSurface(Context *rsc, RsAllocation valloc, RsNativeWindow sur) {
Allocation *alloc = static_cast<Allocation *>(valloc);
alloc->setSurface(rsc, sur);
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index 58a6fca..e2783d2 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -23,6 +23,8 @@ struct ANativeWindow;
// ---------------------------------------------------------------------------
namespace android {
+class SurfaceTexture;
+
namespace renderscript {
class Program;
@@ -60,6 +62,7 @@ public:
void * usrPtr;
int32_t surfaceTextureID;
ANativeWindow *wndSurface;
+ SurfaceTexture *surfaceTexture;
};
State state;
@@ -130,6 +133,7 @@ public:
}
int32_t getSurfaceTextureID(const Context *rsc);
+ void setSurfaceTexture(const Context *rsc, SurfaceTexture *st);
void setSurface(const Context *rsc, RsNativeWindow sur);
void ioSend(const Context *rsc);
void ioReceive(const Context *rsc);
diff --git a/libs/rs/rsDefines.h b/libs/rs/rsDefines.h
index 990ef26..0e0cd8d 100644
--- a/libs/rs/rsDefines.h
+++ b/libs/rs/rsDefines.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2007-2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -100,9 +100,8 @@ enum RsAllocationUsageType {
RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004,
RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008,
RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010,
- RS_ALLOCATION_USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE = 0x0020,
- RS_ALLOCATION_USAGE_IO_INPUT = 0x0040,
- RS_ALLOCATION_USAGE_IO_OUTPUT = 0x0080,
+ RS_ALLOCATION_USAGE_IO_INPUT = 0x0020,
+ RS_ALLOCATION_USAGE_IO_OUTPUT = 0x0040,
RS_ALLOCATION_USAGE_ALL = 0x00FF
};