android_view_DisplayListCanvas.cpp revision 3aadd60521960be063ee06208562ccb63dc414e3
1/* 2 * Copyright (C) 2010 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#define LOG_TAG "OpenGLRenderer" 18 19#include "jni.h" 20#include "GraphicsJNI.h" 21#include <nativehelper/JNIHelp.h> 22 23#include <android_runtime/AndroidRuntime.h> 24 25#include <cutils/properties.h> 26 27#include <SkBitmap.h> 28#include <SkRegion.h> 29 30#include <DisplayListCanvas.h> 31#include <Rect.h> 32#include <RenderNode.h> 33#include <CanvasProperty.h> 34#include <Paint.h> 35#include <renderthread/RenderProxy.h> 36 37#include "core_jni_helpers.h" 38 39namespace android { 40 41using namespace uirenderer; 42 43static struct { 44 jmethodID set; 45} gRectClassInfo; 46 47// ---------------------------------------------------------------------------- 48// Setup 49// ---------------------------------------------------------------------------- 50 51static void android_view_DisplayListCanvas_insertReorderBarrier(JNIEnv* env, jobject clazz, 52 jlong rendererPtr, jboolean reorderEnable) { 53 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); 54 renderer->insertReorderBarrier(reorderEnable); 55} 56 57// ---------------------------------------------------------------------------- 58// Functor 59// ---------------------------------------------------------------------------- 60 61static void android_view_DisplayListCanvas_callDrawGLFunction(JNIEnv* env, jobject clazz, 62 jlong rendererPtr, jlong functorPtr) { 63 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); 64 Functor* functor = reinterpret_cast<Functor*>(functorPtr); 65 renderer->callDrawGLFunction(functor); 66} 67 68// ---------------------------------------------------------------------------- 69// Misc 70// ---------------------------------------------------------------------------- 71 72static jint android_view_DisplayListCanvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) { 73 return Caches::getInstance().maxTextureSize; 74} 75 76static jint android_view_DisplayListCanvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) { 77 return Caches::getInstance().maxTextureSize; 78} 79 80// ---------------------------------------------------------------------------- 81// Drawing 82// ---------------------------------------------------------------------------- 83 84static void android_view_DisplayListCanvas_drawRoundRectProps(JNIEnv* env, jobject clazz, 85 jlong rendererPtr, jlong leftPropPtr, jlong topPropPtr, jlong rightPropPtr, 86 jlong bottomPropPtr, jlong rxPropPtr, jlong ryPropPtr, jlong paintPropPtr) { 87 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); 88 CanvasPropertyPrimitive* leftProp = reinterpret_cast<CanvasPropertyPrimitive*>(leftPropPtr); 89 CanvasPropertyPrimitive* topProp = reinterpret_cast<CanvasPropertyPrimitive*>(topPropPtr); 90 CanvasPropertyPrimitive* rightProp = reinterpret_cast<CanvasPropertyPrimitive*>(rightPropPtr); 91 CanvasPropertyPrimitive* bottomProp = reinterpret_cast<CanvasPropertyPrimitive*>(bottomPropPtr); 92 CanvasPropertyPrimitive* rxProp = reinterpret_cast<CanvasPropertyPrimitive*>(rxPropPtr); 93 CanvasPropertyPrimitive* ryProp = reinterpret_cast<CanvasPropertyPrimitive*>(ryPropPtr); 94 CanvasPropertyPaint* paintProp = reinterpret_cast<CanvasPropertyPaint*>(paintPropPtr); 95 renderer->drawRoundRect(leftProp, topProp, rightProp, bottomProp, rxProp, ryProp, paintProp); 96} 97 98static void android_view_DisplayListCanvas_drawCircleProps(JNIEnv* env, jobject clazz, 99 jlong rendererPtr, jlong xPropPtr, jlong yPropPtr, jlong radiusPropPtr, jlong paintPropPtr) { 100 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); 101 CanvasPropertyPrimitive* xProp = reinterpret_cast<CanvasPropertyPrimitive*>(xPropPtr); 102 CanvasPropertyPrimitive* yProp = reinterpret_cast<CanvasPropertyPrimitive*>(yPropPtr); 103 CanvasPropertyPrimitive* radiusProp = reinterpret_cast<CanvasPropertyPrimitive*>(radiusPropPtr); 104 CanvasPropertyPaint* paintProp = reinterpret_cast<CanvasPropertyPaint*>(paintPropPtr); 105 renderer->drawCircle(xProp, yProp, radiusProp, paintProp); 106} 107 108// ---------------------------------------------------------------------------- 109// Display lists 110// ---------------------------------------------------------------------------- 111 112static jlong android_view_DisplayListCanvas_finishRecording(JNIEnv* env, 113 jobject clazz, jlong rendererPtr) { 114 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); 115 return reinterpret_cast<jlong>(renderer->finishRecording()); 116} 117 118static jlong android_view_DisplayListCanvas_createDisplayListCanvas(JNIEnv* env, jobject clazz, 119 jint width, jint height) { 120 return reinterpret_cast<jlong>(new DisplayListCanvas(width, height)); 121} 122 123static void android_view_DisplayListCanvas_resetDisplayListCanvas(JNIEnv* env, jobject clazz, 124 jlong rendererPtr, jint width, jint height) { 125 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); 126 renderer->reset(width, height); 127} 128 129 130static void android_view_DisplayListCanvas_drawRenderNode(JNIEnv* env, 131 jobject clazz, jlong rendererPtr, jlong renderNodePtr) { 132 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); 133 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); 134 renderer->drawRenderNode(renderNode); 135} 136 137// ---------------------------------------------------------------------------- 138// Layers 139// ---------------------------------------------------------------------------- 140 141static void android_view_DisplayListCanvas_drawLayer(JNIEnv* env, jobject clazz, 142 jlong rendererPtr, jlong layerPtr) { 143 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); 144 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); 145 renderer->drawLayer(layer); 146} 147 148// ---------------------------------------------------------------------------- 149// Common 150// ---------------------------------------------------------------------------- 151 152static jboolean android_view_DisplayListCanvas_isAvailable(JNIEnv* env, jobject clazz) { 153 char prop[PROPERTY_VALUE_MAX]; 154 if (property_get("ro.kernel.qemu", prop, NULL) == 0) { 155 // not in the emulator 156 return JNI_TRUE; 157 } 158 // In the emulator this property will be set to 1 when hardware GLES is 159 // enabled, 0 otherwise. On old emulator versions it will be undefined. 160 property_get("ro.kernel.qemu.gles", prop, "0"); 161 return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE; 162} 163 164// ---------------------------------------------------------------------------- 165// Logging 166// ---------------------------------------------------------------------------- 167 168static void 169android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { 170 int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); 171 android::uirenderer::renderthread::RenderProxy::dumpGraphicsMemory(fd); 172} 173 174// ---------------------------------------------------------------------------- 175// JNI Glue 176// ---------------------------------------------------------------------------- 177 178const char* const kClassPathName = "android/view/DisplayListCanvas"; 179 180static JNINativeMethod gMethods[] = { 181 { "nIsAvailable", "()Z", (void*) android_view_DisplayListCanvas_isAvailable }, 182 { "nInsertReorderBarrier","(JZ)V", (void*) android_view_DisplayListCanvas_insertReorderBarrier }, 183 184 { "nCallDrawGLFunction", "(JJ)V", (void*) android_view_DisplayListCanvas_callDrawGLFunction }, 185 186 { "nDrawRoundRect", "(JJJJJJJJ)V", (void*) android_view_DisplayListCanvas_drawRoundRectProps }, 187 { "nDrawCircle", "(JJJJJ)V", (void*) android_view_DisplayListCanvas_drawCircleProps }, 188 189 { "nFinishRecording", "(J)J", (void*) android_view_DisplayListCanvas_finishRecording }, 190 { "nDrawRenderNode", "(JJ)V", (void*) android_view_DisplayListCanvas_drawRenderNode }, 191 192 { "nCreateDisplayListCanvas", "(II)J", (void*) android_view_DisplayListCanvas_createDisplayListCanvas }, 193 { "nResetDisplayListCanvas", "(JII)V", (void*) android_view_DisplayListCanvas_resetDisplayListCanvas }, 194 195 { "nDrawLayer", "(JJ)V", (void*) android_view_DisplayListCanvas_drawLayer }, 196 197 { "nGetMaximumTextureWidth", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureWidth }, 198 { "nGetMaximumTextureHeight", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureHeight }, 199}; 200 201static JNINativeMethod gActivityThreadMethods[] = { 202 { "dumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V", 203 (void*) android_app_ActivityThread_dumpGraphics } 204}; 205 206int register_android_view_DisplayListCanvas(JNIEnv* env) { 207 jclass clazz = FindClassOrDie(env, "android/graphics/Rect"); 208 gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V"); 209 210 return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); 211} 212 213int register_android_app_ActivityThread(JNIEnv* env) { 214 return RegisterMethodsOrDie(env, "android/app/ActivityThread", 215 gActivityThreadMethods, NELEM(gActivityThreadMethods)); 216} 217 218}; 219