diff options
author | Alex Sakhartchouk <alexst@google.com> | 2011-05-05 16:56:27 -0700 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2011-05-05 16:56:27 -0700 |
commit | 438505431c253fd891f3deda38033c30268913e8 (patch) | |
tree | 956640c1f809f6ffaf17c434539a920b126e794a | |
parent | 19c5c7a7bc0fe7d91a3d39c10a001aed25a6f1ca (diff) | |
download | frameworks_base-438505431c253fd891f3deda38033c30268913e8.zip frameworks_base-438505431c253fd891f3deda38033c30268913e8.tar.gz frameworks_base-438505431c253fd891f3deda38033c30268913e8.tar.bz2 |
Moving samplers behind the hal.
Change-Id: I494e5a9d2b599d07b985328b346f1f10ae4972e1
-rw-r--r-- | libs/rs/Android.mk | 1 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.cpp | 8 | ||||
-rw-r--r-- | libs/rs/driver/rsdSampler.cpp | 40 | ||||
-rw-r--r-- | libs/rs/driver/rsdSampler.h | 30 | ||||
-rw-r--r-- | libs/rs/driver/rsdShader.cpp | 67 | ||||
-rw-r--r-- | libs/rs/driver/rsdShader.h | 1 | ||||
-rw-r--r-- | libs/rs/rsProgram.cpp | 6 | ||||
-rw-r--r-- | libs/rs/rsProgram.h | 14 | ||||
-rw-r--r-- | libs/rs/rsProgramBase.h | 44 | ||||
-rw-r--r-- | libs/rs/rsProgramRaster.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rsProgramRaster.h | 6 | ||||
-rw-r--r-- | libs/rs/rsProgramStore.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rsProgramStore.h | 4 | ||||
-rw-r--r-- | libs/rs/rsSampler.cpp | 70 | ||||
-rw-r--r-- | libs/rs/rsSampler.h | 3 | ||||
-rw-r--r-- | libs/rs/rs_hal.h | 7 |
16 files changed, 210 insertions, 95 deletions
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk index 232ab36..c336c0d 100644 --- a/libs/rs/Android.mk +++ b/libs/rs/Android.mk @@ -124,6 +124,7 @@ LOCAL_SRC_FILES:= \ driver/rsdProgramStore.cpp \ driver/rsdRuntimeMath.cpp \ driver/rsdRuntimeStubs.cpp \ + driver/rsdSampler.cpp \ driver/rsdShader.cpp \ driver/rsdShaderCache.cpp \ driver/rsdVertexArray.cpp diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index d5d23c7..0a5f2ec 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -22,6 +22,7 @@ #include "rsdProgramVertex.h" #include "rsdProgramFragment.h" #include "rsdMesh.h" +#include "rsdSampler.h" #include <malloc.h> #include "rsContext.h" @@ -90,7 +91,12 @@ static RsdHalFunctions FunctionTable = { rsdMeshInit, rsdMeshDraw, rsdMeshDestroy - } + }, + + { + rsdSamplerInit, + rsdSamplerDestroy + }, }; diff --git a/libs/rs/driver/rsdSampler.cpp b/libs/rs/driver/rsdSampler.cpp new file mode 100644 index 0000000..af48c61 --- /dev/null +++ b/libs/rs/driver/rsdSampler.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "rsdCore.h" +#include "rsdSampler.h" + +#include "rsContext.h" +#include "rsSampler.h" +#include "rsProgramVertex.h" +#include "rsProgramFragment.h" + +#include <GLES/gl.h> +#include <GLES/glext.h> + + +using namespace android; +using namespace android::renderscript; + +bool rsdSamplerInit(const android::renderscript::Context *, + const android::renderscript::Sampler *) { + return true; +} + +void rsdSamplerDestroy(const android::renderscript::Context *rsc, + const android::renderscript::Sampler *s) { +} diff --git a/libs/rs/driver/rsdSampler.h b/libs/rs/driver/rsdSampler.h new file mode 100644 index 0000000..3a64e9e --- /dev/null +++ b/libs/rs/driver/rsdSampler.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RSD_SAMPLER_H +#define RSD_SAMPLER_H + +#include <rs_hal.h> + + +bool rsdSamplerInit(const android::renderscript::Context *rsc, + const android::renderscript::Sampler *); + +void rsdSamplerDestroy(const android::renderscript::Context *rsc, + const android::renderscript::Sampler *); + + +#endif // RSD_SAMPLER_H diff --git a/libs/rs/driver/rsdShader.cpp b/libs/rs/driver/rsdShader.cpp index fc623d6..1710a8b 100644 --- a/libs/rs/driver/rsdShader.cpp +++ b/libs/rs/driver/rsdShader.cpp @@ -21,6 +21,7 @@ #include <rsContext.h> #include <rsProgram.h> +#include "rsdCore.h" #include "rsdShader.h" #include "rsdShaderCache.h" @@ -315,6 +316,70 @@ void RsdShader::setUniform(const Context *rsc, const Element *field, const float } } +void RsdShader::setupSampler(const Context *rsc, const Sampler *s, const Allocation *tex) { + RsdHal *dc = (RsdHal *)rsc->mHal.drv; + + GLenum trans[] = { + GL_NEAREST, //RS_SAMPLER_NEAREST, + GL_LINEAR, //RS_SAMPLER_LINEAR, + GL_LINEAR_MIPMAP_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR, + GL_REPEAT, //RS_SAMPLER_WRAP, + GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP + GL_LINEAR_MIPMAP_NEAREST, //RS_SAMPLER_LINEAR_MIP_NEAREST + }; + + GLenum transNP[] = { + GL_NEAREST, //RS_SAMPLER_NEAREST, + GL_LINEAR, //RS_SAMPLER_LINEAR, + GL_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR, + GL_CLAMP_TO_EDGE, //RS_SAMPLER_WRAP, + GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP + GL_LINEAR, //RS_SAMPLER_LINEAR_MIP_NEAREST, + }; + + // This tells us the correct texture type + GLenum target = (GLenum)tex->getGLTarget(); + + if (!dc->gl.gl.OES_texture_npot && tex->getType()->getIsNp2()) { + if (tex->getHasGraphicsMipmaps() && + (dc->gl.gl.GL_NV_texture_npot_2D_mipmap || dc->gl.gl.GL_IMG_texture_npot)) { + if (dc->gl.gl.GL_NV_texture_npot_2D_mipmap) { + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, trans[s->mHal.state.minFilter]); + } else { + switch (trans[s->mHal.state.minFilter]) { + case GL_LINEAR_MIPMAP_LINEAR: + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + break; + default: + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, trans[s->mHal.state.minFilter]); + break; + } + } + } else { + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, transNP[s->mHal.state.minFilter]); + } + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, transNP[s->mHal.state.magFilter]); + glTexParameteri(target, GL_TEXTURE_WRAP_S, transNP[s->mHal.state.wrapS]); + glTexParameteri(target, GL_TEXTURE_WRAP_T, transNP[s->mHal.state.wrapT]); + } else { + if (tex->getHasGraphicsMipmaps()) { + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, trans[s->mHal.state.minFilter]); + } else { + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, transNP[s->mHal.state.minFilter]); + } + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, trans[s->mHal.state.magFilter]); + glTexParameteri(target, GL_TEXTURE_WRAP_S, trans[s->mHal.state.wrapS]); + glTexParameteri(target, GL_TEXTURE_WRAP_T, trans[s->mHal.state.wrapT]); + } + + float anisoValue = rsMin(dc->gl.gl.EXT_texture_max_aniso, s->mHal.state.aniso); + if (dc->gl.gl.EXT_texture_max_aniso > 1.0f) { + glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoValue); + } + + rsc->checkError("Sampler::setupGL2 tex env"); +} + void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) { if (mRSProgram->mHal.state.texturesCount == 0) { return; @@ -345,7 +410,7 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) { glBindTexture(target, mRSProgram->mHal.state.textures[ct]->getTextureID()); rsc->checkError("ProgramFragment::setupGL2 tex bind"); if (mRSProgram->mHal.state.samplers[ct].get()) { - mRSProgram->mHal.state.samplers[ct]->setupGL(rsc, mRSProgram->mHal.state.textures[ct].get()); + setupSampler(rsc, mRSProgram->mHal.state.samplers[ct].get(), mRSProgram->mHal.state.textures[ct].get()); } else { glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); diff --git a/libs/rs/driver/rsdShader.h b/libs/rs/driver/rsdShader.h index 37b1c3d..63c4231 100644 --- a/libs/rs/driver/rsdShader.h +++ b/libs/rs/driver/rsdShader.h @@ -70,6 +70,7 @@ protected: void setupUserConstants(const android::renderscript::Context *rsc, RsdShaderCache *sc, bool isFragment); void initAddUserElement(const android::renderscript::Element *e, android::String8 *names, uint32_t *arrayLengths, uint32_t *count, const char *prefix); void setupTextures(const android::renderscript::Context *rsc, RsdShaderCache *sc); + void setupSampler(const android::renderscript::Context *rsc, const android::renderscript::Sampler *s, const android::renderscript::Allocation *tex); void appendAttributes(); void appendTextures(); diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp index c0fa95b..b1d8f48 100644 --- a/libs/rs/rsProgram.cpp +++ b/libs/rs/rsProgram.cpp @@ -20,13 +20,9 @@ using namespace android; using namespace android::renderscript; -Program::Program(Context *rsc) : ObjectBase(rsc) { - initMemberVars(); -} - Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, const uint32_t * params, uint32_t paramLength) - : ObjectBase(rsc) { + : ProgramBase(rsc) { initMemberVars(); for (uint32_t ct=0; ct < paramLength; ct+=2) { diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h index 2922270..948ba3e 100644 --- a/libs/rs/rsProgram.h +++ b/libs/rs/rsProgram.h @@ -17,7 +17,7 @@ #ifndef ANDROID_RS_PROGRAM_H #define ANDROID_RS_PROGRAM_H -#include "rsObjectBase.h" +#include "rsProgramBase.h" #include "rsElement.h" // --------------------------------------------------------------------------- @@ -28,10 +28,9 @@ namespace renderscript { #define RS_SHADER_ATTR "ATTRIB_" #define RS_SHADER_UNI "UNI_" -class Program : public ObjectBase { +class Program : public ProgramBase { public: - Program(Context *); Program(Context *, const char * shaderText, uint32_t shaderLength, const uint32_t * params, uint32_t paramLength); virtual ~Program(); @@ -43,8 +42,6 @@ public: void bindTexture(Context *, uint32_t slot, Allocation *); void bindSampler(Context *, uint32_t slot, Sampler *); - void forceDirty() const {mDirty = true;} - struct Hal { mutable void *drv; @@ -75,18 +72,13 @@ public: protected: bool mIsInternal; - - mutable bool mDirty; String8 mUserShader; - - void logUniform(const Element *field, const float *fd, uint32_t arraySize ); - void setUniform(Context *rsc, const Element *field, const float *fd, int32_t slot, uint32_t arraySize ); void initMemberVars(); }; } } -#endif +#endif // ANDROID_RS_PROGRAM_H diff --git a/libs/rs/rsProgramBase.h b/libs/rs/rsProgramBase.h new file mode 100644 index 0000000..80da453 --- /dev/null +++ b/libs/rs/rsProgramBase.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_RS_PROGRAM_BASE_H +#define ANDROID_RS_PROGRAM_BASE_H + +#include "rsObjectBase.h" +#include "rsElement.h" + +// --------------------------------------------------------------------------- +namespace android { +namespace renderscript { + +class ProgramBase : public ObjectBase { +public: + ProgramBase(Context *rsc) : ObjectBase(rsc) { + mDirty = true; + } + + void forceDirty() const {mDirty = true;} + +protected: + mutable bool mDirty; +}; + +} +} +#endif // ANDROID_RS_PROGRAM_BASE_H + + + diff --git a/libs/rs/rsProgramRaster.cpp b/libs/rs/rsProgramRaster.cpp index 9617c4d..435561d 100644 --- a/libs/rs/rsProgramRaster.cpp +++ b/libs/rs/rsProgramRaster.cpp @@ -24,7 +24,7 @@ using namespace android::renderscript; ProgramRaster::ProgramRaster(Context *rsc, bool pointSmooth, bool lineSmooth, bool pointSprite, float lineWidth, RsCullMode cull) - : Program(rsc) { + : ProgramBase(rsc) { memset(&mHal, 0, sizeof(mHal)); diff --git a/libs/rs/rsProgramRaster.h b/libs/rs/rsProgramRaster.h index 045a7c1..efdb948 100644 --- a/libs/rs/rsProgramRaster.h +++ b/libs/rs/rsProgramRaster.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2009-2011 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. @@ -17,7 +17,7 @@ #ifndef ANDROID_RS_PROGRAM_RASTER_H #define ANDROID_RS_PROGRAM_RASTER_H -#include "rsProgram.h" +#include "rsProgramBase.h" // --------------------------------------------------------------------------- namespace android { @@ -25,7 +25,7 @@ namespace renderscript { class ProgramRasterState; -class ProgramRaster : public Program { +class ProgramRaster : public ProgramBase { public: ProgramRaster(Context *rsc, bool pointSmooth, diff --git a/libs/rs/rsProgramStore.cpp b/libs/rs/rsProgramStore.cpp index 2ad65e9..8fe890b 100644 --- a/libs/rs/rsProgramStore.cpp +++ b/libs/rs/rsProgramStore.cpp @@ -25,7 +25,7 @@ ProgramStore::ProgramStore(Context *rsc, bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA, bool depthMask, bool ditherEnable, RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, - RsDepthFunc depthFunc) : Program(rsc) { + RsDepthFunc depthFunc) : ProgramBase(rsc) { memset(&mHal, 0, sizeof(mHal)); mHal.state.ditherEnable = ditherEnable; diff --git a/libs/rs/rsProgramStore.h b/libs/rs/rsProgramStore.h index 88a06a8..77b3881 100644 --- a/libs/rs/rsProgramStore.h +++ b/libs/rs/rsProgramStore.h @@ -17,7 +17,7 @@ #ifndef ANDROID_RS_PROGRAM_FRAGMENT_STORE_H #define ANDROID_RS_PROGRAM_FRAGMENT_STORE_H -#include "rsProgram.h" +#include "rsProgramBase.h" #include "rsStream.h" // --------------------------------------------------------------------------- @@ -26,7 +26,7 @@ namespace renderscript { class ProgramStoreState; -class ProgramStore : public Program { +class ProgramStore : public ProgramBase { public: ProgramStore(Context *, bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA, diff --git a/libs/rs/rsSampler.cpp b/libs/rs/rsSampler.cpp index 670d07e..2a05d16 100644 --- a/libs/rs/rsSampler.cpp +++ b/libs/rs/rsSampler.cpp @@ -15,11 +15,6 @@ */ #include "rsContext.h" -#ifndef ANDROID_RS_SERIALIZE -#include <GLES/gl.h> -#include <GLES/glext.h> -#endif //ANDROID_RS_SERIALIZE - #include "rsSampler.h" @@ -45,71 +40,12 @@ Sampler::Sampler(Context *rsc, mHal.state.wrapT = wrapT; mHal.state.wrapR = wrapR; mHal.state.aniso = aniso; -} -Sampler::~Sampler() { + mRSC->mHal.funcs.sampler.init(mRSC, this); } -void Sampler::setupGL(const Context *rsc, const Allocation *tex) { - GLenum trans[] = { - GL_NEAREST, //RS_SAMPLER_NEAREST, - GL_LINEAR, //RS_SAMPLER_LINEAR, - GL_LINEAR_MIPMAP_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR, - GL_REPEAT, //RS_SAMPLER_WRAP, - GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP - GL_LINEAR_MIPMAP_NEAREST, //RS_SAMPLER_LINEAR_MIP_NEAREST - }; - - GLenum transNP[] = { - GL_NEAREST, //RS_SAMPLER_NEAREST, - GL_LINEAR, //RS_SAMPLER_LINEAR, - GL_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR, - GL_CLAMP_TO_EDGE, //RS_SAMPLER_WRAP, - GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP - GL_LINEAR, //RS_SAMPLER_LINEAR_MIP_NEAREST, - }; - - // This tells us the correct texture type - GLenum target = (GLenum)tex->getGLTarget(); - - if (!rsc->ext_OES_texture_npot() && tex->getType()->getIsNp2()) { - if (tex->getHasGraphicsMipmaps() && - (rsc->ext_GL_NV_texture_npot_2D_mipmap() || rsc->ext_GL_IMG_texture_npot())) { - if (rsc->ext_GL_NV_texture_npot_2D_mipmap()) { - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, trans[mHal.state.minFilter]); - } else { - switch (trans[mHal.state.minFilter]) { - case GL_LINEAR_MIPMAP_LINEAR: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - break; - default: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, trans[mHal.state.minFilter]); - break; - } - } - } else { - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, transNP[mHal.state.minFilter]); - } - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, transNP[mHal.state.magFilter]); - glTexParameteri(target, GL_TEXTURE_WRAP_S, transNP[mHal.state.wrapS]); - glTexParameteri(target, GL_TEXTURE_WRAP_T, transNP[mHal.state.wrapT]); - } else { - if (tex->getHasGraphicsMipmaps()) { - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, trans[mHal.state.minFilter]); - } else { - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, transNP[mHal.state.minFilter]); - } - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, trans[mHal.state.magFilter]); - glTexParameteri(target, GL_TEXTURE_WRAP_S, trans[mHal.state.wrapS]); - glTexParameteri(target, GL_TEXTURE_WRAP_T, trans[mHal.state.wrapT]); - } - - float anisoValue = rsMin(rsc->ext_texture_max_aniso(), mHal.state.aniso); - if (rsc->ext_texture_max_aniso() > 1.0f) { - glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoValue); - } - - rsc->checkError("Sampler::setupGL2 tex env"); +Sampler::~Sampler() { + mRSC->mHal.funcs.sampler.destroy(mRSC, this); } void Sampler::bindToContext(SamplerState *ss, uint32_t slot) { diff --git a/libs/rs/rsSampler.h b/libs/rs/rsSampler.h index 192ee07..90b6082 100644 --- a/libs/rs/rsSampler.h +++ b/libs/rs/rsSampler.h @@ -40,9 +40,6 @@ public: virtual ~Sampler(); - void bind(Allocation *); - void setupGL(const Context *, const Allocation *); - void bindToContext(SamplerState *, uint32_t slot); void unbindFromContext(SamplerState *); diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h index d2f273b..4cc2abf 100644 --- a/libs/rs/rs_hal.h +++ b/libs/rs/rs_hal.h @@ -30,11 +30,13 @@ class Type; class Allocation; class Script; class ScriptC; +class Program; class ProgramStore; class ProgramRaster; class ProgramVertex; class ProgramFragment; class Mesh; +class Sampler; typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); @@ -121,6 +123,11 @@ typedef struct { void (*destroy)(const Context *rsc, const Mesh *m); } mesh; + struct { + bool (*init)(const Context *rsc, const Sampler *m); + void (*destroy)(const Context *rsc, const Sampler *m); + } sampler; + } RsdHalFunctions; |