From c9070ebd13263a341511cf779087a46750021196 Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Mon, 9 Mar 2015 18:50:14 -0700 Subject: Rename and simplify DisplayList Canvas classes Change-Id: I49fd2ce02e01401209fe2a378e9f9547c7b27c61 --- core/java/android/view/DisplayListCanvas.java | 298 ++++++++++++++++++++ core/java/android/view/GLES20Canvas.java | 266 ------------------ core/java/android/view/GLES20RecordingCanvas.java | 65 ----- core/java/android/view/HardwareCanvas.java | 2 +- core/java/android/view/HardwareRenderer.java | 4 +- core/java/android/view/RenderNode.java | 6 +- core/java/android/view/RenderNodeAnimator.java | 4 +- core/jni/Android.mk | 18 +- core/jni/AndroidRuntime.cpp | 10 +- core/jni/android_view_DisplayListCanvas.cpp | 313 ++++++++++++++++++++++ core/jni/android_view_GLES20Canvas.cpp | 313 ---------------------- 11 files changed, 633 insertions(+), 666 deletions(-) create mode 100644 core/java/android/view/DisplayListCanvas.java delete mode 100644 core/java/android/view/GLES20Canvas.java delete mode 100644 core/java/android/view/GLES20RecordingCanvas.java create mode 100644 core/jni/android_view_DisplayListCanvas.cpp delete mode 100644 core/jni/android_view_GLES20Canvas.cpp (limited to 'core') diff --git a/core/java/android/view/DisplayListCanvas.java b/core/java/android/view/DisplayListCanvas.java new file mode 100644 index 0000000..90e1f86 --- /dev/null +++ b/core/java/android/view/DisplayListCanvas.java @@ -0,0 +1,298 @@ +/* + * Copyright (C) 2010 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.view; + +import android.annotation.NonNull; +import android.graphics.Bitmap; +import android.graphics.CanvasProperty; +import android.graphics.NinePatch; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.Picture; +import android.graphics.Rect; +import android.graphics.RectF; +import android.util.Pools.SynchronizedPool; + +/** + * An implementation of a GL canvas that records drawing operations. + * This is intended for use with a DisplayList. This class keeps a list of all the Paint and + * Bitmap objects that it draws, preventing the backing memory of Bitmaps from being freed while + * the DisplayList is still holding a native reference to the memory. + */ +class DisplayListCanvas extends HardwareCanvas { + // The recording canvas pool should be large enough to handle a deeply nested + // view hierarchy because display lists are generated recursively. + private static final int POOL_LIMIT = 25; + + private static final SynchronizedPool sPool = + new SynchronizedPool(POOL_LIMIT); + + RenderNode mNode; + private int mWidth; + private int mHeight; + + + static DisplayListCanvas obtain(@NonNull RenderNode node) { + if (node == null) throw new IllegalArgumentException("node cannot be null"); + DisplayListCanvas canvas = sPool.acquire(); + if (canvas == null) { + canvas = new DisplayListCanvas(); + } + canvas.mNode = node; + return canvas; + } + + void recycle() { + mNode = null; + sPool.release(this); + } + + long finishRecording() { + return nFinishRecording(mNativeCanvasWrapper); + } + + @Override + public boolean isRecordingFor(Object o) { + return o == mNode; + } + + /////////////////////////////////////////////////////////////////////////// + // JNI + /////////////////////////////////////////////////////////////////////////// + + private static native boolean nIsAvailable(); + private static boolean sIsAvailable = nIsAvailable(); + + static boolean isAvailable() { + return sIsAvailable; + } + + /////////////////////////////////////////////////////////////////////////// + // Constructors + /////////////////////////////////////////////////////////////////////////// + + + private DisplayListCanvas() { + super(nCreateDisplayListRenderer()); + } + + private static native long nCreateDisplayListRenderer(); + + public static void setProperty(String name, String value) { + nSetProperty(name, value); + } + + private static native void nSetProperty(String name, String value); + + /////////////////////////////////////////////////////////////////////////// + // Canvas management + /////////////////////////////////////////////////////////////////////////// + + @Override + public boolean isOpaque() { + return false; + } + + @Override + public int getWidth() { + return mWidth; + } + + @Override + public int getHeight() { + return mHeight; + } + + @Override + public int getMaximumBitmapWidth() { + return nGetMaximumTextureWidth(); + } + + @Override + public int getMaximumBitmapHeight() { + return nGetMaximumTextureHeight(); + } + + private static native int nGetMaximumTextureWidth(); + private static native int nGetMaximumTextureHeight(); + + /** + * Returns the native OpenGLRenderer object. + */ + long getRenderer() { + return mNativeCanvasWrapper; + } + + /////////////////////////////////////////////////////////////////////////// + // Setup + /////////////////////////////////////////////////////////////////////////// + + @Override + public void setViewport(int width, int height) { + mWidth = width; + mHeight = height; + + nSetViewport(mNativeCanvasWrapper, width, height); + } + + private static native void nSetViewport(long renderer, + int width, int height); + + @Override + public void setHighContrastText(boolean highContrastText) { + nSetHighContrastText(mNativeCanvasWrapper, highContrastText); + } + + private static native void nSetHighContrastText(long renderer, boolean highContrastText); + + @Override + public void insertReorderBarrier() { + nInsertReorderBarrier(mNativeCanvasWrapper, true); + } + + @Override + public void insertInorderBarrier() { + nInsertReorderBarrier(mNativeCanvasWrapper, false); + } + + private static native void nInsertReorderBarrier(long renderer, boolean enableReorder); + + @Override + public void onPreDraw(Rect dirty) { + if (dirty != null) { + nPrepareDirty(mNativeCanvasWrapper, dirty.left, dirty.top, dirty.right, dirty.bottom); + } else { + nPrepare(mNativeCanvasWrapper); + } + } + + private static native void nPrepare(long renderer); + private static native void nPrepareDirty(long renderer, int left, int top, int right, int bottom); + + @Override + public void onPostDraw() { + nFinish(mNativeCanvasWrapper); + } + + private static native void nFinish(long renderer); + + /////////////////////////////////////////////////////////////////////////// + // Functor + /////////////////////////////////////////////////////////////////////////// + + @Override + public void callDrawGLFunction2(long drawGLFunction) { + nCallDrawGLFunction(mNativeCanvasWrapper, drawGLFunction); + } + + private static native void nCallDrawGLFunction(long renderer, long drawGLFunction); + + /////////////////////////////////////////////////////////////////////////// + // Display list + /////////////////////////////////////////////////////////////////////////// + + protected static native long nFinishRecording(long renderer); + + @Override + public void drawRenderNode(RenderNode renderNode, int flags) { + nDrawRenderNode(mNativeCanvasWrapper, renderNode.getNativeDisplayList(), flags); + } + + private static native void nDrawRenderNode(long renderer, long renderNode, + int flags); + + /////////////////////////////////////////////////////////////////////////// + // Hardware layer + /////////////////////////////////////////////////////////////////////////// + + void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint) { + layer.setLayerPaint(paint); + nDrawLayer(mNativeCanvasWrapper, layer.getLayerHandle(), x, y); + } + + private static native void nDrawLayer(long renderer, long layer, float x, float y); + + /////////////////////////////////////////////////////////////////////////// + // Drawing + /////////////////////////////////////////////////////////////////////////// + + // TODO: move to Canvas.java + @Override + public void drawPatch(NinePatch patch, Rect dst, Paint paint) { + Bitmap bitmap = patch.getBitmap(); + throwIfCannotDraw(bitmap); + final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); + nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk, + dst.left, dst.top, dst.right, dst.bottom, nativePaint); + } + + // TODO: move to Canvas.java + @Override + public void drawPatch(NinePatch patch, RectF dst, Paint paint) { + Bitmap bitmap = patch.getBitmap(); + throwIfCannotDraw(bitmap); + final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); + nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk, + dst.left, dst.top, dst.right, dst.bottom, nativePaint); + } + + private static native void nDrawPatch(long renderer, long bitmap, long chunk, + float left, float top, float right, float bottom, long paint); + + @Override + public void drawCircle(CanvasProperty cx, CanvasProperty cy, + CanvasProperty radius, CanvasProperty paint) { + nDrawCircle(mNativeCanvasWrapper, cx.getNativeContainer(), cy.getNativeContainer(), + radius.getNativeContainer(), paint.getNativeContainer()); + } + + private static native void nDrawCircle(long renderer, long propCx, + long propCy, long propRadius, long propPaint); + + @Override + public void drawRoundRect(CanvasProperty left, CanvasProperty top, + CanvasProperty right, CanvasProperty bottom, CanvasProperty rx, + CanvasProperty ry, CanvasProperty paint) { + nDrawRoundRect(mNativeCanvasWrapper, left.getNativeContainer(), top.getNativeContainer(), + right.getNativeContainer(), bottom.getNativeContainer(), + rx.getNativeContainer(), ry.getNativeContainer(), + paint.getNativeContainer()); + } + + private static native void nDrawRoundRect(long renderer, long propLeft, long propTop, + long propRight, long propBottom, long propRx, long propRy, long propPaint); + + // TODO: move this optimization to Canvas.java + @Override + public void drawPath(Path path, Paint paint) { + if (path.isSimplePath) { + if (path.rects != null) { + nDrawRects(mNativeCanvasWrapper, path.rects.mNativeRegion, paint.getNativeInstance()); + } + } else { + super.drawPath(path, paint); + } + } + + private static native void nDrawRects(long renderer, long region, long paint); + + @Override + public void drawPicture(Picture picture) { + picture.endRecording(); + // TODO: Implement rendering + } +} diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java deleted file mode 100644 index 06e196d..0000000 --- a/core/java/android/view/GLES20Canvas.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (C) 2010 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.view; - -import android.graphics.Bitmap; -import android.graphics.CanvasProperty; -import android.graphics.NinePatch; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.Picture; -import android.graphics.Rect; -import android.graphics.RectF; - -/** - * An implementation of Canvas on top of OpenGL ES 2.0. - */ -class GLES20Canvas extends HardwareCanvas { - private int mWidth; - private int mHeight; - - private float[] mPoint; - private float[] mLine; - - private Rect mClipBounds; - private RectF mPathBounds; - - /////////////////////////////////////////////////////////////////////////// - // JNI - /////////////////////////////////////////////////////////////////////////// - - private static native boolean nIsAvailable(); - private static boolean sIsAvailable = nIsAvailable(); - - static boolean isAvailable() { - return sIsAvailable; - } - - /////////////////////////////////////////////////////////////////////////// - // Constructors - /////////////////////////////////////////////////////////////////////////// - - // TODO: Merge with GLES20RecordingCanvas - protected GLES20Canvas() { - super(nCreateDisplayListRenderer()); - } - - private static native long nCreateDisplayListRenderer(); - - public static void setProperty(String name, String value) { - nSetProperty(name, value); - } - - private static native void nSetProperty(String name, String value); - - /////////////////////////////////////////////////////////////////////////// - // Canvas management - /////////////////////////////////////////////////////////////////////////// - - @Override - public boolean isOpaque() { - return false; - } - - @Override - public int getWidth() { - return mWidth; - } - - @Override - public int getHeight() { - return mHeight; - } - - @Override - public int getMaximumBitmapWidth() { - return nGetMaximumTextureWidth(); - } - - @Override - public int getMaximumBitmapHeight() { - return nGetMaximumTextureHeight(); - } - - private static native int nGetMaximumTextureWidth(); - private static native int nGetMaximumTextureHeight(); - - /** - * Returns the native OpenGLRenderer object. - */ - long getRenderer() { - return mNativeCanvasWrapper; - } - - /////////////////////////////////////////////////////////////////////////// - // Setup - /////////////////////////////////////////////////////////////////////////// - - @Override - public void setViewport(int width, int height) { - mWidth = width; - mHeight = height; - - nSetViewport(mNativeCanvasWrapper, width, height); - } - - private static native void nSetViewport(long renderer, - int width, int height); - - @Override - public void setHighContrastText(boolean highContrastText) { - nSetHighContrastText(mNativeCanvasWrapper, highContrastText); - } - - private static native void nSetHighContrastText(long renderer, boolean highContrastText); - - @Override - public void insertReorderBarrier() { - nInsertReorderBarrier(mNativeCanvasWrapper, true); - } - - @Override - public void insertInorderBarrier() { - nInsertReorderBarrier(mNativeCanvasWrapper, false); - } - - private static native void nInsertReorderBarrier(long renderer, boolean enableReorder); - - @Override - public void onPreDraw(Rect dirty) { - if (dirty != null) { - nPrepareDirty(mNativeCanvasWrapper, dirty.left, dirty.top, dirty.right, dirty.bottom); - } else { - nPrepare(mNativeCanvasWrapper); - } - } - - private static native void nPrepare(long renderer); - private static native void nPrepareDirty(long renderer, int left, int top, int right, int bottom); - - @Override - public void onPostDraw() { - nFinish(mNativeCanvasWrapper); - } - - private static native void nFinish(long renderer); - - /////////////////////////////////////////////////////////////////////////// - // Functor - /////////////////////////////////////////////////////////////////////////// - - @Override - public void callDrawGLFunction2(long drawGLFunction) { - nCallDrawGLFunction(mNativeCanvasWrapper, drawGLFunction); - } - - private static native void nCallDrawGLFunction(long renderer, long drawGLFunction); - - /////////////////////////////////////////////////////////////////////////// - // Display list - /////////////////////////////////////////////////////////////////////////// - - protected static native long nFinishRecording(long renderer); - - @Override - public void drawRenderNode(RenderNode renderNode, int flags) { - nDrawRenderNode(mNativeCanvasWrapper, renderNode.getNativeDisplayList(), flags); - } - - private static native void nDrawRenderNode(long renderer, long renderNode, - int flags); - - /////////////////////////////////////////////////////////////////////////// - // Hardware layer - /////////////////////////////////////////////////////////////////////////// - - void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint) { - layer.setLayerPaint(paint); - nDrawLayer(mNativeCanvasWrapper, layer.getLayerHandle(), x, y); - } - - private static native void nDrawLayer(long renderer, long layer, float x, float y); - - /////////////////////////////////////////////////////////////////////////// - // Drawing - /////////////////////////////////////////////////////////////////////////// - - // TODO: move to Canvas.java - @Override - public void drawPatch(NinePatch patch, Rect dst, Paint paint) { - Bitmap bitmap = patch.getBitmap(); - throwIfCannotDraw(bitmap); - final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); - nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk, - dst.left, dst.top, dst.right, dst.bottom, nativePaint); - } - - // TODO: move to Canvas.java - @Override - public void drawPatch(NinePatch patch, RectF dst, Paint paint) { - Bitmap bitmap = patch.getBitmap(); - throwIfCannotDraw(bitmap); - final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); - nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk, - dst.left, dst.top, dst.right, dst.bottom, nativePaint); - } - - private static native void nDrawPatch(long renderer, long bitmap, long chunk, - float left, float top, float right, float bottom, long paint); - - @Override - public void drawCircle(CanvasProperty cx, CanvasProperty cy, - CanvasProperty radius, CanvasProperty paint) { - nDrawCircle(mNativeCanvasWrapper, cx.getNativeContainer(), cy.getNativeContainer(), - radius.getNativeContainer(), paint.getNativeContainer()); - } - - private static native void nDrawCircle(long renderer, long propCx, - long propCy, long propRadius, long propPaint); - - @Override - public void drawRoundRect(CanvasProperty left, CanvasProperty top, - CanvasProperty right, CanvasProperty bottom, CanvasProperty rx, - CanvasProperty ry, CanvasProperty paint) { - nDrawRoundRect(mNativeCanvasWrapper, left.getNativeContainer(), top.getNativeContainer(), - right.getNativeContainer(), bottom.getNativeContainer(), - rx.getNativeContainer(), ry.getNativeContainer(), - paint.getNativeContainer()); - } - - private static native void nDrawRoundRect(long renderer, long propLeft, long propTop, - long propRight, long propBottom, long propRx, long propRy, long propPaint); - - // TODO: move this optimization to Canvas.java - @Override - public void drawPath(Path path, Paint paint) { - if (path.isSimplePath) { - if (path.rects != null) { - nDrawRects(mNativeCanvasWrapper, path.rects.mNativeRegion, paint.getNativeInstance()); - } - } else { - super.drawPath(path, paint); - } - } - - private static native void nDrawRects(long renderer, long region, long paint); - - @Override - public void drawPicture(Picture picture) { - picture.endRecording(); - // TODO: Implement rendering - } -} diff --git a/core/java/android/view/GLES20RecordingCanvas.java b/core/java/android/view/GLES20RecordingCanvas.java deleted file mode 100644 index 6c780c9..0000000 --- a/core/java/android/view/GLES20RecordingCanvas.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2010 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.view; - -import android.annotation.NonNull; -import android.util.Pools.SynchronizedPool; - -/** - * An implementation of a GL canvas that records drawing operations. - * This is intended for use with a DisplayList. This class keeps a list of all the Paint and - * Bitmap objects that it draws, preventing the backing memory of Bitmaps from being freed while - * the DisplayList is still holding a native reference to the memory. - */ -class GLES20RecordingCanvas extends GLES20Canvas { - // The recording canvas pool should be large enough to handle a deeply nested - // view hierarchy because display lists are generated recursively. - private static final int POOL_LIMIT = 25; - - private static final SynchronizedPool sPool = - new SynchronizedPool(POOL_LIMIT); - - RenderNode mNode; - - private GLES20RecordingCanvas() { - super(); - } - - static GLES20RecordingCanvas obtain(@NonNull RenderNode node) { - if (node == null) throw new IllegalArgumentException("node cannot be null"); - GLES20RecordingCanvas canvas = sPool.acquire(); - if (canvas == null) { - canvas = new GLES20RecordingCanvas(); - } - canvas.mNode = node; - return canvas; - } - - void recycle() { - mNode = null; - sPool.release(this); - } - - long finishRecording() { - return nFinishRecording(mNativeCanvasWrapper); - } - - @Override - public boolean isRecordingFor(Object o) { - return o == mNode; - } -} diff --git a/core/java/android/view/HardwareCanvas.java b/core/java/android/view/HardwareCanvas.java index cdb350f..fc2b55b 100644 --- a/core/java/android/view/HardwareCanvas.java +++ b/core/java/android/view/HardwareCanvas.java @@ -119,6 +119,6 @@ public abstract class HardwareCanvas extends Canvas { CanvasProperty paint); public static void setProperty(String name, String value) { - GLES20Canvas.setProperty(name, value); + DisplayListCanvas.setProperty(name, value); } } diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java index 9921be2..afa7f51 100644 --- a/core/java/android/view/HardwareRenderer.java +++ b/core/java/android/view/HardwareRenderer.java @@ -205,7 +205,7 @@ public abstract class HardwareRenderer { * false otherwise */ public static boolean isAvailable() { - return GLES20Canvas.isAvailable(); + return DisplayListCanvas.isAvailable(); } /** @@ -423,7 +423,7 @@ public abstract class HardwareRenderer { */ static HardwareRenderer create(Context context, boolean translucent) { HardwareRenderer renderer = null; - if (GLES20Canvas.isAvailable()) { + if (DisplayListCanvas.isAvailable()) { renderer = new ThreadedRenderer(context, translucent); } return renderer; diff --git a/core/java/android/view/RenderNode.java b/core/java/android/view/RenderNode.java index 09eb486..38867a8 100644 --- a/core/java/android/view/RenderNode.java +++ b/core/java/android/view/RenderNode.java @@ -225,7 +225,7 @@ public class RenderNode { * @see #isValid() */ public HardwareCanvas start(int width, int height) { - HardwareCanvas canvas = GLES20RecordingCanvas.obtain(this); + HardwareCanvas canvas = DisplayListCanvas.obtain(this); canvas.setViewport(width, height); // The dirty rect should always be null for a display list canvas.onPreDraw(null); @@ -241,11 +241,11 @@ public class RenderNode { * @see #isValid() */ public void end(HardwareCanvas endCanvas) { - if (!(endCanvas instanceof GLES20RecordingCanvas)) { + if (!(endCanvas instanceof DisplayListCanvas)) { throw new IllegalArgumentException("Passed an invalid canvas to end!"); } - GLES20RecordingCanvas canvas = (GLES20RecordingCanvas) endCanvas; + DisplayListCanvas canvas = (DisplayListCanvas) endCanvas; canvas.onPostDraw(); long renderNodeData = canvas.finishRecording(); nSetDisplayListData(mNativeRenderNode, renderNodeData); diff --git a/core/java/android/view/RenderNodeAnimator.java b/core/java/android/view/RenderNodeAnimator.java index 7b35a3b..379796d 100644 --- a/core/java/android/view/RenderNodeAnimator.java +++ b/core/java/android/view/RenderNodeAnimator.java @@ -283,10 +283,10 @@ public class RenderNodeAnimator extends Animator { } public void setTarget(Canvas canvas) { - if (!(canvas instanceof GLES20RecordingCanvas)) { + if (!(canvas instanceof DisplayListCanvas)) { throw new IllegalArgumentException("Not a GLES20RecordingCanvas"); } - final GLES20RecordingCanvas recordingCanvas = (GLES20RecordingCanvas) canvas; + final DisplayListCanvas recordingCanvas = (DisplayListCanvas) canvas; setTarget(recordingCanvas.mNode); } diff --git a/core/jni/Android.mk b/core/jni/Android.mk index 97744ea..9d76335 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -41,25 +41,25 @@ LOCAL_SRC_FILES:= \ android_database_SQLiteDebug.cpp \ android_emoji_EmojiFactory.cpp \ android_view_DisplayEventReceiver.cpp \ - android_view_Surface.cpp \ - android_view_SurfaceControl.cpp \ - android_view_SurfaceSession.cpp \ - android_view_TextureView.cpp \ + android_view_DisplayListCanvas.cpp \ + android_view_GraphicBuffer.cpp \ + android_view_HardwareLayer.cpp \ android_view_InputChannel.cpp \ android_view_InputDevice.cpp \ android_view_InputEventReceiver.cpp \ android_view_InputEventSender.cpp \ android_view_InputQueue.cpp \ - android_view_KeyEvent.cpp \ android_view_KeyCharacterMap.cpp \ - android_view_GraphicBuffer.cpp \ - android_view_GLES20Canvas.cpp \ - android_view_HardwareLayer.cpp \ - android_view_ThreadedRenderer.cpp \ + android_view_KeyEvent.cpp \ android_view_MotionEvent.cpp \ android_view_PointerIcon.cpp \ android_view_RenderNode.cpp \ android_view_RenderNodeAnimator.cpp \ + android_view_Surface.cpp \ + android_view_SurfaceControl.cpp \ + android_view_SurfaceSession.cpp \ + android_view_TextureView.cpp \ + android_view_ThreadedRenderer.cpp \ android_view_VelocityTracker.cpp \ android_text_AndroidCharacter.cpp \ android_text_AndroidBidi.cpp \ diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 77afd05..ad52e3f 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -127,16 +127,16 @@ extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env); extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env); extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env); extern int register_android_view_DisplayEventReceiver(JNIEnv* env); -extern int register_android_view_RenderNode(JNIEnv* env); -extern int register_android_view_RenderNodeAnimator(JNIEnv* env); +extern int register_android_view_DisplayListCanvas(JNIEnv* env); extern int register_android_view_GraphicBuffer(JNIEnv* env); -extern int register_android_view_GLES20Canvas(JNIEnv* env); extern int register_android_view_HardwareLayer(JNIEnv* env); -extern int register_android_view_ThreadedRenderer(JNIEnv* env); +extern int register_android_view_RenderNode(JNIEnv* env); +extern int register_android_view_RenderNodeAnimator(JNIEnv* env); extern int register_android_view_Surface(JNIEnv* env); extern int register_android_view_SurfaceControl(JNIEnv* env); extern int register_android_view_SurfaceSession(JNIEnv* env); extern int register_android_view_TextureView(JNIEnv* env); +extern int register_android_view_ThreadedRenderer(JNIEnv* env); extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env); extern int register_android_database_CursorWindow(JNIEnv* env); extern int register_android_database_SQLiteConnection(JNIEnv* env); @@ -1179,7 +1179,7 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_view_RenderNode), REG_JNI(register_android_view_RenderNodeAnimator), REG_JNI(register_android_view_GraphicBuffer), - REG_JNI(register_android_view_GLES20Canvas), + REG_JNI(register_android_view_DisplayListCanvas), REG_JNI(register_android_view_HardwareLayer), REG_JNI(register_android_view_ThreadedRenderer), REG_JNI(register_android_view_Surface), diff --git a/core/jni/android_view_DisplayListCanvas.cpp b/core/jni/android_view_DisplayListCanvas.cpp new file mode 100644 index 0000000..f2e6c4b --- /dev/null +++ b/core/jni/android_view_DisplayListCanvas.cpp @@ -0,0 +1,313 @@ +/* + * Copyright (C) 2010 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. + */ + +#define LOG_TAG "OpenGLRenderer" + +#include "jni.h" +#include "GraphicsJNI.h" +#include + +#include + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "core_jni_helpers.h" + +namespace android { + +using namespace uirenderer; + +static struct { + jmethodID set; +} gRectClassInfo; + +// ---------------------------------------------------------------------------- +// Setup +// ---------------------------------------------------------------------------- + +static void android_view_DisplayListCanvas_setViewport(JNIEnv* env, jobject clazz, + jlong rendererPtr, jint width, jint height) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + renderer->setViewport(width, height); +} + +static void android_view_DisplayListCanvas_setHighContrastText(JNIEnv* env, jobject clazz, + jlong rendererPtr, jboolean highContrastText) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + renderer->setHighContrastText(highContrastText); +} + +static void android_view_DisplayListCanvas_insertReorderBarrier(JNIEnv* env, jobject clazz, + jlong rendererPtr, jboolean reorderEnable) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + renderer->insertReorderBarrier(reorderEnable); +} + +static void android_view_DisplayListCanvas_prepare(JNIEnv* env, jobject clazz, + jlong rendererPtr) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + renderer->prepare(); +} + +static void android_view_DisplayListCanvas_prepareDirty(JNIEnv* env, jobject clazz, + jlong rendererPtr, jint left, jint top, jint right, jint bottom) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + renderer->prepareDirty(left, top, right, bottom); +} + +static void android_view_DisplayListCanvas_finish(JNIEnv* env, jobject clazz, + jlong rendererPtr) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + renderer->finish(); +} + +static void android_view_DisplayListCanvas_setProperty(JNIEnv* env, + jobject clazz, jstring name, jstring value) { + if (!Caches::hasInstance()) { + ALOGW("can't set property, no Caches instance"); + return; + } + + if (name == NULL || value == NULL) { + ALOGW("can't set prop, null passed"); + } + + const char* nameCharArray = env->GetStringUTFChars(name, NULL); + const char* valueCharArray = env->GetStringUTFChars(value, NULL); + Caches::getInstance().setTempProperty(nameCharArray, valueCharArray); + env->ReleaseStringUTFChars(name, nameCharArray); + env->ReleaseStringUTFChars(name, valueCharArray); +} + +// ---------------------------------------------------------------------------- +// Functor +// ---------------------------------------------------------------------------- + +static void android_view_DisplayListCanvas_callDrawGLFunction(JNIEnv* env, jobject clazz, + jlong rendererPtr, jlong functorPtr) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + Functor* functor = reinterpret_cast(functorPtr); + android::uirenderer::Rect dirty; + renderer->callDrawGLFunction(functor, dirty); +} + +// ---------------------------------------------------------------------------- +// Misc +// ---------------------------------------------------------------------------- + +static jint android_view_DisplayListCanvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) { + return Caches::getInstance().maxTextureSize; +} + +static jint android_view_DisplayListCanvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) { + return Caches::getInstance().maxTextureSize; +} + +// ---------------------------------------------------------------------------- +// Drawing +// ---------------------------------------------------------------------------- + +static void android_view_DisplayListCanvas_drawPatch(JNIEnv* env, jobject clazz, + jlong rendererPtr, jlong bitmapPtr, jlong patchPtr, + float left, float top, float right, float bottom, jlong paintPtr) { + SkBitmap* bitmap = reinterpret_cast(bitmapPtr); + + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + Res_png_9patch* patch = reinterpret_cast(patchPtr); + Paint* paint = reinterpret_cast(paintPtr); + renderer->drawPatch(bitmap, patch, left, top, right, bottom, paint); +} + +static void android_view_DisplayListCanvas_drawRoundRectProps(JNIEnv* env, jobject clazz, + jlong rendererPtr, jlong leftPropPtr, jlong topPropPtr, jlong rightPropPtr, + jlong bottomPropPtr, jlong rxPropPtr, jlong ryPropPtr, jlong paintPropPtr) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + CanvasPropertyPrimitive* leftProp = reinterpret_cast(leftPropPtr); + CanvasPropertyPrimitive* topProp = reinterpret_cast(topPropPtr); + CanvasPropertyPrimitive* rightProp = reinterpret_cast(rightPropPtr); + CanvasPropertyPrimitive* bottomProp = reinterpret_cast(bottomPropPtr); + CanvasPropertyPrimitive* rxProp = reinterpret_cast(rxPropPtr); + CanvasPropertyPrimitive* ryProp = reinterpret_cast(ryPropPtr); + CanvasPropertyPaint* paintProp = reinterpret_cast(paintPropPtr); + renderer->drawRoundRect(leftProp, topProp, rightProp, bottomProp, rxProp, ryProp, paintProp); +} + +static void android_view_DisplayListCanvas_drawCircleProps(JNIEnv* env, jobject clazz, + jlong rendererPtr, jlong xPropPtr, jlong yPropPtr, jlong radiusPropPtr, jlong paintPropPtr) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + CanvasPropertyPrimitive* xProp = reinterpret_cast(xPropPtr); + CanvasPropertyPrimitive* yProp = reinterpret_cast(yPropPtr); + CanvasPropertyPrimitive* radiusProp = reinterpret_cast(radiusPropPtr); + CanvasPropertyPaint* paintProp = reinterpret_cast(paintPropPtr); + renderer->drawCircle(xProp, yProp, radiusProp, paintProp); +} + +static void android_view_DisplayListCanvas_drawRegionAsRects(JNIEnv* env, jobject clazz, + jlong rendererPtr, jlong regionPtr, jlong paintPtr) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + SkRegion* region = reinterpret_cast(regionPtr); + Paint* paint = reinterpret_cast(paintPtr); + if (paint->getStyle() != Paint::kFill_Style || + (paint->isAntiAlias() && !renderer->isCurrentTransformSimple())) { + SkRegion::Iterator it(*region); + while (!it.done()) { + const SkIRect& r = it.rect(); + renderer->drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, *paint); + it.next(); + } + } else { + int count = 0; + Vector rects; + SkRegion::Iterator it(*region); + while (!it.done()) { + const SkIRect& r = it.rect(); + rects.push(r.fLeft); + rects.push(r.fTop); + rects.push(r.fRight); + rects.push(r.fBottom); + count += 4; + it.next(); + } + renderer->drawRects(rects.array(), count, paint); + } +} + +// ---------------------------------------------------------------------------- +// Display lists +// ---------------------------------------------------------------------------- + +static jlong android_view_DisplayListCanvas_finishRecording(JNIEnv* env, + jobject clazz, jlong rendererPtr) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + return reinterpret_cast(renderer->finishRecording()); +} + +static jlong android_view_DisplayListCanvas_createDisplayListRenderer(JNIEnv* env, jobject clazz) { + return reinterpret_cast(new DisplayListRenderer); +} + +static void android_view_DisplayListCanvas_drawRenderNode(JNIEnv* env, + jobject clazz, jlong rendererPtr, jlong renderNodePtr, + jint flags) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + RenderNode* renderNode = reinterpret_cast(renderNodePtr); + android::uirenderer::Rect bounds; + renderer->drawRenderNode(renderNode, bounds, flags); +} + +// ---------------------------------------------------------------------------- +// Layers +// ---------------------------------------------------------------------------- + +static void android_view_DisplayListCanvas_drawLayer(JNIEnv* env, jobject clazz, + jlong rendererPtr, jlong layerPtr, jfloat x, jfloat y) { + DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); + DeferredLayerUpdater* layer = reinterpret_cast(layerPtr); + renderer->drawLayer(layer, x, y); +} + +// ---------------------------------------------------------------------------- +// Common +// ---------------------------------------------------------------------------- + +static jboolean android_view_DisplayListCanvas_isAvailable(JNIEnv* env, jobject clazz) { + char prop[PROPERTY_VALUE_MAX]; + if (property_get("ro.kernel.qemu", prop, NULL) == 0) { + // not in the emulator + return JNI_TRUE; + } + // In the emulator this property will be set to 1 when hardware GLES is + // enabled, 0 otherwise. On old emulator versions it will be undefined. + property_get("ro.kernel.qemu.gles", prop, "0"); + return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE; +} + +// ---------------------------------------------------------------------------- +// Logging +// ---------------------------------------------------------------------------- + +static void +android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { + int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); + android::uirenderer::renderthread::RenderProxy::dumpGraphicsMemory(fd); +} + +// ---------------------------------------------------------------------------- +// JNI Glue +// ---------------------------------------------------------------------------- + +const char* const kClassPathName = "android/view/DisplayListCanvas"; + +static JNINativeMethod gMethods[] = { + { "nIsAvailable", "()Z", (void*) android_view_DisplayListCanvas_isAvailable }, + { "nSetViewport", "(JII)V", (void*) android_view_DisplayListCanvas_setViewport }, + { "nSetHighContrastText","(JZ)V", (void*) android_view_DisplayListCanvas_setHighContrastText }, + { "nInsertReorderBarrier","(JZ)V", (void*) android_view_DisplayListCanvas_insertReorderBarrier }, + { "nPrepare", "(J)V", (void*) android_view_DisplayListCanvas_prepare }, + { "nPrepareDirty", "(JIIII)V", (void*) android_view_DisplayListCanvas_prepareDirty }, + { "nFinish", "(J)V", (void*) android_view_DisplayListCanvas_finish }, + { "nSetProperty", "(Ljava/lang/String;Ljava/lang/String;)V", + (void*) android_view_DisplayListCanvas_setProperty }, + + { "nCallDrawGLFunction", "(JJ)V", (void*) android_view_DisplayListCanvas_callDrawGLFunction }, + + { "nDrawPatch", "(JJJFFFFJ)V", (void*) android_view_DisplayListCanvas_drawPatch }, + + { "nDrawRects", "(JJJ)V", (void*) android_view_DisplayListCanvas_drawRegionAsRects }, + { "nDrawRoundRect", "(JJJJJJJJ)V", (void*) android_view_DisplayListCanvas_drawRoundRectProps }, + { "nDrawCircle", "(JJJJJ)V", (void*) android_view_DisplayListCanvas_drawCircleProps }, + + { "nFinishRecording", "(J)J", (void*) android_view_DisplayListCanvas_finishRecording }, + { "nDrawRenderNode", "(JJI)V", (void*) android_view_DisplayListCanvas_drawRenderNode }, + + { "nCreateDisplayListRenderer", "()J", (void*) android_view_DisplayListCanvas_createDisplayListRenderer }, + + { "nDrawLayer", "(JJFF)V", (void*) android_view_DisplayListCanvas_drawLayer }, + + { "nGetMaximumTextureWidth", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureWidth }, + { "nGetMaximumTextureHeight", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureHeight }, +}; + +static JNINativeMethod gActivityThreadMethods[] = { + { "dumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V", + (void*) android_app_ActivityThread_dumpGraphics } +}; + +int register_android_view_DisplayListCanvas(JNIEnv* env) { + jclass clazz = FindClassOrDie(env, "android/graphics/Rect"); + gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V"); + + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); +} + +int register_android_app_ActivityThread(JNIEnv* env) { + return RegisterMethodsOrDie(env, "android/app/ActivityThread", + gActivityThreadMethods, NELEM(gActivityThreadMethods)); +} + +}; diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp deleted file mode 100644 index 0bee7ae..0000000 --- a/core/jni/android_view_GLES20Canvas.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Copyright (C) 2010 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. - */ - -#define LOG_TAG "OpenGLRenderer" - -#include "jni.h" -#include "GraphicsJNI.h" -#include - -#include - -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "core_jni_helpers.h" - -namespace android { - -using namespace uirenderer; - -static struct { - jmethodID set; -} gRectClassInfo; - -// ---------------------------------------------------------------------------- -// Setup -// ---------------------------------------------------------------------------- - -static void android_view_GLES20Canvas_setViewport(JNIEnv* env, jobject clazz, - jlong rendererPtr, jint width, jint height) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - renderer->setViewport(width, height); -} - -static void android_view_GLES20Canvas_setHighContrastText(JNIEnv* env, jobject clazz, - jlong rendererPtr, jboolean highContrastText) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - renderer->setHighContrastText(highContrastText); -} - -static void android_view_GLES20Canvas_insertReorderBarrier(JNIEnv* env, jobject clazz, - jlong rendererPtr, jboolean reorderEnable) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - renderer->insertReorderBarrier(reorderEnable); -} - -static void android_view_GLES20Canvas_prepare(JNIEnv* env, jobject clazz, - jlong rendererPtr) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - renderer->prepare(); -} - -static void android_view_GLES20Canvas_prepareDirty(JNIEnv* env, jobject clazz, - jlong rendererPtr, jint left, jint top, jint right, jint bottom) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - renderer->prepareDirty(left, top, right, bottom); -} - -static void android_view_GLES20Canvas_finish(JNIEnv* env, jobject clazz, - jlong rendererPtr) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - renderer->finish(); -} - -static void android_view_GLES20Canvas_setProperty(JNIEnv* env, - jobject clazz, jstring name, jstring value) { - if (!Caches::hasInstance()) { - ALOGW("can't set property, no Caches instance"); - return; - } - - if (name == NULL || value == NULL) { - ALOGW("can't set prop, null passed"); - } - - const char* nameCharArray = env->GetStringUTFChars(name, NULL); - const char* valueCharArray = env->GetStringUTFChars(value, NULL); - Caches::getInstance().setTempProperty(nameCharArray, valueCharArray); - env->ReleaseStringUTFChars(name, nameCharArray); - env->ReleaseStringUTFChars(name, valueCharArray); -} - -// ---------------------------------------------------------------------------- -// Functor -// ---------------------------------------------------------------------------- - -static void android_view_GLES20Canvas_callDrawGLFunction(JNIEnv* env, jobject clazz, - jlong rendererPtr, jlong functorPtr) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - Functor* functor = reinterpret_cast(functorPtr); - android::uirenderer::Rect dirty; - renderer->callDrawGLFunction(functor, dirty); -} - -// ---------------------------------------------------------------------------- -// Misc -// ---------------------------------------------------------------------------- - -static jint android_view_GLES20Canvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) { - return Caches::getInstance().maxTextureSize; -} - -static jint android_view_GLES20Canvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) { - return Caches::getInstance().maxTextureSize; -} - -// ---------------------------------------------------------------------------- -// Drawing -// ---------------------------------------------------------------------------- - -static void android_view_GLES20Canvas_drawPatch(JNIEnv* env, jobject clazz, - jlong rendererPtr, jlong bitmapPtr, jlong patchPtr, - float left, float top, float right, float bottom, jlong paintPtr) { - SkBitmap* bitmap = reinterpret_cast(bitmapPtr); - - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - Res_png_9patch* patch = reinterpret_cast(patchPtr); - Paint* paint = reinterpret_cast(paintPtr); - renderer->drawPatch(bitmap, patch, left, top, right, bottom, paint); -} - -static void android_view_GLES20Canvas_drawRoundRectProps(JNIEnv* env, jobject clazz, - jlong rendererPtr, jlong leftPropPtr, jlong topPropPtr, jlong rightPropPtr, - jlong bottomPropPtr, jlong rxPropPtr, jlong ryPropPtr, jlong paintPropPtr) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - CanvasPropertyPrimitive* leftProp = reinterpret_cast(leftPropPtr); - CanvasPropertyPrimitive* topProp = reinterpret_cast(topPropPtr); - CanvasPropertyPrimitive* rightProp = reinterpret_cast(rightPropPtr); - CanvasPropertyPrimitive* bottomProp = reinterpret_cast(bottomPropPtr); - CanvasPropertyPrimitive* rxProp = reinterpret_cast(rxPropPtr); - CanvasPropertyPrimitive* ryProp = reinterpret_cast(ryPropPtr); - CanvasPropertyPaint* paintProp = reinterpret_cast(paintPropPtr); - renderer->drawRoundRect(leftProp, topProp, rightProp, bottomProp, rxProp, ryProp, paintProp); -} - -static void android_view_GLES20Canvas_drawCircleProps(JNIEnv* env, jobject clazz, - jlong rendererPtr, jlong xPropPtr, jlong yPropPtr, jlong radiusPropPtr, jlong paintPropPtr) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - CanvasPropertyPrimitive* xProp = reinterpret_cast(xPropPtr); - CanvasPropertyPrimitive* yProp = reinterpret_cast(yPropPtr); - CanvasPropertyPrimitive* radiusProp = reinterpret_cast(radiusPropPtr); - CanvasPropertyPaint* paintProp = reinterpret_cast(paintPropPtr); - renderer->drawCircle(xProp, yProp, radiusProp, paintProp); -} - -static void android_view_GLES20Canvas_drawRegionAsRects(JNIEnv* env, jobject clazz, - jlong rendererPtr, jlong regionPtr, jlong paintPtr) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - SkRegion* region = reinterpret_cast(regionPtr); - Paint* paint = reinterpret_cast(paintPtr); - if (paint->getStyle() != Paint::kFill_Style || - (paint->isAntiAlias() && !renderer->isCurrentTransformSimple())) { - SkRegion::Iterator it(*region); - while (!it.done()) { - const SkIRect& r = it.rect(); - renderer->drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, *paint); - it.next(); - } - } else { - int count = 0; - Vector rects; - SkRegion::Iterator it(*region); - while (!it.done()) { - const SkIRect& r = it.rect(); - rects.push(r.fLeft); - rects.push(r.fTop); - rects.push(r.fRight); - rects.push(r.fBottom); - count += 4; - it.next(); - } - renderer->drawRects(rects.array(), count, paint); - } -} - -// ---------------------------------------------------------------------------- -// Display lists -// ---------------------------------------------------------------------------- - -static jlong android_view_GLES20Canvas_finishRecording(JNIEnv* env, - jobject clazz, jlong rendererPtr) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - return reinterpret_cast(renderer->finishRecording()); -} - -static jlong android_view_GLES20Canvas_createDisplayListRenderer(JNIEnv* env, jobject clazz) { - return reinterpret_cast(new DisplayListRenderer); -} - -static void android_view_GLES20Canvas_drawRenderNode(JNIEnv* env, - jobject clazz, jlong rendererPtr, jlong renderNodePtr, - jint flags) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - RenderNode* renderNode = reinterpret_cast(renderNodePtr); - android::uirenderer::Rect bounds; - renderer->drawRenderNode(renderNode, bounds, flags); -} - -// ---------------------------------------------------------------------------- -// Layers -// ---------------------------------------------------------------------------- - -static void android_view_GLES20Canvas_drawLayer(JNIEnv* env, jobject clazz, - jlong rendererPtr, jlong layerPtr, jfloat x, jfloat y) { - DisplayListRenderer* renderer = reinterpret_cast(rendererPtr); - DeferredLayerUpdater* layer = reinterpret_cast(layerPtr); - renderer->drawLayer(layer, x, y); -} - -// ---------------------------------------------------------------------------- -// Common -// ---------------------------------------------------------------------------- - -static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) { - char prop[PROPERTY_VALUE_MAX]; - if (property_get("ro.kernel.qemu", prop, NULL) == 0) { - // not in the emulator - return JNI_TRUE; - } - // In the emulator this property will be set to 1 when hardware GLES is - // enabled, 0 otherwise. On old emulator versions it will be undefined. - property_get("ro.kernel.qemu.gles", prop, "0"); - return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE; -} - -// ---------------------------------------------------------------------------- -// Logging -// ---------------------------------------------------------------------------- - -static void -android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { - int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); - android::uirenderer::renderthread::RenderProxy::dumpGraphicsMemory(fd); -} - -// ---------------------------------------------------------------------------- -// JNI Glue -// ---------------------------------------------------------------------------- - -const char* const kClassPathName = "android/view/GLES20Canvas"; - -static JNINativeMethod gMethods[] = { - { "nIsAvailable", "()Z", (void*) android_view_GLES20Canvas_isAvailable }, - { "nSetViewport", "(JII)V", (void*) android_view_GLES20Canvas_setViewport }, - { "nSetHighContrastText","(JZ)V", (void*) android_view_GLES20Canvas_setHighContrastText }, - { "nInsertReorderBarrier","(JZ)V", (void*) android_view_GLES20Canvas_insertReorderBarrier }, - { "nPrepare", "(J)V", (void*) android_view_GLES20Canvas_prepare }, - { "nPrepareDirty", "(JIIII)V", (void*) android_view_GLES20Canvas_prepareDirty }, - { "nFinish", "(J)V", (void*) android_view_GLES20Canvas_finish }, - { "nSetProperty", "(Ljava/lang/String;Ljava/lang/String;)V", - (void*) android_view_GLES20Canvas_setProperty }, - - { "nCallDrawGLFunction", "(JJ)V", (void*) android_view_GLES20Canvas_callDrawGLFunction }, - - { "nDrawPatch", "(JJJFFFFJ)V", (void*) android_view_GLES20Canvas_drawPatch }, - - { "nDrawRects", "(JJJ)V", (void*) android_view_GLES20Canvas_drawRegionAsRects }, - { "nDrawRoundRect", "(JJJJJJJJ)V", (void*) android_view_GLES20Canvas_drawRoundRectProps }, - { "nDrawCircle", "(JJJJJ)V", (void*) android_view_GLES20Canvas_drawCircleProps }, - - { "nFinishRecording", "(J)J", (void*) android_view_GLES20Canvas_finishRecording }, - { "nDrawRenderNode", "(JJI)V", (void*) android_view_GLES20Canvas_drawRenderNode }, - - { "nCreateDisplayListRenderer", "()J", (void*) android_view_GLES20Canvas_createDisplayListRenderer }, - - { "nDrawLayer", "(JJFF)V", (void*) android_view_GLES20Canvas_drawLayer }, - - { "nGetMaximumTextureWidth", "()I", (void*) android_view_GLES20Canvas_getMaxTextureWidth }, - { "nGetMaximumTextureHeight", "()I", (void*) android_view_GLES20Canvas_getMaxTextureHeight }, -}; - -static JNINativeMethod gActivityThreadMethods[] = { - { "dumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V", - (void*) android_app_ActivityThread_dumpGraphics } -}; - -int register_android_view_GLES20Canvas(JNIEnv* env) { - jclass clazz = FindClassOrDie(env, "android/graphics/Rect"); - gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V"); - - return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); -} - -int register_android_app_ActivityThread(JNIEnv* env) { - return RegisterMethodsOrDie(env, "android/app/ActivityThread", - gActivityThreadMethods, NELEM(gActivityThreadMethods)); -} - -}; -- cgit v1.1