Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aaafa4fb authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 2362

* changes:
  Add the Renderscript library. (Not in the build by default yet.)
parents 22075a3b d19f10d4
Loading
Loading
Loading
Loading

libs/rs/Android.mk

0 → 100644
+132 −0
Original line number Diff line number Diff line
# Only build if BUILD_RENDERSCRIPT is defined to true in the environment.
ifeq ($(BUILD_RENDERSCRIPT),true)

TOP_LOCAL_PATH:=$(call my-dir)
LOCAL_PATH:= $(TOP_LOCAL_PATH)


# Build rsg-generator

LOCAL_MODULE := rsg-generator

# These symbols are normally defined by BUILD_XXX, but we need to define them
# here so that local-intermediates-dir works.

LOCAL_IS_HOST_MODULE := true
LOCAL_MODULE_CLASS := EXECUTABLES
intermediates:= $(local-intermediates-dir)

GEN := $(addprefix $(intermediates)/, \
            lex.yy.c \
        )
$(GEN):	PRIVATE_CUSTOM_TOOL = flex -o $@ $<

$(intermediates)/lex.yy.c : $(LOCAL_PATH)/spec.lex
	$(transform-generated-source)

$(LOCAL_PATH)/rsg_generator.c : $(intermediates)/lex.yy.c

LOCAL_SRC_FILES:= \
    rsg_generator.c
	
include $(BUILD_HOST_EXECUTABLE)

RSG_GENERATOR:=$(LOCAL_BUILT_MODULE)

# Build render script lib

include $(CLEAR_VARS)
LOCAL_MODULE := libRS

LOCAL_MODULE_CLASS := SHARED_LIBRARIES
intermediates:= $(local-intermediates-dir)

RS_GENERATED_INCLUDE_DIR:=$(intermediates)

# Generate custom headers

GEN := $(addprefix $(intermediates)/, \
            rsgApiStructs.h \
            rsgApiFuncDecl.h \
        )

$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(LOCAL_PATH)/rs.spec
$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec
$(GEN): $(intermediates)/%.h : $(LOCAL_PATH)/%.h.rsg
	$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)

# Generate custom source files

GEN := $(addprefix $(intermediates)/, \
            rsgApi.cpp \
            rsgApiReplay.cpp \
        )
        
$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(LOCAL_PATH)/rs.spec
$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec
$(GEN): $(intermediates)/%.cpp : $(LOCAL_PATH)/%.cpp.rsg
	$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)

LOCAL_SRC_FILES:= \
	rsAdapter.cpp \
	rsAllocation.cpp \
	rsComponent.cpp \
	rsContext.cpp \
	rsDevice.cpp \
	rsElement.cpp \
	rsLocklessFifo.cpp \
	rsObjectBase.cpp \
	rsMatrix.cpp \
	rsProgram.cpp \
	rsProgramFragment.cpp \
	rsProgramFragmentStore.cpp \
	rsProgramVertex.cpp \
	rsSampler.cpp \
	rsScript.cpp \
	rsScriptC.cpp \
	rsThreadIO.cpp \
	rsType.cpp \
	rsTriangleMesh.cpp

LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libui 
LOCAL_LDLIBS := -lpthread -ldl
LOCAL_MODULE:= libRS

#LOCAL_MODULE_TAGS := tests

include $(BUILD_SHARED_LIBRARY)

# Build JNI library

LOCAL_PATH:= $(TOP_LOCAL_PATH)/jni
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
	RenderScript_jni.cpp

LOCAL_SHARED_LIBRARIES := \
	libandroid_runtime \
	libnativehelper \
	libRS \
	libcutils \
	libutils \
	libui

LOCAL_STATIC_LIBRARIES :=

LOCAL_C_INCLUDES += \
	$(JNI_H_INCLUDE) \
	$(RS_GENERATED_INCLUDE_DIR) \
	$(call include-path-for, corecg graphics)

LOCAL_CFLAGS +=

LOCAL_LDLIBS := -lpthread

LOCAL_MODULE:= libRS_jni

include $(BUILD_SHARED_LIBRARY)

endif # BUILD_RENDERSCRIPT
 No newline at end of file

libs/rs/RenderScript.h

0 → 100644
+185 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 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 RENDER_SCRIPT_H
#define RENDER_SCRIPT_H

#include <stdint.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

//////////////////////////////////////////////////////
// 

typedef void * RsAdapter1D;
typedef void * RsAdapter2D;
typedef void * RsAllocation;
typedef void * RsContext;
typedef void * RsDevice;
typedef void * RsElement;
typedef void * RsSampler;
typedef void * RsScript;
typedef void * RsScriptBasicTemp;
typedef void * RsTriangleMesh;
typedef void * RsType;

typedef void * RsProgramVertex;
typedef void * RsProgramFragment;
typedef void * RsProgramFragmentStore;

RsDevice rsDeviceCreate();
void rsDeviceDestroy(RsDevice);

RsContext rsContextCreate(RsDevice, void *, uint32_t version);
void rsContextDestroy(RsContext);

enum RsDataType {
    RS_TYPE_FLOAT,
    RS_TYPE_UNSIGNED,
    RS_TYPE_SIGNED
};

enum RsDataKind {
    RS_KIND_USER,
    RS_KIND_RED, 
    RS_KIND_GREEN, 
    RS_KIND_BLUE, 
    RS_KIND_ALPHA, 
    RS_KIND_LUMINANCE, 
    RS_KIND_INTENSITY,
    RS_KIND_X, 
    RS_KIND_Y, 
    RS_KIND_Z, 
    RS_KIND_W,
    RS_KIND_S, 
    RS_KIND_T, 
    RS_KIND_Q, 
    RS_KIND_R,
    RS_KIND_NX, 
    RS_KIND_NY, 
    RS_KIND_NZ,
    RS_KIND_INDEX
};

enum RsElementPredefined {
    RS_ELEMENT_USER_U8,
    RS_ELEMENT_USER_I8,
    RS_ELEMENT_USER_U16,
    RS_ELEMENT_USER_I16,
    RS_ELEMENT_USER_U32,
    RS_ELEMENT_USER_I32,
    RS_ELEMENT_USER_FLOAT, 

    RS_ELEMENT_RGB_565, 
    RS_ELEMENT_RGBA_5551, 
    RS_ELEMENT_RGBA_4444, 
    RS_ELEMENT_RGB_888, 
    RS_ELEMENT_RGBA_8888, 

    RS_ELEMENT_INDEX_16, 
    RS_ELEMENT_INDEX_32, 
    RS_ELEMENT_XY_F32, 
    RS_ELEMENT_XYZ_F32, 
    RS_ELEMENT_ST_XY_F32, 
    RS_ELEMENT_ST_XYZ_F32, 
    RS_ELEMENT_NORM_XYZ_F32,
    RS_ELEMENT_NORM_ST_XYZ_F32,
};  

enum RsSamplerParam {
    RS_SAMPLER_MIN_FILTER,
    RS_SAMPLER_MAG_FILTER,
    RS_SAMPLER_WRAP_S,
    RS_SAMPLER_WRAP_T,
    RS_SAMPLER_WRAP_R
};  

enum RsSamplerValue {
    RS_SAMPLER_NEAREST,
    RS_SAMPLER_LINEAR,
    RS_SAMPLER_LINEAR_MIP_LINEAR,
    RS_SAMPLER_WRAP,
    RS_SAMPLER_CLAMP
};  

enum RsDimension {
    RS_DIMENSION_X,
    RS_DIMENSION_Y,
    RS_DIMENSION_Z,
    RS_DIMENSION_LOD,
    RS_DIMENSION_FACE,

    RS_DIMENSION_ARRAY_0 = 100, 
    RS_DIMENSION_ARRAY_1, 
    RS_DIMENSION_ARRAY_2, 
    RS_DIMENSION_ARRAY_3,
    RS_DIMENSION_MAX = RS_DIMENSION_ARRAY_3
};

enum RsDepthFunc {
    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
};

enum RsBlendSrcFunc {
    RS_BLEND_SRC_ZERO, 
    RS_BLEND_SRC_ONE, 
    RS_BLEND_SRC_DST_COLOR, 
    RS_BLEND_SRC_ONE_MINUS_DST_COLOR, 
    RS_BLEND_SRC_SRC_ALPHA, 
    RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA, 
    RS_BLEND_SRC_DST_ALPHA, 
    RS_BLEND_SRC_ONE_MINUS_DST_ALPHA, 
    RS_BLEND_SRC_SRC_ALPHA_SATURATE
};

enum RsBlendDstFunc {
    RS_BLEND_DST_ZERO, 
    RS_BLEND_DST_ONE, 
    RS_BLEND_DST_SRC_COLOR, 
    RS_BLEND_DST_ONE_MINUS_SRC_COLOR, 
    RS_BLEND_DST_SRC_ALPHA, 
    RS_BLEND_DST_ONE_MINUS_SRC_ALPHA, 
    RS_BLEND_DST_DST_ALPHA, 
    RS_BLEND_DST_ONE_MINUS_DST_ALPHA
};

enum RsTexEnvMode {
    RS_TEX_ENV_MODE_REPLACE,
    RS_TEX_ENV_MODE_MODULATE,
    RS_TEX_ENV_MODE_DECAL
};



#include "rsgApiFuncDecl.h"

#ifdef __cplusplus
};
#endif

#endif // RENDER_SCRIPT_H


+93 −0
Original line number Diff line number Diff line
#include <stdint.h>


typedef void * RsAdapter1D;
typedef void * RsAdapter2D;
typedef void * RsAllocation;
typedef void * RsContext;
typedef void * RsDevice;
typedef void * RsElement;
typedef void * RsSampler;
typedef void * RsScript;
typedef void * RsScriptBasicTemp;
typedef void * RsTriangleMesh;
typedef void * RsType;
typedef void * RsProgramFragment;
typedef void * RsProgramFragmentStore;


typedef struct {
    float m[16];
} rsc_Matrix;


typedef struct {
    float v[4];
} rsc_Vector4;

#define RS_PROGRAM_VERTEX_MODELVIEW_OFFSET 0
#define RS_PROGRAM_VERTEX_PROJECTION_OFFSET 16
#define RS_PROGRAM_VERTEX_TEXTURE_OFFSET 32

typedef struct {
    const void * (*loadEnvVp)(void *con, uint32_t bank, uint32_t offset);

    float (*loadEnvF)(void *con, uint32_t bank, uint32_t offset);
    int32_t (*loadEnvI32)(void *con, uint32_t bank, uint32_t offset);
    uint32_t (*loadEnvU32)(void *con, uint32_t bank, uint32_t offset);
    void (*loadEnvVec4)(void *con, uint32_t bank, uint32_t offset, rsc_Vector4 *);
    void (*loadEnvMatrix)(void *con, uint32_t bank, uint32_t offset, rsc_Matrix *);

    void (*storeEnvF)(void *con, uint32_t bank, uint32_t offset, float);
    void (*storeEnvI32)(void *con, uint32_t bank, uint32_t offset, int32_t);
    void (*storeEnvU32)(void *con, uint32_t bank, uint32_t offset, uint32_t);
    void (*storeEnvVec4)(void *con, uint32_t bank, uint32_t offset, const rsc_Vector4 *);
    void (*storeEnvMatrix)(void *con, uint32_t bank, uint32_t offset, const rsc_Matrix *);

    void (*matrixLoadIdentity)(void *con, rsc_Matrix *);
    void (*matrixLoadFloat)(void *con, rsc_Matrix *, const float *);
    void (*matrixLoadMat)(void *con, rsc_Matrix *, const rsc_Matrix *);
    void (*matrixLoadRotate)(void *con, rsc_Matrix *, float rot, float x, float y, float z);
    void (*matrixLoadScale)(void *con, rsc_Matrix *, float x, float y, float z);
    void (*matrixLoadTranslate)(void *con, rsc_Matrix *, float x, float y, float z);
    void (*matrixLoadMultiply)(void *con, rsc_Matrix *, const rsc_Matrix *lhs, const rsc_Matrix *rhs);
    void (*matrixMultiply)(void *con, rsc_Matrix *, const rsc_Matrix *rhs);
    void (*matrixRotate)(void *con, rsc_Matrix *, float rot, float x, float y, float z);
    void (*matrixScale)(void *con, rsc_Matrix *, float x, float y, float z);
    void (*matrixTranslate)(void *con, rsc_Matrix *, float x, float y, float z);

    void (*color)(void *con, float r, float g, float b, float a);

    void (*renderTriangleMesh)(void *con, RsTriangleMesh);
    void (*renderTriangleMeshRange)(void *con, RsTriangleMesh, uint32_t start, uint32_t count);

    void (*programFragmentBindTexture)(void *con, RsProgramFragment, uint32_t slot, RsAllocation);
    void (*programFragmentBindSampler)(void *con, RsProgramFragment, uint32_t slot, RsAllocation);
    
    void (*materialDiffuse)(void *con, float r, float g, float b, float a);
    void (*materialSpecular)(void *con, float r, float g, float b, float a);
    void (*lightPosition)(void *con, float x, float y, float z, float w);
    void (*materialShininess)(void *con, float s);

    void (*uploadToTexture)(void *con, RsAllocation va, uint32_t baseMipLevel);

    void (*enable)(void *con, uint32_t);
    void (*disable)(void *con, uint32_t);

    uint32_t (*rand)(void *con, uint32_t max);

    // Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a
    void (*drawTriangleArray)(void *con, RsAllocation alloc, uint32_t count);

    void (*contextBindProgramFragment)(void *con, RsProgramFragment pf);
    void (*contextBindProgramFragmentStore)(void *con, RsProgramFragmentStore pfs);
} rsc_FunctionTable;

typedef void (*rsc_RunScript)(void *con, const rsc_FunctionTable *, uint32_t launchID);


/* EnableCap */
#define GL_LIGHTING                       0x0B50

/* LightName */
#define GL_LIGHT0                         0x4000
+897 −0

File added.

Preview size limit exceeded, changes collapsed.

libs/rs/rs.spec

0 → 100644
+392 −0
Original line number Diff line number Diff line


ContextBindSampler {
	param uint32_t slot
	param RsSampler sampler
	}

ContextBindRootScript {
	param RsScript sampler
	}

ContextBindProgramFragmentStore {
	param RsProgramFragmentStore pgm
	}

ContextBindProgramFragment {
	param RsProgramFragment pgm
	}

ContextBindProgramVertex {
	param RsProgramVertex pgm
	}


ElementBegin {
}

ElementAddPredefined {
	param RsElementPredefined predef
	}

ElementAdd {
	param RsDataKind dataKind
	param RsDataType dataType
	param bool isNormalized
	param size_t bits
	}

ElementCreate {
	ret RsElement
	}

ElementGetPredefined {
	param RsElementPredefined predef
	ret RsElement
	}

ElementDestroy {
	param RsElement ve
	}

TypeBegin {
	param RsElement type
	}

TypeAdd {
	param RsDimension dim
	param size_t value
	}

TypeCreate {
	ret RsType
	}

TypeDestroy {
	param RsType p
	}

AllocationCreateTyped {
	param RsType type
	ret RsAllocation
	}

AllocationCreatePredefSized {
	param RsElementPredefined predef
	param size_t count
	ret RsAllocation
	}

AllocationCreateSized {
	param RsElement e
	param size_t count
	ret RsAllocation
	}

AllocationCreateFromBitmap {
	param const char *file
	param bool genMips
	ret RsAllocation
	}

AllocationUploadToTexture {
	param RsAllocation alloc
	param uint32_t baseMipLevel
	}

AllocationUploadToBufferObject {
	param RsAllocation alloc
	}

AllocationDestroy {
	param RsAllocation alloc
	}


AllocationData {
	param RsAllocation va
	param const void * data
	} 

Allocation1DSubData {
	param RsAllocation va
	param uint32_t xoff
	param uint32_t count
	param const void *data
	} 

Allocation2DSubData {
	param RsAllocation va
	param uint32_t xoff
	param uint32_t yoff
	param uint32_t w
	param uint32_t h
	param const void *data
	}


Adapter1DCreate {
	ret RsAdapter1D
	}

Adapter1DBindAllocation {
	param RsAdapter1D adapt
	param RsAllocation alloc
	}

Adapter1DDestroy {
	param RsAdapter1D adapter
	}

Adapter1DSetConstraint {
	param RsAdapter1D adapter
	param RsDimension dim
	param uint32_t value
	}

Adapter1DData {
	param RsAdapter1D adapter
	param const void * data
	} 

Adapter1DSubData {
	param RsAdapter1D adapter
	param uint32_t xoff
	param uint32_t count
	param const void *data
	} 

Adapter2DCreate {
	ret RsAdapter2D
	}

Adapter2DBindAllocation {
	param RsAdapter2D adapt
	param RsAllocation alloc
	}

Adapter2DDestroy {
	param RsAdapter2D adapter
	}

Adapter2DSetConstraint {
	param RsAdapter2D adapter
	param RsDimension dim
	param uint32_t value
	}

Adapter2DData {
	param RsAdapter2D adapter
	param const void *data
	} 

Adapter2DSubData {
	param RsAdapter2D adapter
	param uint32_t xoff
	param uint32_t yoff
	param uint32_t w
	param uint32_t h
	param const void *data
	}

SamplerBegin {
	}

SamplerSet {
	param RsSamplerParam p
	param RsSamplerValue value
	}

SamplerCreate {
	ret RsSampler
	}


TriangleMeshBegin {
	param RsElement vertex
	param RsElement index
	}

TriangleMeshAddVertex {
	param const void *vtx
	}

TriangleMeshAddTriangle {
	param uint32_t idx1
	param uint32_t idx2
	param uint32_t idx3
	}

TriangleMeshCreate {
	ret RsTriangleMesh
	}

TriangleMeshDestroy {
	param RsTriangleMesh mesh
	}

TriangleMeshRender {
	param RsTriangleMesh vtm
	}

TriangleMeshRenderRange {
	param RsTriangleMesh vtm
	param uint32_t start
	param uint32_t count
	}

ScriptDestroy {
	param RsScript script
	}

ScriptBindAllocation {
	param RsScript vtm
	param RsAllocation va
	param uint32_t slot
	}


ScriptCBegin {
	}

ScriptCSetClearColor {
	param float r
	param float g
	param float b
	param float a
	}

ScriptCSetClearDepth {
	param float depth
	}

ScriptCSetClearStencil {
	param uint32_t stencil
	}

ScriptCAddType {
	param RsType type
	}

ScriptCSetRoot {
	param bool isRoot
	}

ScriptCSetOrtho {
	param bool isOrtho
	}

ScriptCSetScript {
	param void * ptr
	}

ScriptCCreate {
	ret RsScript
	}


ProgramFragmentStoreBegin {
	param RsElement in
	param RsElement out
	}

ProgramFragmentStoreColorMask {
	param bool r
	param bool g
	param bool b
	param bool a
	}

ProgramFragmentStoreBlendFunc {
	param RsBlendSrcFunc srcFunc
	param RsBlendDstFunc destFunc
	}

ProgramFragmentStoreDepthMask {
	param bool enable
}

ProgramFragmentStoreDither {
	param bool enable
}

ProgramFragmentStoreDepthFunc {
	param RsDepthFunc func
}

ProgramFragmentStoreCreate {
	ret RsProgramFragmentStore
	}



ProgramFragmentBegin {
	param RsElement in
	param RsElement out
	}

ProgramFragmentBindTexture {
	param RsProgramFragment pf
	param uint32_t slot
	param RsAllocation a
	}

ProgramFragmentBindSampler {
	param RsProgramFragment pf
	param uint32_t slot
	param RsSampler s
	}

ProgramFragmentSetType {
	param uint32_t slot
	param RsType t
	}

ProgramFragmentSetEnvMode {
	param uint32_t slot
	param RsTexEnvMode env
	}

ProgramFragmentSetTexEnable {
	param uint32_t slot
	param bool enable
	}

ProgramFragmentCreate {
	ret RsProgramFragment
	}



ProgramVertexBegin {
	param RsElement in
	param RsElement out
	}

ProgramVertexCreate {
	ret RsProgramVertex
	}

ProgramVertexBindAllocation {
	param RsProgramVertex vpgm
	param uint32_t slot
	param RsAllocation constants
	}

ProgramVertexSetType {
	param uint32_t slot
	param RsType constants
	}

ProgramVertexSetCameraMode {
	param bool ortho
	}

ProgramVertexSetTextureMatrixEnable {
	param bool enable
	}

ProgramVertexSetModelMatrixEnable {
	param bool enable
	}
Loading