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

Commit 5b7e333c authored by Alex Sakhartchouk's avatar Alex Sakhartchouk Committed by Android (Google) Code Review
Browse files

Merge "Adding freetype font rendering to renderscript."

parents c086d940 9b949fce
Loading
Loading
Loading
Loading
+15 −0
Original line number Original line Diff line number Diff line
@@ -386,6 +386,21 @@ public class Allocation extends BaseObj {
        Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions);
        Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions);
        return createFromBitmapBoxed(rs, b, dstFmt, genMips);
        return createFromBitmapBoxed(rs, b, dstFmt, genMips);
    }
    }

    static public Allocation createFromString(RenderScript rs, String str)
        throws IllegalArgumentException {
        byte[] allocArray = null;
        try {
            allocArray = str.getBytes("UTF-8");
            Allocation alloc = Allocation.createSized(rs, Element.U8(rs), allocArray.length);
            alloc.data(allocArray);
            return alloc;
        }
        catch (Exception e) {
            Log.e("rs", "could not convert string to utf-8");
        }
        return null;
    }
}
}


+59 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2008 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.
 */

package android.renderscript;

import java.io.IOException;
import java.io.InputStream;

import android.content.res.Resources;
import android.content.res.AssetManager;
import android.util.Log;
import android.util.TypedValue;

/**
 * @hide
 *
 **/
public class Font extends BaseObj {

    Font(int id, RenderScript rs) {
        super(rs);
        mID = id;
    }

    static public Font create(RenderScript rs, Resources res, String fileName, int size)
        throws IllegalArgumentException {

        rs.validate();
        try {
            int dpi = res.getDisplayMetrics().densityDpi;
            int fontId = rs.nFontCreateFromFile(fileName, size, dpi);

            if(fontId == 0) {
                throw new IllegalStateException("Load loading a font");
            }
            Font rsFont = new Font(fontId, rs);

            return rsFont;

        } catch (Exception e) {
            // Ignore
        }

        return null;
    }
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -123,6 +123,8 @@ public class RenderScript {
    native void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names);
    native void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names);
    native int  nFileA3DGetEntryByIndex(int fileA3D, int index);
    native int  nFileA3DGetEntryByIndex(int fileA3D, int index);


    native int  nFontCreateFromFile(String fileName, int size, int dpi);

    native void nAdapter1DBindAllocation(int ad, int alloc);
    native void nAdapter1DBindAllocation(int ad, int alloc);
    native void nAdapter1DSetConstraint(int ad, int dim, int value);
    native void nAdapter1DSetConstraint(int ad, int dim, int value);
    native void nAdapter1DData(int ad, int[] d);
    native void nAdapter1DData(int ad, int[] d);
+19 −5
Original line number Original line Diff line number Diff line
@@ -762,6 +762,19 @@ nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jint fileA3D, jint index)
    return id;
    return id;
}
}


// -----------------------------------

static int
nFontCreateFromFile(JNIEnv *_env, jobject _this, jstring fileName, jint fontSize, jint dpi)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    const char* fileNameUTF = _env->GetStringUTFChars(fileName, NULL);

    jint id = (jint)rsFontCreateFromFile(con, fileNameUTF, fontSize, dpi);
    return id;
}


// -----------------------------------
// -----------------------------------


static void
static void
@@ -1395,6 +1408,12 @@ static JNINativeMethod methods[] = {
{"nContextDeinitToClient",         "()V",                                  (void*)nContextDeinitToClient },
{"nContextDeinitToClient",         "()V",                                  (void*)nContextDeinitToClient },


{"nFileOpen",                      "([B)I",                                (void*)nFileOpen },
{"nFileOpen",                      "([B)I",                                (void*)nFileOpen },
{"nFileA3DCreateFromAssetStream", "(I)I",                                 (void*)nFileA3DCreateFromAssetStream },
{"nFileA3DGetNumIndexEntries",     "(I)I",                                 (void*)nFileA3DGetNumIndexEntries },
{"nFileA3DGetIndexEntries",        "(II[I[Ljava/lang/String;)V",          (void*)nFileA3DGetIndexEntries },
{"nFileA3DGetEntryByIndex",        "(II)I",                                (void*)nFileA3DGetEntryByIndex },

{"nFontCreateFromFile",           "(Ljava/lang/String;II)I",             (void*)nFontCreateFromFile },


{"nElementCreate",                 "(IIZI)I",                              (void*)nElementCreate },
{"nElementCreate",                 "(IIZI)I",                              (void*)nElementCreate },
{"nElementCreate2",                "([I[Ljava/lang/String;)I",             (void*)nElementCreate2 },
{"nElementCreate2",                "([I[Ljava/lang/String;)I",             (void*)nElementCreate2 },
@@ -1494,11 +1513,6 @@ static JNINativeMethod methods[] = {
{"nSimpleMeshBindVertex",          "(III)V",                               (void*)nSimpleMeshBindVertex },
{"nSimpleMeshBindVertex",          "(III)V",                               (void*)nSimpleMeshBindVertex },
{"nSimpleMeshBindIndex",           "(II)V",                                (void*)nSimpleMeshBindIndex },
{"nSimpleMeshBindIndex",           "(II)V",                                (void*)nSimpleMeshBindIndex },


{"nFileA3DCreateFromAssetStream", "(I)I",                                 (void*)nFileA3DCreateFromAssetStream },
{"nFileA3DGetNumIndexEntries",     "(I)I",                                 (void*)nFileA3DGetNumIndexEntries },
{"nFileA3DGetIndexEntries",        "(II[I[Ljava/lang/String;)V",          (void*)nFileA3DGetIndexEntries },
{"nFileA3DGetEntryByIndex",        "(II)I",                                (void*)nFileA3DGetEntryByIndex },

};
};


static int registerFuncs(JNIEnv *_env)
static int registerFuncs(JNIEnv *_env)
+11 −5
Original line number Original line Diff line number Diff line
@@ -82,6 +82,7 @@ LOCAL_SRC_FILES:= \
	rsDevice.cpp \
	rsDevice.cpp \
	rsElement.cpp \
	rsElement.cpp \
	rsFileA3D.cpp \
	rsFileA3D.cpp \
	rsFont.cpp \
	rsLight.cpp \
	rsLight.cpp \
	rsLocklessFifo.cpp \
	rsLocklessFifo.cpp \
	rsObjectBase.cpp \
	rsObjectBase.cpp \
@@ -109,6 +110,11 @@ LOCAL_SRC_FILES:= \




LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libbcc
LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libbcc

LOCAL_STATIC_LIBRARIES := libft2

LOCAL_C_INCLUDES += external/freetype/include

LOCAL_LDLIBS := -lpthread -ldl
LOCAL_LDLIBS := -lpthread -ldl
LOCAL_MODULE:= libRS
LOCAL_MODULE:= libRS
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_TAGS := optional
Loading