2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "OpenGLRenderer"
20 #include "GraphicsJNI.h"
21 #include <nativehelper/JNIHelp.h>
23 #include <android_runtime/AndroidRuntime.h>
25 #include <androidfw/ResourceTypes.h>
27 #include <cutils/properties.h>
32 #include <DisplayListCanvas.h>
34 #include <RenderNode.h>
35 #include <CanvasProperty.h>
37 #include <renderthread/RenderProxy.h>
39 #include "core_jni_helpers.h"
43 using namespace uirenderer;
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 static void android_view_DisplayListCanvas_setViewport(JNIEnv* env, jobject clazz,
54 jlong rendererPtr, jint width, jint height) {
55 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
56 renderer->setViewport(width, height);
59 static void android_view_DisplayListCanvas_setHighContrastText(JNIEnv* env, jobject clazz,
60 jlong rendererPtr, jboolean highContrastText) {
61 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
62 renderer->setHighContrastText(highContrastText);
65 static void android_view_DisplayListCanvas_insertReorderBarrier(JNIEnv* env, jobject clazz,
66 jlong rendererPtr, jboolean reorderEnable) {
67 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
68 renderer->insertReorderBarrier(reorderEnable);
71 static void android_view_DisplayListCanvas_prepare(JNIEnv* env, jobject clazz,
73 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
77 static void android_view_DisplayListCanvas_prepareDirty(JNIEnv* env, jobject clazz,
78 jlong rendererPtr, jint left, jint top, jint right, jint bottom) {
79 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
80 renderer->prepareDirty(left, top, right, bottom);
83 static void android_view_DisplayListCanvas_finish(JNIEnv* env, jobject clazz,
85 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 static void android_view_DisplayListCanvas_callDrawGLFunction(JNIEnv* env, jobject clazz,
94 jlong rendererPtr, jlong functorPtr) {
95 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
96 Functor* functor = reinterpret_cast<Functor*>(functorPtr);
97 renderer->callDrawGLFunction(functor);
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 static jint android_view_DisplayListCanvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) {
105 return Caches::getInstance().maxTextureSize;
108 static jint android_view_DisplayListCanvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) {
109 return Caches::getInstance().maxTextureSize;
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 static void android_view_DisplayListCanvas_drawPatch(JNIEnv* env, jobject clazz,
117 jlong rendererPtr, jobject jbitmap, jlong patchPtr,
118 float left, float top, float right, float bottom, jlong paintPtr) {
120 GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
121 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
122 Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(patchPtr);
123 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
124 renderer->drawPatch(bitmap, patch, left, top, right, bottom, paint);
127 static void android_view_DisplayListCanvas_drawRoundRectProps(JNIEnv* env, jobject clazz,
128 jlong rendererPtr, jlong leftPropPtr, jlong topPropPtr, jlong rightPropPtr,
129 jlong bottomPropPtr, jlong rxPropPtr, jlong ryPropPtr, jlong paintPropPtr) {
130 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
131 CanvasPropertyPrimitive* leftProp = reinterpret_cast<CanvasPropertyPrimitive*>(leftPropPtr);
132 CanvasPropertyPrimitive* topProp = reinterpret_cast<CanvasPropertyPrimitive*>(topPropPtr);
133 CanvasPropertyPrimitive* rightProp = reinterpret_cast<CanvasPropertyPrimitive*>(rightPropPtr);
134 CanvasPropertyPrimitive* bottomProp = reinterpret_cast<CanvasPropertyPrimitive*>(bottomPropPtr);
135 CanvasPropertyPrimitive* rxProp = reinterpret_cast<CanvasPropertyPrimitive*>(rxPropPtr);
136 CanvasPropertyPrimitive* ryProp = reinterpret_cast<CanvasPropertyPrimitive*>(ryPropPtr);
137 CanvasPropertyPaint* paintProp = reinterpret_cast<CanvasPropertyPaint*>(paintPropPtr);
138 renderer->drawRoundRect(leftProp, topProp, rightProp, bottomProp, rxProp, ryProp, paintProp);
141 static void android_view_DisplayListCanvas_drawCircleProps(JNIEnv* env, jobject clazz,
142 jlong rendererPtr, jlong xPropPtr, jlong yPropPtr, jlong radiusPropPtr, jlong paintPropPtr) {
143 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
144 CanvasPropertyPrimitive* xProp = reinterpret_cast<CanvasPropertyPrimitive*>(xPropPtr);
145 CanvasPropertyPrimitive* yProp = reinterpret_cast<CanvasPropertyPrimitive*>(yPropPtr);
146 CanvasPropertyPrimitive* radiusProp = reinterpret_cast<CanvasPropertyPrimitive*>(radiusPropPtr);
147 CanvasPropertyPaint* paintProp = reinterpret_cast<CanvasPropertyPaint*>(paintPropPtr);
148 renderer->drawCircle(xProp, yProp, radiusProp, paintProp);
151 static void android_view_DisplayListCanvas_drawRegionAsRects(JNIEnv* env, jobject clazz,
152 jlong rendererPtr, jlong regionPtr, jlong paintPtr) {
153 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
154 SkRegion* region = reinterpret_cast<SkRegion*>(regionPtr);
155 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
156 if (paint->getStyle() != Paint::kFill_Style ||
157 (paint->isAntiAlias() && !renderer->isCurrentTransformSimple())) {
158 SkRegion::Iterator it(*region);
160 const SkIRect& r = it.rect();
161 renderer->drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, *paint);
167 SkRegion::Iterator it(*region);
169 const SkIRect& r = it.rect();
172 rects.push(r.fRight);
173 rects.push(r.fBottom);
177 renderer->drawRects(rects.array(), count, paint);
181 // ----------------------------------------------------------------------------
183 // ----------------------------------------------------------------------------
185 static jlong android_view_DisplayListCanvas_finishRecording(JNIEnv* env,
186 jobject clazz, jlong rendererPtr) {
187 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
188 return reinterpret_cast<jlong>(renderer->finishRecording());
191 static jlong android_view_DisplayListCanvas_createDisplayListCanvas(JNIEnv* env, jobject clazz) {
192 return reinterpret_cast<jlong>(new DisplayListCanvas);
195 static void android_view_DisplayListCanvas_drawRenderNode(JNIEnv* env,
196 jobject clazz, jlong rendererPtr, jlong renderNodePtr) {
197 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
198 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
199 renderer->drawRenderNode(renderNode);
202 // ----------------------------------------------------------------------------
204 // ----------------------------------------------------------------------------
206 static void android_view_DisplayListCanvas_drawLayer(JNIEnv* env, jobject clazz,
207 jlong rendererPtr, jlong layerPtr, jfloat x, jfloat y) {
208 DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
209 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr);
210 renderer->drawLayer(layer, x, y);
213 // ----------------------------------------------------------------------------
215 // ----------------------------------------------------------------------------
217 static jboolean android_view_DisplayListCanvas_isAvailable(JNIEnv* env, jobject clazz) {
218 char prop[PROPERTY_VALUE_MAX];
219 if (property_get("ro.kernel.qemu", prop, NULL) == 0) {
220 // not in the emulator
223 // In the emulator this property will be set to 1 when hardware GLES is
224 // enabled, 0 otherwise. On old emulator versions it will be undefined.
225 property_get("ro.kernel.qemu.gles", prop, "0");
226 return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE;
229 // ----------------------------------------------------------------------------
231 // ----------------------------------------------------------------------------
234 android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) {
235 int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor);
236 android::uirenderer::renderthread::RenderProxy::dumpGraphicsMemory(fd);
239 // ----------------------------------------------------------------------------
241 // ----------------------------------------------------------------------------
243 const char* const kClassPathName = "android/view/DisplayListCanvas";
245 static JNINativeMethod gMethods[] = {
246 { "nIsAvailable", "()Z", (void*) android_view_DisplayListCanvas_isAvailable },
247 { "nSetViewport", "(JII)V", (void*) android_view_DisplayListCanvas_setViewport },
248 { "nSetHighContrastText","(JZ)V", (void*) android_view_DisplayListCanvas_setHighContrastText },
249 { "nInsertReorderBarrier","(JZ)V", (void*) android_view_DisplayListCanvas_insertReorderBarrier },
250 { "nPrepare", "(J)V", (void*) android_view_DisplayListCanvas_prepare },
251 { "nPrepareDirty", "(JIIII)V", (void*) android_view_DisplayListCanvas_prepareDirty },
252 { "nFinish", "(J)V", (void*) android_view_DisplayListCanvas_finish },
254 { "nCallDrawGLFunction", "(JJ)V", (void*) android_view_DisplayListCanvas_callDrawGLFunction },
256 { "nDrawPatch", "(JLandroid/graphics/Bitmap;JFFFFJ)V", (void*) android_view_DisplayListCanvas_drawPatch },
258 { "nDrawRects", "(JJJ)V", (void*) android_view_DisplayListCanvas_drawRegionAsRects },
259 { "nDrawRoundRect", "(JJJJJJJJ)V", (void*) android_view_DisplayListCanvas_drawRoundRectProps },
260 { "nDrawCircle", "(JJJJJ)V", (void*) android_view_DisplayListCanvas_drawCircleProps },
262 { "nFinishRecording", "(J)J", (void*) android_view_DisplayListCanvas_finishRecording },
263 { "nDrawRenderNode", "(JJ)V", (void*) android_view_DisplayListCanvas_drawRenderNode },
265 { "nCreateDisplayListCanvas", "()J", (void*) android_view_DisplayListCanvas_createDisplayListCanvas },
267 { "nDrawLayer", "(JJFF)V", (void*) android_view_DisplayListCanvas_drawLayer },
269 { "nGetMaximumTextureWidth", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureWidth },
270 { "nGetMaximumTextureHeight", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureHeight },
273 static JNINativeMethod gActivityThreadMethods[] = {
274 { "dumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V",
275 (void*) android_app_ActivityThread_dumpGraphics }
278 int register_android_view_DisplayListCanvas(JNIEnv* env) {
279 jclass clazz = FindClassOrDie(env, "android/graphics/Rect");
280 gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V");
282 return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
285 int register_android_app_ActivityThread(JNIEnv* env) {
286 return RegisterMethodsOrDie(env, "android/app/ActivityThread",
287 gActivityThreadMethods, NELEM(gActivityThreadMethods));