Derek Sollenberger | 9ca0c52 | 2019-08-29 13:08:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "android/graphics/jni_runtime.h" |
| 18 | |
| 19 | #include <android/log.h> |
| 20 | #include <nativehelper/JNIHelp.h> |
| 21 | #include <sys/cdefs.h> |
| 22 | |
| 23 | #include <EGL/egl.h> |
| 24 | #include <Properties.h> |
| 25 | #include <SkGraphics.h> |
| 26 | |
| 27 | #define LOG_TAG "AndroidGraphicsJNI" |
| 28 | |
| 29 | extern int register_android_graphics_Bitmap(JNIEnv*); |
| 30 | extern int register_android_graphics_BitmapFactory(JNIEnv*); |
| 31 | extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*); |
| 32 | extern int register_android_graphics_ByteBufferStreamAdaptor(JNIEnv* env); |
| 33 | extern int register_android_graphics_Camera(JNIEnv* env); |
| 34 | extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env); |
| 35 | extern int register_android_graphics_Graphics(JNIEnv* env); |
| 36 | extern int register_android_graphics_ImageDecoder(JNIEnv*); |
| 37 | extern int register_android_graphics_drawable_AnimatedImageDrawable(JNIEnv*); |
| 38 | extern int register_android_graphics_Interpolator(JNIEnv* env); |
| 39 | extern int register_android_graphics_MaskFilter(JNIEnv* env); |
| 40 | extern int register_android_graphics_Movie(JNIEnv* env); |
| 41 | extern int register_android_graphics_NinePatch(JNIEnv*); |
| 42 | extern int register_android_graphics_PathEffect(JNIEnv* env); |
| 43 | extern int register_android_graphics_Shader(JNIEnv* env); |
| 44 | extern int register_android_graphics_Typeface(JNIEnv* env); |
| 45 | extern int register_android_graphics_YuvImage(JNIEnv* env); |
| 46 | |
| 47 | namespace android { |
| 48 | |
| 49 | extern int register_android_graphics_Canvas(JNIEnv* env); |
| 50 | extern int register_android_graphics_CanvasProperty(JNIEnv* env); |
| 51 | extern int register_android_graphics_ColorFilter(JNIEnv* env); |
| 52 | extern int register_android_graphics_ColorSpace(JNIEnv* env); |
| 53 | extern int register_android_graphics_DrawFilter(JNIEnv* env); |
| 54 | extern int register_android_graphics_FontFamily(JNIEnv* env); |
| 55 | extern int register_android_graphics_Matrix(JNIEnv* env); |
| 56 | extern int register_android_graphics_Paint(JNIEnv* env); |
| 57 | extern int register_android_graphics_Path(JNIEnv* env); |
| 58 | extern int register_android_graphics_PathMeasure(JNIEnv* env); |
| 59 | extern int register_android_graphics_Picture(JNIEnv*); |
| 60 | extern int register_android_graphics_Region(JNIEnv* env); |
| 61 | extern int register_android_graphics_SurfaceTexture(JNIEnv* env); |
| 62 | extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env); |
| 63 | extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env); |
| 64 | extern int register_android_graphics_fonts_Font(JNIEnv* env); |
| 65 | extern int register_android_graphics_fonts_FontFamily(JNIEnv* env); |
| 66 | extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env); |
| 67 | extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env); |
| 68 | extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env); |
| 69 | extern int register_android_graphics_text_MeasuredText(JNIEnv* env); |
| 70 | extern int register_android_graphics_text_LineBreaker(JNIEnv *env); |
| 71 | |
| 72 | extern int register_android_util_PathParser(JNIEnv* env); |
| 73 | extern int register_android_view_DisplayListCanvas(JNIEnv* env); |
| 74 | extern int register_android_view_FrameMetricsObserver(JNIEnv* env); |
| 75 | extern int register_android_view_RenderNode(JNIEnv* env); |
| 76 | extern int register_android_view_TextureLayer(JNIEnv* env); |
| 77 | extern int register_android_view_ThreadedRenderer(JNIEnv* env); |
| 78 | |
| 79 | #ifdef NDEBUG |
| 80 | #define REG_JNI(name) { name } |
| 81 | struct RegJNIRec { |
| 82 | int (*mProc)(JNIEnv*); |
| 83 | }; |
| 84 | #else |
| 85 | #define REG_JNI(name) { name, #name } |
| 86 | struct RegJNIRec { |
| 87 | int (*mProc)(JNIEnv*); |
| 88 | const char* mName; |
| 89 | }; |
| 90 | #endif |
| 91 | |
| 92 | static const RegJNIRec gRegJNI[] = { |
| 93 | REG_JNI(register_android_graphics_Canvas), |
| 94 | // This needs to be before register_android_graphics_Graphics, or the latter |
| 95 | // will not be able to find the jmethodID for ColorSpace.get(). |
| 96 | REG_JNI(register_android_graphics_ColorSpace), |
| 97 | REG_JNI(register_android_graphics_Graphics), |
| 98 | REG_JNI(register_android_graphics_Bitmap), |
| 99 | REG_JNI(register_android_graphics_BitmapFactory), |
| 100 | REG_JNI(register_android_graphics_BitmapRegionDecoder), |
| 101 | REG_JNI(register_android_graphics_ByteBufferStreamAdaptor), |
| 102 | REG_JNI(register_android_graphics_Camera), |
| 103 | REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor), |
| 104 | REG_JNI(register_android_graphics_CanvasProperty), |
| 105 | REG_JNI(register_android_graphics_ColorFilter), |
| 106 | REG_JNI(register_android_graphics_DrawFilter), |
| 107 | REG_JNI(register_android_graphics_FontFamily), |
| 108 | REG_JNI(register_android_graphics_ImageDecoder), |
| 109 | REG_JNI(register_android_graphics_drawable_AnimatedImageDrawable), |
| 110 | REG_JNI(register_android_graphics_Interpolator), |
| 111 | REG_JNI(register_android_graphics_MaskFilter), |
| 112 | REG_JNI(register_android_graphics_Matrix), |
| 113 | REG_JNI(register_android_graphics_Movie), |
| 114 | REG_JNI(register_android_graphics_NinePatch), |
| 115 | REG_JNI(register_android_graphics_Paint), |
| 116 | REG_JNI(register_android_graphics_Path), |
| 117 | REG_JNI(register_android_graphics_PathMeasure), |
| 118 | REG_JNI(register_android_graphics_PathEffect), |
| 119 | REG_JNI(register_android_graphics_Picture), |
| 120 | REG_JNI(register_android_graphics_Region), |
| 121 | REG_JNI(register_android_graphics_Shader), |
| 122 | REG_JNI(register_android_graphics_SurfaceTexture), |
| 123 | REG_JNI(register_android_graphics_Typeface), |
| 124 | REG_JNI(register_android_graphics_YuvImage), |
| 125 | REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable), |
| 126 | REG_JNI(register_android_graphics_drawable_VectorDrawable), |
| 127 | REG_JNI(register_android_graphics_fonts_Font), |
| 128 | REG_JNI(register_android_graphics_fonts_FontFamily), |
| 129 | REG_JNI(register_android_graphics_pdf_PdfDocument), |
| 130 | REG_JNI(register_android_graphics_pdf_PdfEditor), |
| 131 | REG_JNI(register_android_graphics_pdf_PdfRenderer), |
| 132 | REG_JNI(register_android_graphics_text_MeasuredText), |
| 133 | REG_JNI(register_android_graphics_text_LineBreaker), |
| 134 | |
| 135 | REG_JNI(register_android_util_PathParser), |
| 136 | REG_JNI(register_android_view_RenderNode), |
| 137 | REG_JNI(register_android_view_DisplayListCanvas), |
| 138 | REG_JNI(register_android_view_FrameMetricsObserver), |
| 139 | REG_JNI(register_android_view_TextureLayer), |
| 140 | REG_JNI(register_android_view_ThreadedRenderer), |
| 141 | }; |
| 142 | |
| 143 | } // namespace android |
| 144 | |
| 145 | void init_android_graphics() { |
| 146 | SkGraphics::Init(); |
| 147 | } |
| 148 | |
| 149 | int register_android_graphics_classes(JNIEnv *env) { |
| 150 | for (size_t i = 0; i < NELEM(android::gRegJNI); i++) { |
| 151 | if (android::gRegJNI[i].mProc(env) < 0) { |
| 152 | #ifndef NDEBUG |
| 153 | __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, "JNI Error!!! %s failed to load\n", |
| 154 | android::gRegJNI[i].mName); |
| 155 | #endif |
| 156 | return -1; |
| 157 | } |
| 158 | } |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | using android::uirenderer::Properties; |
| 163 | using android::uirenderer::RenderPipelineType; |
| 164 | |
| 165 | void zygote_preload_graphics() { |
| 166 | if (Properties::peekRenderPipelineType() == RenderPipelineType::SkiaGL) { |
| 167 | eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 168 | } |
| 169 | } |