Remove dependencies on headers outside UI module
This includes AndroidRuntime and core_jni_helper.h Bug: 137655431 Test: CtsUiRenderingTestCases Change-Id: If3d26f41eaf4981505ee47634097f3645fd563fd
This commit is contained in:
@@ -34,19 +34,6 @@ using namespace std;
|
||||
|
||||
static JavaVM* javaVM;
|
||||
|
||||
extern int register_android_graphics_Bitmap(JNIEnv*);
|
||||
extern int register_android_graphics_BitmapFactory(JNIEnv*);
|
||||
extern int register_android_graphics_ByteBufferStreamAdaptor(JNIEnv* env);
|
||||
extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
|
||||
extern int register_android_graphics_Graphics(JNIEnv* env);
|
||||
extern int register_android_graphics_ImageDecoder(JNIEnv*);
|
||||
extern int register_android_graphics_Interpolator(JNIEnv* env);
|
||||
extern int register_android_graphics_MaskFilter(JNIEnv* env);
|
||||
extern int register_android_graphics_NinePatch(JNIEnv*);
|
||||
extern int register_android_graphics_PathEffect(JNIEnv* env);
|
||||
extern int register_android_graphics_Shader(JNIEnv* env);
|
||||
extern int register_android_graphics_Typeface(JNIEnv* env);
|
||||
|
||||
namespace android {
|
||||
|
||||
extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
|
||||
@@ -54,25 +41,6 @@ extern int register_android_content_AssetManager(JNIEnv* env);
|
||||
extern int register_android_content_StringBlock(JNIEnv* env);
|
||||
extern int register_android_content_XmlBlock(JNIEnv* env);
|
||||
extern int register_android_content_res_ApkAssets(JNIEnv* env);
|
||||
extern int register_android_graphics_Canvas(JNIEnv* env);
|
||||
extern int register_android_graphics_ColorFilter(JNIEnv* env);
|
||||
extern int register_android_graphics_ColorSpace(JNIEnv* env);
|
||||
extern int register_android_graphics_DrawFilter(JNIEnv* env);
|
||||
extern int register_android_graphics_FontFamily(JNIEnv* env);
|
||||
extern int register_android_graphics_Matrix(JNIEnv* env);
|
||||
extern int register_android_graphics_Paint(JNIEnv* env);
|
||||
extern int register_android_graphics_Path(JNIEnv* env);
|
||||
extern int register_android_graphics_PathMeasure(JNIEnv* env);
|
||||
extern int register_android_graphics_Picture(JNIEnv* env);
|
||||
extern int register_android_graphics_Region(JNIEnv* env);
|
||||
extern int register_android_graphics_animation_NativeInterpolatorFactory(JNIEnv* env);
|
||||
extern int register_android_graphics_animation_RenderNodeAnimator(JNIEnv* env);
|
||||
extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
|
||||
extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
|
||||
extern int register_android_graphics_fonts_Font(JNIEnv* env);
|
||||
extern int register_android_graphics_fonts_FontFamily(JNIEnv* env);
|
||||
extern int register_android_graphics_text_LineBreaker(JNIEnv* env);
|
||||
extern int register_android_graphics_text_MeasuredText(JNIEnv* env);
|
||||
extern int register_android_os_FileObserver(JNIEnv* env);
|
||||
extern int register_android_os_MessageQueue(JNIEnv* env);
|
||||
extern int register_android_os_SystemClock(JNIEnv* env);
|
||||
@@ -81,10 +49,7 @@ extern int register_android_os_Trace(JNIEnv* env);
|
||||
extern int register_android_text_AndroidCharacter(JNIEnv* env);
|
||||
extern int register_android_util_EventLog(JNIEnv* env);
|
||||
extern int register_android_util_Log(JNIEnv* env);
|
||||
extern int register_android_util_PathParser(JNIEnv* env);
|
||||
extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
|
||||
extern int register_android_view_RenderNode(JNIEnv* env);
|
||||
extern int register_android_view_DisplayListCanvas(JNIEnv* env);
|
||||
extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
|
||||
|
||||
#define REG_JNI(name) { name }
|
||||
@@ -103,46 +68,6 @@ static const std::unordered_map<std::string, RegJNIRec> gRegJNIMap = {
|
||||
#endif
|
||||
{"android.content.res.StringBlock", REG_JNI(register_android_content_StringBlock)},
|
||||
{"android.content.res.XmlBlock", REG_JNI(register_android_content_XmlBlock)},
|
||||
{"android.graphics.Bitmap", REG_JNI(register_android_graphics_Bitmap)},
|
||||
{"android.graphics.BitmapFactory", REG_JNI(register_android_graphics_BitmapFactory)},
|
||||
{"android.graphics.ByteBufferStreamAdaptor",
|
||||
REG_JNI(register_android_graphics_ByteBufferStreamAdaptor)},
|
||||
{"android.graphics.Canvas", REG_JNI(register_android_graphics_Canvas)},
|
||||
{"android.graphics.RenderNode", REG_JNI(register_android_view_RenderNode)},
|
||||
{"android.graphics.ColorFilter", REG_JNI(register_android_graphics_ColorFilter)},
|
||||
{"android.graphics.ColorSpace", REG_JNI(register_android_graphics_ColorSpace)},
|
||||
{"android.graphics.CreateJavaOutputStreamAdaptor",
|
||||
REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor)},
|
||||
{"android.graphics.DrawFilter", REG_JNI(register_android_graphics_DrawFilter)},
|
||||
{"android.graphics.FontFamily", REG_JNI(register_android_graphics_FontFamily)},
|
||||
{"android.graphics.Graphics", REG_JNI(register_android_graphics_Graphics)},
|
||||
{"android.graphics.ImageDecoder", REG_JNI(register_android_graphics_ImageDecoder)},
|
||||
{"android.graphics.Interpolator", REG_JNI(register_android_graphics_Interpolator)},
|
||||
{"android.graphics.MaskFilter", REG_JNI(register_android_graphics_MaskFilter)},
|
||||
{"android.graphics.Matrix", REG_JNI(register_android_graphics_Matrix)},
|
||||
{"android.graphics.NinePatch", REG_JNI(register_android_graphics_NinePatch)},
|
||||
{"android.graphics.Paint", REG_JNI(register_android_graphics_Paint)},
|
||||
{"android.graphics.Path", REG_JNI(register_android_graphics_Path)},
|
||||
{"android.graphics.PathEffect", REG_JNI(register_android_graphics_PathEffect)},
|
||||
{"android.graphics.PathMeasure", REG_JNI(register_android_graphics_PathMeasure)},
|
||||
{"android.graphics.Picture", REG_JNI(register_android_graphics_Picture)},
|
||||
{"android.graphics.RecordingCanvas", REG_JNI(register_android_view_DisplayListCanvas)},
|
||||
{"android.graphics.Region", REG_JNI(register_android_graphics_Region)},
|
||||
{"android.graphics.Shader", REG_JNI(register_android_graphics_Shader)},
|
||||
{"android.graphics.Typeface", REG_JNI(register_android_graphics_Typeface)},
|
||||
{"android.graphics.animation.NativeInterpolatorFactory",
|
||||
REG_JNI(register_android_graphics_animation_NativeInterpolatorFactory)},
|
||||
{"android.graphics.animation.RenderNodeAnimator",
|
||||
REG_JNI(register_android_graphics_animation_RenderNodeAnimator)},
|
||||
{"android.graphics.drawable.AnimatedVectorDrawable",
|
||||
REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable)},
|
||||
{"android.graphics.drawable.VectorDrawable",
|
||||
REG_JNI(register_android_graphics_drawable_VectorDrawable)},
|
||||
{"android.graphics.fonts.Font", REG_JNI(register_android_graphics_fonts_Font)},
|
||||
{"android.graphics.fonts.FontFamily", REG_JNI(register_android_graphics_fonts_FontFamily)},
|
||||
{"android.graphics.text.LineBreaker", REG_JNI(register_android_graphics_text_LineBreaker)},
|
||||
{"android.graphics.text.MeasuredText",
|
||||
REG_JNI(register_android_graphics_text_MeasuredText)},
|
||||
#ifdef __linux__
|
||||
{"android.os.FileObserver", REG_JNI(register_android_os_FileObserver)},
|
||||
{"android.os.MessageQueue", REG_JNI(register_android_os_MessageQueue)},
|
||||
@@ -153,7 +78,6 @@ static const std::unordered_map<std::string, RegJNIRec> gRegJNIMap = {
|
||||
{"android.text.AndroidCharacter", REG_JNI(register_android_text_AndroidCharacter)},
|
||||
{"android.util.EventLog", REG_JNI(register_android_util_EventLog)},
|
||||
{"android.util.Log", REG_JNI(register_android_util_Log)},
|
||||
{"android.util.PathParser", REG_JNI(register_android_util_PathParser)},
|
||||
{"android.util.jar.StrictJarFile", REG_JNI(register_android_util_jar_StrictJarFile)},
|
||||
{"com.android.internal.util.VirtualRefBasePtr",
|
||||
REG_JNI(register_com_android_internal_util_VirtualRefBasePtr)},
|
||||
|
||||
@@ -203,6 +203,11 @@ cc_defaults {
|
||||
"apex/renderthread.cpp",
|
||||
],
|
||||
},
|
||||
host: {
|
||||
srcs: [
|
||||
"apex/LayoutlibLoader.cpp",
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
#include <log/log.h>
|
||||
#include <utils/Errors.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include "Properties.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
191
libs/hwui/apex/LayoutlibLoader.cpp
Normal file
191
libs/hwui/apex/LayoutlibLoader.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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 "graphics_jni_helpers.h"
|
||||
|
||||
#include <GraphicsJNI.h>
|
||||
#include <SkGraphics.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <unicode/putil.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
* This is responsible for setting up the JNI environment for communication between
|
||||
* the Java and native parts of layoutlib, including registering native methods.
|
||||
* This is mostly achieved by copying the way it is done in the platform
|
||||
* (see AndroidRuntime.cpp).
|
||||
*/
|
||||
|
||||
static JavaVM* javaVM;
|
||||
|
||||
extern int register_android_graphics_Bitmap(JNIEnv*);
|
||||
extern int register_android_graphics_BitmapFactory(JNIEnv*);
|
||||
extern int register_android_graphics_ByteBufferStreamAdaptor(JNIEnv* env);
|
||||
extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
|
||||
extern int register_android_graphics_Graphics(JNIEnv* env);
|
||||
extern int register_android_graphics_ImageDecoder(JNIEnv*);
|
||||
extern int register_android_graphics_Interpolator(JNIEnv* env);
|
||||
extern int register_android_graphics_MaskFilter(JNIEnv* env);
|
||||
extern int register_android_graphics_NinePatch(JNIEnv*);
|
||||
extern int register_android_graphics_PathEffect(JNIEnv* env);
|
||||
extern int register_android_graphics_Shader(JNIEnv* env);
|
||||
extern int register_android_graphics_Typeface(JNIEnv* env);
|
||||
|
||||
namespace android {
|
||||
|
||||
extern int register_android_graphics_Canvas(JNIEnv* env);
|
||||
extern int register_android_graphics_ColorFilter(JNIEnv* env);
|
||||
extern int register_android_graphics_ColorSpace(JNIEnv* env);
|
||||
extern int register_android_graphics_DrawFilter(JNIEnv* env);
|
||||
extern int register_android_graphics_FontFamily(JNIEnv* env);
|
||||
extern int register_android_graphics_Matrix(JNIEnv* env);
|
||||
extern int register_android_graphics_Paint(JNIEnv* env);
|
||||
extern int register_android_graphics_Path(JNIEnv* env);
|
||||
extern int register_android_graphics_PathMeasure(JNIEnv* env);
|
||||
extern int register_android_graphics_Picture(JNIEnv* env);
|
||||
//extern int register_android_graphics_Region(JNIEnv* env);
|
||||
extern int register_android_graphics_animation_NativeInterpolatorFactory(JNIEnv* env);
|
||||
extern int register_android_graphics_animation_RenderNodeAnimator(JNIEnv* env);
|
||||
extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
|
||||
extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
|
||||
extern int register_android_graphics_fonts_Font(JNIEnv* env);
|
||||
extern int register_android_graphics_fonts_FontFamily(JNIEnv* env);
|
||||
extern int register_android_graphics_text_LineBreaker(JNIEnv* env);
|
||||
extern int register_android_graphics_text_MeasuredText(JNIEnv* env);
|
||||
extern int register_android_util_PathParser(JNIEnv* env);
|
||||
extern int register_android_view_RenderNode(JNIEnv* env);
|
||||
extern int register_android_view_DisplayListCanvas(JNIEnv* env);
|
||||
|
||||
#define REG_JNI(name) { name }
|
||||
struct RegJNIRec {
|
||||
int (*mProc)(JNIEnv*);
|
||||
};
|
||||
|
||||
// Map of all possible class names to register to their corresponding JNI registration function pointer
|
||||
// The actual list of registered classes will be determined at runtime via the 'native_classes' System property
|
||||
static const std::unordered_map<std::string, RegJNIRec> gRegJNIMap = {
|
||||
{"android.graphics.Bitmap", REG_JNI(register_android_graphics_Bitmap)},
|
||||
{"android.graphics.BitmapFactory", REG_JNI(register_android_graphics_BitmapFactory)},
|
||||
{"android.graphics.ByteBufferStreamAdaptor",
|
||||
REG_JNI(register_android_graphics_ByteBufferStreamAdaptor)},
|
||||
{"android.graphics.Canvas", REG_JNI(register_android_graphics_Canvas)},
|
||||
{"android.graphics.RenderNode", REG_JNI(register_android_view_RenderNode)},
|
||||
{"android.graphics.ColorFilter", REG_JNI(register_android_graphics_ColorFilter)},
|
||||
{"android.graphics.ColorSpace", REG_JNI(register_android_graphics_ColorSpace)},
|
||||
{"android.graphics.CreateJavaOutputStreamAdaptor",
|
||||
REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor)},
|
||||
{"android.graphics.DrawFilter", REG_JNI(register_android_graphics_DrawFilter)},
|
||||
{"android.graphics.FontFamily", REG_JNI(register_android_graphics_FontFamily)},
|
||||
{"android.graphics.Graphics", REG_JNI(register_android_graphics_Graphics)},
|
||||
{"android.graphics.ImageDecoder", REG_JNI(register_android_graphics_ImageDecoder)},
|
||||
{"android.graphics.Interpolator", REG_JNI(register_android_graphics_Interpolator)},
|
||||
{"android.graphics.MaskFilter", REG_JNI(register_android_graphics_MaskFilter)},
|
||||
{"android.graphics.Matrix", REG_JNI(register_android_graphics_Matrix)},
|
||||
{"android.graphics.NinePatch", REG_JNI(register_android_graphics_NinePatch)},
|
||||
{"android.graphics.Paint", REG_JNI(register_android_graphics_Paint)},
|
||||
{"android.graphics.Path", REG_JNI(register_android_graphics_Path)},
|
||||
{"android.graphics.PathEffect", REG_JNI(register_android_graphics_PathEffect)},
|
||||
{"android.graphics.PathMeasure", REG_JNI(register_android_graphics_PathMeasure)},
|
||||
{"android.graphics.Picture", REG_JNI(register_android_graphics_Picture)},
|
||||
{"android.graphics.RecordingCanvas", REG_JNI(register_android_view_DisplayListCanvas)},
|
||||
// {"android.graphics.Region", REG_JNI(register_android_graphics_Region)},
|
||||
{"android.graphics.Shader", REG_JNI(register_android_graphics_Shader)},
|
||||
{"android.graphics.Typeface", REG_JNI(register_android_graphics_Typeface)},
|
||||
{"android.graphics.animation.NativeInterpolatorFactory",
|
||||
REG_JNI(register_android_graphics_animation_NativeInterpolatorFactory)},
|
||||
{"android.graphics.animation.RenderNodeAnimator",
|
||||
REG_JNI(register_android_graphics_animation_RenderNodeAnimator)},
|
||||
{"android.graphics.drawable.AnimatedVectorDrawable",
|
||||
REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable)},
|
||||
{"android.graphics.drawable.VectorDrawable",
|
||||
REG_JNI(register_android_graphics_drawable_VectorDrawable)},
|
||||
{"android.graphics.fonts.Font", REG_JNI(register_android_graphics_fonts_Font)},
|
||||
{"android.graphics.fonts.FontFamily", REG_JNI(register_android_graphics_fonts_FontFamily)},
|
||||
{"android.graphics.text.LineBreaker", REG_JNI(register_android_graphics_text_LineBreaker)},
|
||||
{"android.graphics.text.MeasuredText",
|
||||
REG_JNI(register_android_graphics_text_MeasuredText)},
|
||||
{"android.util.PathParser", REG_JNI(register_android_util_PathParser)},
|
||||
};
|
||||
|
||||
static int register_jni_procs(const std::unordered_map<std::string, RegJNIRec>& jniRegMap,
|
||||
const vector<string>& classesToRegister, JNIEnv* env) {
|
||||
|
||||
for (const string& className : classesToRegister) {
|
||||
if (jniRegMap.at(className).mProc(env) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static vector<string> parseCsv(const string& csvString) {
|
||||
vector<string> result;
|
||||
istringstream stream(csvString);
|
||||
string segment;
|
||||
while(getline(stream, segment, ','))
|
||||
{
|
||||
result.push_back(segment);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static vector<string> parseCsv(JNIEnv* env, jstring csvJString) {
|
||||
const char* charArray = env->GetStringUTFChars(csvJString, 0);
|
||||
string csvString(charArray);
|
||||
vector<string> result = parseCsv(csvString);
|
||||
env->ReleaseStringUTFChars(csvJString, charArray);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
using namespace android;
|
||||
|
||||
void init_android_graphics() {
|
||||
SkGraphics::Init();
|
||||
}
|
||||
|
||||
int register_android_graphics_classes(JNIEnv *env) {
|
||||
JavaVM* vm = nullptr;
|
||||
env->GetJavaVM(&vm);
|
||||
GraphicsJNI::setJavaVM(vm);
|
||||
|
||||
// Configuration is stored as java System properties.
|
||||
// Get a reference to System.getProperty
|
||||
jclass system = FindClassOrDie(env, "java/lang/System");
|
||||
jmethodID getPropertyMethod = GetStaticMethodIDOrDie(env, system, "getProperty",
|
||||
"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
|
||||
|
||||
// Get the names of classes that need to register their native methods
|
||||
auto nativesClassesJString =
|
||||
(jstring) env->CallStaticObjectMethod(system,
|
||||
getPropertyMethod, env->NewStringUTF("native_classes"),
|
||||
env->NewStringUTF(""));
|
||||
vector<string> classesToRegister = parseCsv(env, nativesClassesJString);
|
||||
|
||||
if (register_jni_procs(gRegJNIMap, classesToRegister, env) < 0) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void zygote_preload_graphics() { }
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <GraphicsJNI.h>
|
||||
#include <Properties.h>
|
||||
#include <SkGraphics.h>
|
||||
|
||||
@@ -150,6 +151,10 @@ void init_android_graphics() {
|
||||
}
|
||||
|
||||
int register_android_graphics_classes(JNIEnv *env) {
|
||||
JavaVM* vm = nullptr;
|
||||
env->GetJavaVM(&vm);
|
||||
GraphicsJNI::setJavaVM(vm);
|
||||
|
||||
for (size_t i = 0; i < NELEM(android::gRegJNI); i++) {
|
||||
if (android::gRegJNI[i].mProc(env) < 0) {
|
||||
#ifndef NDEBUG
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "GraphicsJNI.h"
|
||||
#include "ImageDecoder.h"
|
||||
#include "Utils.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <SkAndroidCodec.h>
|
||||
#include <SkAnimatedImage.h>
|
||||
|
||||
@@ -26,9 +26,6 @@
|
||||
#include <renderthread/RenderProxy.h>
|
||||
#endif
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <jni.h>
|
||||
#include <string.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -13,17 +13,15 @@
|
||||
#include "SkStream.h"
|
||||
#include "SkUtils.h"
|
||||
#include "Utils.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <HardwareBitmapUploader.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <androidfw/Asset.h>
|
||||
#include <androidfw/ResourceTypes.h>
|
||||
#include <cutils/compiler.h>
|
||||
#include <fcntl.h>
|
||||
#include <memory>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
jfieldID gOptions_justBoundsFieldID;
|
||||
@@ -522,7 +520,9 @@ static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteA
|
||||
|
||||
static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fileDescriptor,
|
||||
jobject padding, jobject bitmapFactoryOptions, jlong inBitmapHandle, jlong colorSpaceHandle) {
|
||||
|
||||
#ifndef __ANDROID__ // LayoutLib for Windows does not support F_DUPFD_CLOEXEC
|
||||
return nullObjectReturn("Not supported on Windows");
|
||||
#else
|
||||
NPE_CHECK_RETURN_ZERO(env, fileDescriptor);
|
||||
|
||||
int descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
|
||||
@@ -569,6 +569,7 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
|
||||
|
||||
return doDecode(env, std::move(stream), padding, bitmapFactoryOptions, inBitmapHandle,
|
||||
colorSpaceHandle);
|
||||
#endif
|
||||
}
|
||||
|
||||
static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz, jlong native_asset,
|
||||
|
||||
@@ -28,12 +28,8 @@
|
||||
#include "SkData.h"
|
||||
#include "SkStream.h"
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <HardwareBitmapUploader.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <androidfw/Asset.h>
|
||||
#include <jni.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "ByteBufferStreamAdaptor.h"
|
||||
#include "core_jni_helpers.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "Utils.h"
|
||||
#include <jni.h>
|
||||
|
||||
#include <SkStream.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
#include "jni.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include "SkCamera.h"
|
||||
|
||||
#include "GraphicsJNI.h"
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include <core_jni_helpers.h>
|
||||
|
||||
#include <hwui/Paint.h>
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkColorMatrixFilter.h"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef _ANDROID_GRAPHICS_CREATE_JAVA_OUTPUT_STREAM_ADAPTOR_H_
|
||||
#define _ANDROID_GRAPHICS_CREATE_JAVA_OUTPUT_STREAM_ADAPTOR_H_
|
||||
|
||||
//#include <android_runtime/AndroidRuntime.h>
|
||||
#include "jni.h"
|
||||
|
||||
class SkMemoryStream;
|
||||
|
||||
@@ -17,9 +17,6 @@
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "Minikin"
|
||||
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <core_jni_helpers.h>
|
||||
|
||||
#include "SkData.h"
|
||||
#include "SkFontMgr.h"
|
||||
#include "SkRefCnt.h"
|
||||
@@ -27,7 +24,6 @@
|
||||
#include "GraphicsJNI.h"
|
||||
#include <nativehelper/ScopedPrimitiveArray.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
#include "Utils.h"
|
||||
#include "FontUtils.h"
|
||||
|
||||
@@ -145,15 +141,11 @@ static bool addSkTypeface(NativeFamilyBuilder* builder, sk_sp<SkData>&& data, in
|
||||
}
|
||||
|
||||
static void release_global_ref(const void* /*data*/, void* context) {
|
||||
JNIEnv* env = AndroidRuntime::getJNIEnv();
|
||||
JNIEnv* env = GraphicsJNI::getJNIEnv();
|
||||
bool needToAttach = (env == NULL);
|
||||
if (needToAttach) {
|
||||
JavaVMAttachArgs args;
|
||||
args.version = JNI_VERSION_1_4;
|
||||
args.name = "release_font_data";
|
||||
args.group = NULL;
|
||||
jint result = AndroidRuntime::getJavaVM()->AttachCurrentThread(&env, &args);
|
||||
if (result != JNI_OK) {
|
||||
env = GraphicsJNI::attachJNIEnv("release_font_data");
|
||||
if (env == nullptr) {
|
||||
ALOGE("failed to attach to thread to release global ref.");
|
||||
return;
|
||||
}
|
||||
@@ -163,7 +155,7 @@ static void release_global_ref(const void* /*data*/, void* context) {
|
||||
env->DeleteGlobalRef(obj);
|
||||
|
||||
if (needToAttach) {
|
||||
AndroidRuntime::getJavaVM()->DetachCurrentThread();
|
||||
GraphicsJNI::detachJNIEnv();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
#include "FontUtils.h"
|
||||
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <core_jni_helpers.h>
|
||||
#include "graphics_jni_helpers.h"
|
||||
|
||||
namespace android {
|
||||
namespace {
|
||||
|
||||
@@ -1,23 +1,55 @@
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "GraphicsJNI"
|
||||
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "jni.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include "GraphicsJNI.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include "SkCanvas.h"
|
||||
#include "SkMath.h"
|
||||
#include "SkRegion.h"
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
#include <cutils/ashmem.h>
|
||||
#include <hwui/Canvas.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
/*static*/ JavaVM* GraphicsJNI::mJavaVM = nullptr;
|
||||
|
||||
void GraphicsJNI::setJavaVM(JavaVM* javaVM) {
|
||||
mJavaVM = javaVM;
|
||||
}
|
||||
|
||||
/** return a pointer to the JNIEnv for this thread */
|
||||
JNIEnv* GraphicsJNI::getJNIEnv() {
|
||||
assert(mJavaVM != nullptr);
|
||||
JNIEnv* env;
|
||||
if (mJavaVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
/** create a JNIEnv* for this thread or assert if one already exists */
|
||||
JNIEnv* GraphicsJNI::attachJNIEnv(const char* envName) {
|
||||
assert(getJNIEnv() == nullptr);
|
||||
JNIEnv* env = nullptr;
|
||||
JavaVMAttachArgs args = { JNI_VERSION_1_4, envName, NULL };
|
||||
int result = mJavaVM->AttachCurrentThread(&env, (void*) &args);
|
||||
if (result != JNI_OK) {
|
||||
ALOGE("thread attach failed: %#x", result);
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
/** detach the current thread from the JavaVM */
|
||||
void GraphicsJNI::detachJNIEnv() {
|
||||
assert(mJavaVM != nullptr);
|
||||
mJavaVM->DetachCurrentThread();
|
||||
}
|
||||
|
||||
void doThrowNPE(JNIEnv* env) {
|
||||
jniThrowNullPointerException(env, NULL);
|
||||
}
|
||||
|
||||
@@ -10,10 +10,11 @@
|
||||
#include "SkPoint.h"
|
||||
#include "SkRect.h"
|
||||
#include "SkColorSpace.h"
|
||||
#include <jni.h>
|
||||
#include <hwui/Canvas.h>
|
||||
#include <hwui/Bitmap.h>
|
||||
|
||||
#include "graphics_jni_helpers.h"
|
||||
|
||||
class SkBitmapRegionDecoder;
|
||||
class SkCanvas;
|
||||
|
||||
@@ -39,6 +40,20 @@ public:
|
||||
kLastEnum_LegacyBitmapConfig = kHardware_LegacyBitmapConfig
|
||||
};
|
||||
|
||||
static void setJavaVM(JavaVM* javaVM);
|
||||
|
||||
/** returns a pointer to the JavaVM provided when we initialized the module */
|
||||
static JavaVM* getJavaVM() { return mJavaVM; }
|
||||
|
||||
/** return a pointer to the JNIEnv for this thread */
|
||||
static JNIEnv* getJNIEnv();
|
||||
|
||||
/** create a JNIEnv* for this thread or assert if one already exists */
|
||||
static JNIEnv* attachJNIEnv(const char* envName);
|
||||
|
||||
/** detach the current thread from the JavaVM */
|
||||
static void detachJNIEnv();
|
||||
|
||||
// returns true if an exception is set (and dumps it out to the Log)
|
||||
static bool hasException(JNIEnv*);
|
||||
|
||||
@@ -131,6 +146,10 @@ public:
|
||||
* above.
|
||||
*/
|
||||
static SkColor4f convertColorLong(jlong color);
|
||||
|
||||
private:
|
||||
/* JNI JavaVM pointer */
|
||||
static JavaVM* mJavaVM;
|
||||
};
|
||||
|
||||
class HeapAllocator : public SkBRDAllocator {
|
||||
|
||||
@@ -18,16 +18,14 @@
|
||||
#define LOG_TAG "GraphicsStatsService"
|
||||
|
||||
#include <JankTracker.h>
|
||||
#include <jni.h>
|
||||
#include <log/log.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/ScopedPrimitiveArray.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include <service/GraphicsStatsService.h>
|
||||
#include <stats_event.h>
|
||||
#include <stats_pull_atom_callback.h>
|
||||
#include <statslog.h>
|
||||
#include "core_jni_helpers.h"
|
||||
#include "GraphicsJNI.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
@@ -116,7 +114,7 @@ static jobject gGraphicsStatsServiceObject = nullptr;
|
||||
static jmethodID gGraphicsStatsService_pullGraphicsStatsMethodID;
|
||||
|
||||
static JNIEnv* getJNIEnv() {
|
||||
JavaVM* vm = AndroidRuntime::getJavaVM();
|
||||
JavaVM* vm = GraphicsJNI::getJavaVM();
|
||||
JNIEnv* env = nullptr;
|
||||
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||
if (vm->AttachCurrentThreadAsDaemon(&env, nullptr) != JNI_OK) {
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "ImageDecoder.h"
|
||||
#include "NinePatchPeeker.h"
|
||||
#include "Utils.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <hwui/Bitmap.h>
|
||||
#include <hwui/ImageDecoder.h>
|
||||
@@ -34,7 +33,7 @@
|
||||
#include <SkStream.h>
|
||||
|
||||
#include <androidfw/Asset.h>
|
||||
#include <jni.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace android;
|
||||
@@ -154,6 +153,9 @@ static jobject native_create(JNIEnv* env, std::unique_ptr<SkStream> stream,
|
||||
|
||||
static jobject ImageDecoder_nCreateFd(JNIEnv* env, jobject /*clazz*/,
|
||||
jobject fileDescriptor, jboolean preferAnimation, jobject source) {
|
||||
#ifndef __ANDROID__ // LayoutLib for Windows does not support F_DUPFD_CLOEXEC
|
||||
return throw_exception(env, kSourceException, "Only supported on Android", nullptr, source);
|
||||
#else
|
||||
int descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
|
||||
|
||||
struct stat fdStat;
|
||||
@@ -172,6 +174,7 @@ static jobject ImageDecoder_nCreateFd(JNIEnv* env, jobject /*clazz*/,
|
||||
|
||||
std::unique_ptr<SkFILEStream> fileStream(new SkFILEStream(file));
|
||||
return native_create(env, std::move(fileStream), source, preferAnimation);
|
||||
#endif
|
||||
}
|
||||
|
||||
static jobject ImageDecoder_nCreateInputStream(JNIEnv* env, jobject /*clazz*/,
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "GraphicsJNI.h"
|
||||
#include "SkInterpolator.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
static jlong Interpolator_constructor(JNIEnv* env, jobject clazz, jint valueCount, jint frameCount)
|
||||
{
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
#include "SkBlurMaskFilter.h"
|
||||
#include "SkTableMaskFilter.h"
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
static void ThrowIAE_IfNull(JNIEnv* env, void* ptr) {
|
||||
if (NULL == ptr) {
|
||||
doThrowIAE(env);
|
||||
|
||||
@@ -6,13 +6,11 @@
|
||||
#include "SkStream.h"
|
||||
#include "SkUtils.h"
|
||||
#include "Utils.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <androidfw/Asset.h>
|
||||
#include <androidfw/ResourceTypes.h>
|
||||
#include <hwui/Canvas.h>
|
||||
#include <hwui/Paint.h>
|
||||
#include <jni.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
static jclass gMovie_class;
|
||||
|
||||
@@ -31,9 +31,6 @@
|
||||
#include "NinePatchPeeker.h"
|
||||
#include "NinePatchUtils.h"
|
||||
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
jclass gInsetStruct_class;
|
||||
jmethodID gInsetStruct_constructorMethodID;
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@
|
||||
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "core_jni_helpers.h"
|
||||
#include <nativehelper/ScopedStringChars.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include <nativehelper/ScopedPrimitiveArray.h>
|
||||
|
||||
@@ -15,11 +15,7 @@
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include "hwui/Paint.h"
|
||||
#include "hwui/PaintFilter.h"
|
||||
|
||||
@@ -20,9 +20,7 @@
|
||||
// To change this file, either edit the include, or device/tools/gluemaker/main.cpp,
|
||||
// or one of the auxilary file specifications in device/tools/gluemaker.
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include "SkPath.h"
|
||||
#include "SkPathOps.h"
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
#include "SkDashPathEffect.h"
|
||||
#include "SkDiscretePathEffect.h"
|
||||
#include "SkPathEffect.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
class SkPathEffectGlue {
|
||||
public:
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include <core_jni_helpers.h>
|
||||
|
||||
#include "SkPathMeasure.h"
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
#include "android_os_Parcel.h"
|
||||
#include "android_util_Binder.h"
|
||||
|
||||
#include <jni.h>
|
||||
#include <core_jni_helpers.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
static jfieldID gRegion_nativeInstanceFieldID;
|
||||
|
||||
@@ -4,11 +4,8 @@
|
||||
#include "SkImagePriv.h"
|
||||
#include "SkShader.h"
|
||||
#include "SkBlendMode.h"
|
||||
#include "core_jni_helpers.h"
|
||||
#include "include/effects/SkRuntimeEffect.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace android::uirenderer;
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include "FontUtils.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include <nativehelper/ScopedPrimitiveArray.h>
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
#include <ui/PixelFormat.h>
|
||||
#include <hardware/hardware.h>
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <jni.h>
|
||||
#include "graphics_jni_helpers.h"
|
||||
|
||||
YuvToJpegEncoder* YuvToJpegEncoder::create(int format, int* strides) {
|
||||
// Only ImageFormat.NV21 and ImageFormat.YUY2 are supported
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#ifdef __ANDROID_
|
||||
#include <android/api-level.h>
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include "SkColor.h"
|
||||
#include "SkColorSpace.h"
|
||||
#include "SkHalf.h"
|
||||
|
||||
using namespace android;
|
||||
|
||||
@@ -42,9 +41,13 @@ static skcms_Matrix3x3 getNativeXYZMatrix(JNIEnv* env, jfloatArray xyzD50) {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static float halfToFloat(uint16_t bits) {
|
||||
__fp16 h;
|
||||
memcpy(&h, &bits, 2);
|
||||
return (float)h;
|
||||
#ifdef __ANDROID__ // __fp16 is not defined on non-Android builds
|
||||
__fp16 h;
|
||||
memcpy(&h, &bits, 2);
|
||||
return (float)h;
|
||||
#else
|
||||
return SkHalfToFloat(bits);
|
||||
#endif
|
||||
}
|
||||
|
||||
SkColor4f GraphicsJNI::convertColorLong(jlong color) {
|
||||
|
||||
@@ -14,11 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
#ifdef __ANDROID__ // Layoutlib does not support Looper and device properties
|
||||
#include <utils/Looper.h>
|
||||
#endif
|
||||
@@ -36,8 +33,6 @@
|
||||
#include <renderthread/RenderProxy.h>
|
||||
#endif
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
using namespace uirenderer;
|
||||
|
||||
@@ -44,8 +44,6 @@
|
||||
#include <atomic>
|
||||
|
||||
#include "android_graphics_HardwareRendererObserver.h"
|
||||
#include "core_jni_helpers.h"
|
||||
#include "jni.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "android_graphics_HardwareRendererObserver.h"
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
#include "graphics_jni_helpers.h"
|
||||
#include "nativehelper/jni_macros.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
#include "GraphicsJNI.h"
|
||||
#include "Matrix.h"
|
||||
#include "SkMatrix.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
|
||||
@@ -19,12 +19,9 @@
|
||||
#include "Picture.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkStream.h"
|
||||
#include "core_jni_helpers.h"
|
||||
#include "nativehelper/jni_macros.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <array>
|
||||
#include "nativehelper/jni_macros.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
|
||||
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
|
||||
#define ATRACE_TAG ATRACE_TAG_VIEW
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
|
||||
#include <Animator.h>
|
||||
#include <DamageAccumulator.h>
|
||||
@@ -31,8 +28,6 @@
|
||||
#include <hwui/Paint.h>
|
||||
#include <utils/TraceUtils.h>
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
using namespace uirenderer;
|
||||
|
||||
@@ -14,11 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
|
||||
#include <android/surface_texture_jni.h>
|
||||
#include "core_jni_helpers.h"
|
||||
#include "graphics_jni_helpers.h"
|
||||
|
||||
#include <hwui/Paint.h>
|
||||
#include <SkMatrix.h>
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
#define LOG_TAG "OpenGLRenderer"
|
||||
|
||||
#include "jni.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <cutils/log.h>
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <Interpolator.h>
|
||||
#include <cutils/log.h>
|
||||
|
||||
#include "graphics_jni_helpers.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
|
||||
@@ -16,15 +16,11 @@
|
||||
|
||||
#define LOG_TAG "OpenGLRenderer"
|
||||
|
||||
#include "jni.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
|
||||
#include <Animator.h>
|
||||
#include <Interpolator.h>
|
||||
#include <RenderProperties.h>
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
#include "graphics_jni_helpers.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
#include "android/log.h"
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include "Animator.h"
|
||||
#include "Interpolator.h"
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
|
||||
#include "GraphicsJNI.h"
|
||||
#include "jni.h"
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include "PathParser.h"
|
||||
#include "VectorDrawable.h"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "android_nio_utils.h"
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
|
||||
#include <PathParser.h>
|
||||
@@ -22,7 +21,6 @@
|
||||
#include <utils/VectorDrawableUtils.h>
|
||||
|
||||
#include <android/log.h>
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
|
||||
@@ -17,16 +17,12 @@
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "Minikin"
|
||||
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <core_jni_helpers.h>
|
||||
|
||||
#include "SkData.h"
|
||||
#include "SkFontMgr.h"
|
||||
#include "SkRefCnt.h"
|
||||
#include "SkTypeface.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
#include "Utils.h"
|
||||
#include "FontUtils.h"
|
||||
|
||||
@@ -52,14 +48,11 @@ static void releaseFont(jlong font) {
|
||||
}
|
||||
|
||||
static void release_global_ref(const void* /*data*/, void* context) {
|
||||
JNIEnv* env = AndroidRuntime::getJNIEnv();
|
||||
if (env == nullptr) {
|
||||
JavaVMAttachArgs args;
|
||||
args.version = JNI_VERSION_1_4;
|
||||
args.name = "release_font_data";
|
||||
args.group = nullptr;
|
||||
jint result = AndroidRuntime::getJavaVM()->AttachCurrentThread(&env, &args);
|
||||
if (result != JNI_OK) {
|
||||
JNIEnv* env = GraphicsJNI::getJNIEnv();
|
||||
bool needToAttach = (env == nullptr);
|
||||
if (needToAttach) {
|
||||
env = GraphicsJNI::attachJNIEnv("release_font_data");
|
||||
if (env == nullptr) {
|
||||
ALOGE("failed to attach to thread to release global ref.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "Minikin"
|
||||
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include "graphics_jni_helpers.h"
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include <core_jni_helpers.h>
|
||||
|
||||
#include "FontUtils.h"
|
||||
|
||||
|
||||
106
libs/hwui/jni/graphics_jni_helpers.h
Normal file
106
libs/hwui/jni/graphics_jni_helpers.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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 GRAPHICS_JNI_HELPERS
|
||||
#define GRAPHICS_JNI_HELPERS
|
||||
|
||||
#include <log/log.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/scoped_local_ref.h>
|
||||
#include <nativehelper/scoped_utf_chars.h>
|
||||
#include <string>
|
||||
|
||||
// Host targets (layoutlib) do not differentiate between regular and critical native methods,
|
||||
// and they need all the JNI methods to have JNIEnv* and jclass/jobject as their first two arguments.
|
||||
// The following macro allows to have those arguments when compiling for host while omitting them when
|
||||
// compiling for Android.
|
||||
#ifdef __ANDROID__
|
||||
#define CRITICAL_JNI_PARAMS
|
||||
#define CRITICAL_JNI_PARAMS_COMMA
|
||||
#else
|
||||
#define CRITICAL_JNI_PARAMS JNIEnv*, jclass
|
||||
#define CRITICAL_JNI_PARAMS_COMMA JNIEnv*, jclass,
|
||||
#endif
|
||||
|
||||
namespace android {
|
||||
|
||||
// Defines some helpful functions.
|
||||
|
||||
static inline jclass FindClassOrDie(JNIEnv* env, const char* class_name) {
|
||||
jclass clazz = env->FindClass(class_name);
|
||||
LOG_ALWAYS_FATAL_IF(clazz == NULL, "Unable to find class %s", class_name);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
static inline jfieldID GetFieldIDOrDie(JNIEnv* env, jclass clazz, const char* field_name,
|
||||
const char* field_signature) {
|
||||
jfieldID res = env->GetFieldID(clazz, field_name, field_signature);
|
||||
LOG_ALWAYS_FATAL_IF(res == NULL, "Unable to find static field %s", field_name);
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline jmethodID GetMethodIDOrDie(JNIEnv* env, jclass clazz, const char* method_name,
|
||||
const char* method_signature) {
|
||||
jmethodID res = env->GetMethodID(clazz, method_name, method_signature);
|
||||
LOG_ALWAYS_FATAL_IF(res == NULL, "Unable to find method %s", method_name);
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline jfieldID GetStaticFieldIDOrDie(JNIEnv* env, jclass clazz, const char* field_name,
|
||||
const char* field_signature) {
|
||||
jfieldID res = env->GetStaticFieldID(clazz, field_name, field_signature);
|
||||
LOG_ALWAYS_FATAL_IF(res == NULL, "Unable to find static field %s", field_name);
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline jmethodID GetStaticMethodIDOrDie(JNIEnv* env, jclass clazz, const char* method_name,
|
||||
const char* method_signature) {
|
||||
jmethodID res = env->GetStaticMethodID(clazz, method_name, method_signature);
|
||||
LOG_ALWAYS_FATAL_IF(res == NULL, "Unable to find static method %s", method_name);
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline T MakeGlobalRefOrDie(JNIEnv* env, T in) {
|
||||
jobject res = env->NewGlobalRef(in);
|
||||
LOG_ALWAYS_FATAL_IF(res == NULL, "Unable to create global reference.");
|
||||
return static_cast<T>(res);
|
||||
}
|
||||
|
||||
static inline int RegisterMethodsOrDie(JNIEnv* env, const char* className,
|
||||
const JNINativeMethod* gMethods, int numMethods) {
|
||||
int res = jniRegisterNativeMethods(env, className, gMethods, numMethods);
|
||||
LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods.");
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the specified field from jobject, and convert to std::string.
|
||||
* If the field cannot be obtained, return defaultValue.
|
||||
*/
|
||||
static inline std::string getStringField(JNIEnv* env, jobject obj, jfieldID fieldId,
|
||||
const char* defaultValue) {
|
||||
ScopedLocalRef<jstring> strObj(env, jstring(env->GetObjectField(obj, fieldId)));
|
||||
if (strObj != nullptr) {
|
||||
ScopedUtfChars chars(env, strObj.get());
|
||||
return std::string(chars.c_str());
|
||||
}
|
||||
return std::string(defaultValue);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // GRAPHICS_JNI_HELPERS
|
||||
@@ -14,9 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "core_jni_helpers.h"
|
||||
#include <vector>
|
||||
|
||||
#include "CreateJavaOutputStreamAdaptor.h"
|
||||
|
||||
@@ -27,8 +27,7 @@
|
||||
|
||||
#include "PdfUtils.h"
|
||||
|
||||
#include "jni.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include "graphics_jni_helpers.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
|
||||
@@ -40,8 +39,6 @@
|
||||
|
||||
#include "SkMatrix.h"
|
||||
|
||||
#include <core_jni_helpers.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
enum PageBox {PAGE_BOX_MEDIA, PAGE_BOX_CROP};
|
||||
|
||||
@@ -16,14 +16,11 @@
|
||||
|
||||
#include "PdfUtils.h"
|
||||
|
||||
#include "jni.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include "GraphicsJNI.h"
|
||||
#include "SkBitmap.h"
|
||||
#include "SkMatrix.h"
|
||||
#include "fpdfview.h"
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
#include <vector>
|
||||
#include <utils/Log.h>
|
||||
#include <unistd.h>
|
||||
|
||||
103
libs/hwui/jni/scoped_nullable_primitive_array.h
Normal file
103
libs/hwui/jni/scoped_nullable_primitive_array.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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 SCOPED_NULLABLE_PRIMITIVE_ARRAY_H
|
||||
#define SCOPED_NULLABLE_PRIMITIVE_ARRAY_H
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
#define ARRAY_TRAITS(ARRAY_TYPE, POINTER_TYPE, NAME) \
|
||||
class NAME ## ArrayTraits { \
|
||||
public: \
|
||||
static constexpr void getArrayRegion(JNIEnv* env, ARRAY_TYPE array, size_t start, \
|
||||
size_t len, POINTER_TYPE out) { \
|
||||
env->Get ## NAME ## ArrayRegion(array, start, len, out); \
|
||||
} \
|
||||
\
|
||||
static constexpr POINTER_TYPE getArrayElements(JNIEnv* env, ARRAY_TYPE array) { \
|
||||
return env->Get ## NAME ## ArrayElements(array, nullptr); \
|
||||
} \
|
||||
\
|
||||
static constexpr void releaseArrayElements(JNIEnv* env, ARRAY_TYPE array, \
|
||||
POINTER_TYPE buffer, jint mode) { \
|
||||
env->Release ## NAME ## ArrayElements(array, buffer, mode); \
|
||||
} \
|
||||
}; \
|
||||
|
||||
ARRAY_TRAITS(jbooleanArray, jboolean*, Boolean)
|
||||
ARRAY_TRAITS(jbyteArray, jbyte*, Byte)
|
||||
ARRAY_TRAITS(jcharArray, jchar*, Char)
|
||||
ARRAY_TRAITS(jdoubleArray, jdouble*, Double)
|
||||
ARRAY_TRAITS(jfloatArray, jfloat*, Float)
|
||||
ARRAY_TRAITS(jintArray, jint*, Int)
|
||||
ARRAY_TRAITS(jlongArray, jlong*, Long)
|
||||
ARRAY_TRAITS(jshortArray, jshort*, Short)
|
||||
|
||||
#undef ARRAY_TRAITS
|
||||
|
||||
template<typename JavaArrayType, typename PrimitiveType, class Traits, size_t preallocSize = 10>
|
||||
class ScopedArrayRO {
|
||||
public:
|
||||
ScopedArrayRO(JNIEnv* env, JavaArrayType javaArray) : mEnv(env), mJavaArray(javaArray) {
|
||||
if (mJavaArray == nullptr) {
|
||||
mSize = 0;
|
||||
mRawArray = nullptr;
|
||||
} else {
|
||||
mSize = mEnv->GetArrayLength(mJavaArray);
|
||||
if (mSize <= preallocSize) {
|
||||
Traits::getArrayRegion(mEnv, mJavaArray, 0, mSize, mBuffer);
|
||||
mRawArray = mBuffer;
|
||||
} else {
|
||||
mRawArray = Traits::getArrayElements(mEnv, mJavaArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~ScopedArrayRO() {
|
||||
if (mRawArray != nullptr && mRawArray != mBuffer) {
|
||||
Traits::releaseArrayElements(mEnv, mJavaArray, mRawArray, JNI_ABORT);
|
||||
}
|
||||
}
|
||||
|
||||
const PrimitiveType* get() const { return mRawArray; }
|
||||
const PrimitiveType& operator[](size_t n) const { return mRawArray[n]; }
|
||||
size_t size() const { return mSize; }
|
||||
|
||||
private:
|
||||
JNIEnv* const mEnv;
|
||||
JavaArrayType mJavaArray;
|
||||
PrimitiveType* mRawArray;
|
||||
size_t mSize;
|
||||
PrimitiveType mBuffer[preallocSize];
|
||||
DISALLOW_COPY_AND_ASSIGN(ScopedArrayRO);
|
||||
};
|
||||
|
||||
// ScopedNullable***ArrayRO provide convenient read-only access to Java array from JNI code.
|
||||
// These accept nullptr. In that case, get() returns nullptr and size() returns 0.
|
||||
using ScopedNullableBooleanArrayRO = ScopedArrayRO<jbooleanArray, jboolean, BooleanArrayTraits>;
|
||||
using ScopedNullableByteArrayRO = ScopedArrayRO<jbyteArray, jbyte, ByteArrayTraits>;
|
||||
using ScopedNullableCharArrayRO = ScopedArrayRO<jcharArray, jchar, CharArrayTraits>;
|
||||
using ScopedNullableDoubleArrayRO = ScopedArrayRO<jdoubleArray, jdouble, DoubleArrayTraits>;
|
||||
using ScopedNullableFloatArrayRO = ScopedArrayRO<jfloatArray, jfloat, FloatArrayTraits>;
|
||||
using ScopedNullableIntArrayRO = ScopedArrayRO<jintArray, jint, IntArrayTraits>;
|
||||
using ScopedNullableLongArrayRO = ScopedArrayRO<jlongArray, jlong, LongArrayTraits>;
|
||||
using ScopedNullableShortArrayRO = ScopedArrayRO<jshortArray, jshort, ShortArrayTraits>;
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // SCOPED_NULLABLE_PRIMITIVE_ARRAY_H
|
||||
@@ -19,10 +19,9 @@
|
||||
|
||||
#include "utils/misc.h"
|
||||
#include "utils/Log.h"
|
||||
#include "graphics_jni_helpers.h"
|
||||
#include <nativehelper/ScopedStringChars.h>
|
||||
#include <nativehelper/ScopedPrimitiveArray.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include "core_jni_helpers.h"
|
||||
#include "scoped_nullable_primitive_array.h"
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#include "utils/Log.h"
|
||||
#include <nativehelper/ScopedStringChars.h>
|
||||
#include <nativehelper/ScopedPrimitiveArray.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include "core_jni_helpers.h"
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
#define DEBUG_INPUT_DISPATCHER_POLICY 0
|
||||
|
||||
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include "jni.h"
|
||||
#include <atomic>
|
||||
#include <cinttypes>
|
||||
#include <limits.h>
|
||||
@@ -50,7 +48,6 @@
|
||||
|
||||
#include <inputflinger/InputManager.h>
|
||||
|
||||
#include <android/graphics/GraphicsJNI.h>
|
||||
#include <android_os_MessageQueue.h>
|
||||
#include <android_view_InputChannel.h>
|
||||
#include <android_view_InputDevice.h>
|
||||
|
||||
Reference in New Issue
Block a user