diff options
-rw-r--r-- | CleanSpec.mk | 8 | ||||
-rw-r--r-- | api/9.xml | 47 | ||||
-rw-r--r-- | api/current.xml | 49 | ||||
-rw-r--r-- | core/java/android/view/GLES20Canvas.java | 17 | ||||
-rw-r--r-- | core/java/android/view/HardwareRenderer.java | 46 | ||||
-rw-r--r-- | core/jni/Android.mk | 10 | ||||
-rw-r--r-- | core/jni/AndroidRuntime.cpp | 2 | ||||
-rw-r--r-- | core/jni/android/graphics/Canvas.cpp | 13 | ||||
-rw-r--r-- | core/jni/android/graphics/ColorFilter.cpp | 56 | ||||
-rw-r--r-- | core/jni/android/graphics/Shader.cpp | 23 | ||||
-rw-r--r-- | core/jni/android_view_GLES20Canvas.cpp | 46 | ||||
-rw-r--r-- | core/jni/android_view_HardwareRenderer.cpp | 44 | ||||
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 81 | ||||
-rw-r--r-- | libs/hwui/Android.mk | 64 | ||||
-rw-r--r-- | libs/hwui/TextureCache.cpp | 6 | ||||
-rw-r--r-- | libs/hwui/TextureCache.h | 2 | ||||
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/Canvas.java | 23 |
17 files changed, 199 insertions, 338 deletions
diff --git a/CleanSpec.mk b/CleanSpec.mk index 1b7daa6..f73e4d5 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -68,6 +68,14 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libreverb_inte $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libreverbtest_intermediates) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/) $(call add-clean-step, find . -type f -name "*.rs" -print0 | xargs -0 touch) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libandroid_runtime_intermediates) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/lib/libandroid_runtime.so) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/symbols/system/lib/libandroid_runtime.so) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/libandroid_runtime.so) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libhwui_intermediates) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/lib/libhwui.so) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/symbols/system/lib/libhwui.so) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/libhwui.so) # ************************************************ # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST @@ -58593,16 +58593,6 @@ <parameter name="bitmap" type="android.graphics.Bitmap"> </parameter> </constructor> -<constructor name="Canvas" - type="android.graphics.Canvas" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="gl" type="javax.microedition.khronos.opengles.GL"> -</parameter> -</constructor> <method name="clipPath" return="boolean" abstract="false" @@ -59519,17 +59509,6 @@ <parameter name="paint" type="android.graphics.Paint"> </parameter> </method> -<method name="freeGlCaches" - return="void" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -</method> <method name="getClipBounds" return="boolean" abstract="false" @@ -59576,17 +59555,6 @@ visibility="public" > </method> -<method name="getGL" - return="javax.microedition.khronos.opengles.GL" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -</method> <method name="getHeight" return="int" abstract="false" @@ -59950,21 +59918,6 @@ <parameter name="matrix" type="android.graphics.Matrix"> </parameter> </method> -<method name="setViewport" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="width" type="int"> -</parameter> -<parameter name="height" type="int"> -</parameter> -</method> <method name="skew" return="void" abstract="false" diff --git a/api/current.xml b/api/current.xml index 4b40758..3e32be2 100644 --- a/api/current.xml +++ b/api/current.xml @@ -68809,16 +68809,6 @@ <parameter name="bitmap" type="android.graphics.Bitmap"> </parameter> </constructor> -<constructor name="Canvas" - type="android.graphics.Canvas" - static="false" - final="false" - deprecated="deprecated" - visibility="public" -> -<parameter name="gl" type="javax.microedition.khronos.opengles.GL"> -</parameter> -</constructor> <method name="clipPath" return="boolean" abstract="false" @@ -69735,17 +69725,6 @@ <parameter name="paint" type="android.graphics.Paint"> </parameter> </method> -<method name="freeGlCaches" - return="void" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="deprecated" - visibility="public" -> -</method> <method name="getClipBounds" return="boolean" abstract="false" @@ -69800,7 +69779,7 @@ static="false" final="false" deprecated="deprecated" - visibility="public" + visibility="protected" > </method> <method name="getHeight" @@ -70177,21 +70156,6 @@ <parameter name="matrix" type="android.graphics.Matrix"> </parameter> </method> -<method name="setViewport" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="deprecated" - visibility="public" -> -<parameter name="width" type="int"> -</parameter> -<parameter name="height" type="int"> -</parameter> -</method> <method name="skew" return="void" abstract="false" @@ -213051,6 +213015,17 @@ visibility="public" > </method> +<method name="getVisibleTitleHeight" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> <method name="getZoomControls" return="android.view.View" abstract="false" diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java index 8e1338d..96bd884 100644 --- a/core/java/android/view/GLES20Canvas.java +++ b/core/java/android/view/GLES20Canvas.java @@ -40,7 +40,6 @@ import javax.microedition.khronos.opengles.GL; /** * An implementation of Canvas on top of OpenGL ES 2.0. */ -@SuppressWarnings({"deprecation"}) class GLES20Canvas extends Canvas { @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) private final GL mGl; @@ -56,6 +55,17 @@ class GLES20Canvas extends Canvas { private final Rect mClipBounds = new Rect(); private DrawFilter mFilter; + + /////////////////////////////////////////////////////////////////////////// + // JNI + /////////////////////////////////////////////////////////////////////////// + + private static native boolean nIsAvailable(); + private static boolean sIsAvailable = nIsAvailable(); + + static boolean isAvailable() { + return sIsAvailable; + } /////////////////////////////////////////////////////////////////////////// // Constructors @@ -91,11 +101,6 @@ class GLES20Canvas extends Canvas { } @Override - public GL getGL() { - throw new UnsupportedOperationException(); - } - - @Override public void setBitmap(Bitmap bitmap) { throw new UnsupportedOperationException(); } diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java index 090a743..60d495f 100644 --- a/core/java/android/view/HardwareRenderer.java +++ b/core/java/android/view/HardwareRenderer.java @@ -28,10 +28,6 @@ import javax.microedition.khronos.egl.EGLContext; import javax.microedition.khronos.egl.EGLDisplay; import javax.microedition.khronos.egl.EGLSurface; import javax.microedition.khronos.opengles.GL; -import javax.microedition.khronos.opengles.GL11; - -import static javax.microedition.khronos.opengles.GL10.GL_COLOR_BUFFER_BIT; -import static javax.microedition.khronos.opengles.GL10.GL_SCISSOR_TEST; /** * Interface for rendering a ViewRoot using hardware acceleration. @@ -110,10 +106,8 @@ abstract class HardwareRenderer { */ static HardwareRenderer createGlRenderer(int glVersion, boolean translucent) { switch (glVersion) { - case 1: - return new Gl10Renderer(translucent); case 2: - return new Gl20Renderer(translucent); + return Gl20Renderer.create(translucent); } throw new IllegalArgumentException("Unknown GL version: " + glVersion); } @@ -520,43 +514,13 @@ abstract class HardwareRenderer { @Override void onPreDraw() { mGlCanvas.onPreDraw(); - } - } - - /** - * Hardware renderer using OpenGL ES 1.0. - */ - @SuppressWarnings({"deprecation"}) - static class Gl10Renderer extends GlRenderer { - Gl10Renderer(boolean translucent) { - super(1, translucent); - } - - @Override - Canvas createCanvas() { - return new Canvas(mGl); } - @Override - void destroy() { - if (isEnabled()) { - nativeAbandonGlCaches(); + static HardwareRenderer create(boolean translucent) { + if (GLES20Canvas.isAvailable()) { + return new Gl20Renderer(translucent); } - - super.destroy(); - } - - @Override - void onPreDraw() { - GL11 gl = (GL11) mGl; - gl.glDisable(GL_SCISSOR_TEST); - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL_COLOR_BUFFER_BIT); - gl.glEnable(GL_SCISSOR_TEST); + return null; } } - - // Inform Skia to just abandon its texture cache IDs doesn't call glDeleteTextures - // Used only by the native Skia OpenGL ES 1.x implementation - private static native void nativeAbandonGlCaches(); } diff --git a/core/jni/Android.mk b/core/jni/Android.mk index 77c77f9..d1a5ae1 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -19,6 +19,10 @@ ifneq ($(USE_CUSTOM_RUNTIME_HEAP_MAX),) LOCAL_CFLAGS += -DCUSTOM_RUNTIME_HEAP_MAX=$(USE_CUSTOM_RUNTIME_HEAP_MAX) endif +ifeq ($(USE_OPENGL_RENDERER),true) + LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER +endif + LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES LOCAL_SRC_FILES:= \ @@ -47,7 +51,6 @@ LOCAL_SRC_FILES:= \ android_view_InputChannel.cpp \ android_view_InputQueue.cpp \ android_view_KeyEvent.cpp \ - android_view_HardwareRenderer.cpp \ android_view_GLES20Canvas.cpp \ android_view_MotionEvent.cpp \ android_text_AndroidCharacter.cpp \ @@ -170,7 +173,6 @@ LOCAL_SHARED_LIBRARIES := \ libbinder \ libnetutils \ libui \ - libhwui \ libgui \ libsurfaceflinger_client \ libcamera_client \ @@ -193,6 +195,10 @@ LOCAL_SHARED_LIBRARIES := \ libwpa_client \ libjpeg +ifeq ($(USE_OPENGL_RENDERER),true) + LOCAL_SHARED_LIBRARIES += libhwui +endif + ifeq ($(BOARD_HAVE_BLUETOOTH),true) LOCAL_C_INCLUDES += \ external/dbus \ diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 1e6d219..8b09e5f 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -115,7 +115,6 @@ extern int register_android_graphics_PixelFormat(JNIEnv* env); extern int register_com_android_internal_graphics_NativeUtils(JNIEnv *env); extern int register_android_view_Display(JNIEnv* env); extern int register_android_view_GLES20Canvas(JNIEnv* env); -extern int register_android_view_HardwareRenderer(JNIEnv* env); extern int register_android_view_Surface(JNIEnv* env); extern int register_android_view_ViewRoot(JNIEnv* env); extern int register_android_database_CursorWindow(JNIEnv* env); @@ -1244,7 +1243,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_graphics_PixelFormat), REG_JNI(register_android_graphics_Graphics), REG_JNI(register_android_view_GLES20Canvas), - REG_JNI(register_android_view_HardwareRenderer), REG_JNI(register_android_view_Surface), REG_JNI(register_android_view_ViewRoot), REG_JNI(register_com_google_android_gles_jni_EGLImpl), diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp index 558f5ff..bf150a9 100644 --- a/core/jni/android/graphics/Canvas.cpp +++ b/core/jni/android/graphics/Canvas.cpp @@ -20,7 +20,6 @@ #include "SkCanvas.h" #include "SkDevice.h" -#include "SkGLCanvas.h" #include "SkGraphics.h" #include "SkImageRef_GlobalPool.h" #include "SkPorterDuff.h" @@ -67,13 +66,8 @@ public: return bitmap ? new SkCanvas(*bitmap) : new SkCanvas; } - static SkCanvas* initGL(JNIEnv* env, jobject) { - return new SkGLCanvas; - } - static void freeCaches(JNIEnv* env, jobject) { // these are called in no particular order - SkGLCanvas::DeleteAllTextures(); SkImageRef_GlobalPool::SetRAMUsed(0); SkGraphics::SetFontCacheUsed(0); } @@ -110,11 +104,6 @@ public: return canvas->getDevice()->accessBitmap(false).height(); } - static void setViewport(JNIEnv* env, jobject, SkCanvas* canvas, - int width, int height) { - canvas->setViewport(width, height); - } - static void setBitmap(JNIEnv* env, jobject, SkCanvas* canvas, SkBitmap* bitmap) { canvas->setBitmapDevice(*bitmap); @@ -880,12 +869,10 @@ public: static JNINativeMethod gCanvasMethods[] = { {"finalizer", "(I)V", (void*) SkCanvasGlue::finalizer}, {"initRaster","(I)I", (void*) SkCanvasGlue::initRaster}, - {"initGL","()I", (void*) SkCanvasGlue::initGL}, {"isOpaque","()Z", (void*) SkCanvasGlue::isOpaque}, {"getWidth","()I", (void*) SkCanvasGlue::getWidth}, {"getHeight","()I", (void*) SkCanvasGlue::getHeight}, {"native_setBitmap","(II)V", (void*) SkCanvasGlue::setBitmap}, - {"nativeSetViewport", "(III)V", (void*) SkCanvasGlue::setViewport}, {"save","()I", (void*) SkCanvasGlue::saveAll}, {"save","(I)I", (void*) SkCanvasGlue::save}, {"native_saveLayer","(ILandroid/graphics/RectF;II)I", diff --git a/core/jni/android/graphics/ColorFilter.cpp b/core/jni/android/graphics/ColorFilter.cpp index 848234f..f3be8b0 100644 --- a/core/jni/android/graphics/ColorFilter.cpp +++ b/core/jni/android/graphics/ColorFilter.cpp @@ -36,40 +36,25 @@ public: obj->safeUnref(); } - static SkColorFilter* CreatePorterDuffFilter(JNIEnv* env, jobject, jint srcColor, - SkPorterDuff::Mode mode) { - return SkColorFilter::CreateModeFilter(srcColor, SkPorterDuff::ToXfermodeMode(mode)); - } - static SkiaColorFilter* glCreatePorterDuffFilter(JNIEnv* env, jobject, jint srcColor, SkPorterDuff::Mode mode) { +#ifdef USE_OPENGL_RENDERER return new SkiaBlendFilter(srcColor, SkPorterDuff::ToXfermodeMode(mode)); +#else + return NULL; +#endif } - static SkColorFilter* CreateLightingFilter(JNIEnv* env, jobject, jint mul, jint add) { - return SkColorFilter::CreateLightingFilter(mul, add); - } - static SkiaColorFilter* glCreateLightingFilter(JNIEnv* env, jobject, jint mul, jint add) { +#ifdef USE_OPENGL_RENDERER return new SkiaLightingFilter(mul, add); - } - - static SkColorFilter* CreateColorMatrixFilter(JNIEnv* env, jobject, jfloatArray jarray) { - AutoJavaFloatArray autoArray(env, jarray, 20); - const float* src = autoArray.ptr(); - -#ifdef SK_SCALAR_IS_FIXED - SkFixed array[20]; - for (int i = 0; i < 20; i++) { - array[i] = SkFloatToScalar(src[i]); - } - return new SkColorMatrixFilter(array); #else - return new SkColorMatrixFilter(src); + return NULL; #endif } static SkiaColorFilter* glCreateColorMatrixFilter(JNIEnv* env, jobject, jfloatArray jarray) { +#ifdef USE_OPENGL_RENDERER AutoJavaFloatArray autoArray(env, jarray, 20); const float* src = autoArray.ptr(); @@ -86,6 +71,33 @@ public: colorVector[3] = src[19]; return new SkiaColorMatrixFilter(colorMatrix, colorVector); +#else + return NULL; +#endif + } + + static SkColorFilter* CreatePorterDuffFilter(JNIEnv* env, jobject, jint srcColor, + SkPorterDuff::Mode mode) { + return SkColorFilter::CreateModeFilter(srcColor, SkPorterDuff::ToXfermodeMode(mode)); + } + + static SkColorFilter* CreateLightingFilter(JNIEnv* env, jobject, jint mul, jint add) { + return SkColorFilter::CreateLightingFilter(mul, add); + } + + static SkColorFilter* CreateColorMatrixFilter(JNIEnv* env, jobject, jfloatArray jarray) { + AutoJavaFloatArray autoArray(env, jarray, 20); + const float* src = autoArray.ptr(); + +#ifdef SK_SCALAR_IS_FIXED + SkFixed array[20]; + for (int i = 0; i < 20; i++) { + array[i] = SkFloatToScalar(src[i]); + } + return new SkColorMatrixFilter(array); +#else + return new SkColorMatrixFilter(src); +#endif } }; diff --git a/core/jni/android/graphics/Shader.cpp b/core/jni/android/graphics/Shader.cpp index 34b4ab5..2b98e89 100644 --- a/core/jni/android/graphics/Shader.cpp +++ b/core/jni/android/graphics/Shader.cpp @@ -71,7 +71,9 @@ static void Shader_setLocalMatrix(JNIEnv* env, jobject o, SkShader* shader, Skia else { shader->setLocalMatrix(*matrix); } +#ifdef USE_OPENGL_RENDERER skiaShader->setMatrix(const_cast<SkMatrix*>(matrix)); +#endif } } @@ -90,10 +92,14 @@ static SkShader* BitmapShader_constructor(JNIEnv* env, jobject o, const SkBitmap static SkiaShader* BitmapShader_postConstructor(JNIEnv* env, jobject o, SkShader* shader, SkBitmap* bitmap, int tileModeX, int tileModeY) { +#ifdef USE_OPENGL_RENDERER SkiaShader* skiaShader = new SkiaBitmapShader(bitmap, shader, static_cast<SkShader::TileMode>(tileModeX), static_cast<SkShader::TileMode>(tileModeY), NULL, (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0); return skiaShader; +#else + return NULL; +#endif } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -134,7 +140,7 @@ static SkShader* LinearGradient_create1(JNIEnv* env, jobject o, static SkiaShader* LinearGradient_postCreate1(JNIEnv* env, jobject o, SkShader* shader, float x0, float y0, float x1, float y1, jintArray colorArray, jfloatArray posArray, int tileMode) { - +#ifdef USE_OPENGL_RENDERER size_t count = env->GetArrayLength(colorArray); const jint* colorValues = env->GetIntArrayElements(colorArray, NULL); @@ -162,10 +168,14 @@ static SkiaShader* LinearGradient_postCreate1(JNIEnv* env, jobject o, SkShader* env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT); return skiaShader; +#else + return NULL; +#endif } static SkiaShader* LinearGradient_postCreate2(JNIEnv* env, jobject o, SkShader* shader, float x0, float y0, float x1, float y1, int color0, int color1, int tileMode) { +#ifdef USE_OPENGL_RENDERER float* storedBounds = new float[4]; storedBounds[0] = x0; storedBounds[1] = y0; storedBounds[2] = x1; storedBounds[3] = y1; @@ -183,6 +193,9 @@ static SkiaShader* LinearGradient_postCreate2(JNIEnv* env, jobject o, SkShader* (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0); return skiaShader; +#else + return NULL; +#endif } static SkShader* LinearGradient_create2(JNIEnv* env, jobject o, @@ -315,6 +328,7 @@ static SkShader* ComposeShader_create2(JNIEnv* env, jobject o, static SkiaShader* ComposeShader_postCreate2(JNIEnv* env, jobject o, SkShader* shader, SkiaShader* shaderA, SkiaShader* shaderB, SkPorterDuff::Mode porterDuffMode) { +#ifdef USE_OPENGL_RENDERER SkAutoUnref au(SkPorterDuff::CreateXfermode(porterDuffMode)); SkXfermode* mode = (SkXfermode*) au.get(); SkXfermode::Mode skiaMode; @@ -322,15 +336,22 @@ static SkiaShader* ComposeShader_postCreate2(JNIEnv* env, jobject o, SkShader* s skiaMode = SkXfermode::kSrcOver_Mode; } return new SkiaComposeShader(shaderA, shaderB, skiaMode, shader); +#else + return NULL; +#endif } static SkiaShader* ComposeShader_postCreate1(JNIEnv* env, jobject o, SkShader* shader, SkiaShader* shaderA, SkiaShader* shaderB, SkXfermode* mode) { +#ifdef USE_OPENGL_RENDERER SkXfermode::Mode skiaMode; if (!SkXfermode::IsMode(mode, &skiaMode)) { skiaMode = SkXfermode::kSrcOver_Mode; } return new SkiaComposeShader(shaderA, shaderB, skiaMode, shader); +#else + return NULL; +#endif } /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index 9fd2b86..bb1a9e3 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -41,6 +41,13 @@ namespace android { using namespace uirenderer; +/** + * Note: OpenGLRenderer JNI layer is generated and compiled only on supported + * devices. This means all the logic must be compiled only when the + * preprocessor variable USE_OPENGL_RENDERER is defined. + */ +#ifdef USE_OPENGL_RENDERER + // ---------------------------------------------------------------------------- // Java APIs // ---------------------------------------------------------------------------- @@ -284,6 +291,20 @@ static void android_view_GLES20Canvas_drawText(JNIEnv* env, jobject canvas, env->ReleaseStringChars(text, textArray); } +#endif // USE_OPENGL_RENDERER + +// ---------------------------------------------------------------------------- +// Common +// ---------------------------------------------------------------------------- + +static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) { +#ifdef USE_OPENGL_RENDERER + return JNI_TRUE; +#else + return JNI_FALSE; +#endif +} + // ---------------------------------------------------------------------------- // JNI Glue // ---------------------------------------------------------------------------- @@ -291,6 +312,9 @@ static void android_view_GLES20Canvas_drawText(JNIEnv* env, jobject canvas, const char* const kClassPathName = "android/view/GLES20Canvas"; static JNINativeMethod gMethods[] = { + { "nIsAvailable", "()Z", (void*) android_view_GLES20Canvas_isAvailable }, +#ifdef USE_OPENGL_RENDERER + { "nCreateRenderer", "()I", (void*) android_view_GLES20Canvas_createRenderer }, { "nDestroyRenderer", "(I)V", (void*) android_view_GLES20Canvas_destroyRenderer }, { "nSetViewport", "(III)V", (void*) android_view_GLES20Canvas_setViewport }, @@ -334,16 +358,22 @@ static JNINativeMethod gMethods[] = { { "nGetClipBounds", "(ILandroid/graphics/Rect;)Z", (void*) android_view_GLES20Canvas_getClipBounds }, +#endif }; -#define FIND_CLASS(var, className) \ - var = env->FindClass(className); \ - LOG_FATAL_IF(! var, "Unable to find class " className); \ - var = jclass(env->NewGlobalRef(var)); - -#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ - var = env->GetMethodID(clazz, methodName, methodDescriptor); \ - LOG_FATAL_IF(! var, "Unable to find method " methodName); +#ifdef USE_OPENGL_RENDERER + #define FIND_CLASS(var, className) \ + var = env->FindClass(className); \ + LOG_FATAL_IF(! var, "Unable to find class " className); \ + var = jclass(env->NewGlobalRef(var)); + + #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ + var = env->GetMethodID(clazz, methodName, methodDescriptor); \ + LOG_FATAL_IF(! var, "Unable to find method " methodName); +#else + #define FIND_CLASS(var, className) + #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) +#endif int register_android_view_GLES20Canvas(JNIEnv* env) { FIND_CLASS(gRectClassInfo.clazz, "android/graphics/Rect"); diff --git a/core/jni/android_view_HardwareRenderer.cpp b/core/jni/android_view_HardwareRenderer.cpp deleted file mode 100644 index 6d20c9d..0000000 --- a/core/jni/android_view_HardwareRenderer.cpp +++ /dev/null @@ -1,44 +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. - */ - -#include <utils/SkGLCanvas.h> - -#include "jni.h" -#include <nativehelper/JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> -#include <utils/misc.h> - -// ---------------------------------------------------------------------------- - -namespace android { - -static void android_view_HardwareRenderer_abandonGlCaches(JNIEnv* env, jobject) { - SkGLCanvas::AbandonAllTextures(); -} - -// ---------------------------------------------------------------------------- - -const char* const kClassPathName = "android/view/HardwareRenderer"; - -static JNINativeMethod gMethods[] = { - { "nativeAbandonGlCaches", "()V", (void*)android_view_HardwareRenderer_abandonGlCaches }, -}; - -int register_android_view_HardwareRenderer(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); -} - -}; diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 77a1930..36a8e57 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -42,7 +42,6 @@ public class Canvas { for both to be null. */ private Bitmap mBitmap; // if not null, mGL must be null - private GL mGL; // if not null, mBitmap must be null // optional field set by the caller private DrawFilter mDrawFilter; @@ -106,31 +105,22 @@ public class Canvas { mDensity = bitmap.mDensity; } - /*package*/ Canvas(int nativeCanvas) { + Canvas(int nativeCanvas) { if (nativeCanvas == 0) { throw new IllegalStateException(); } mNativeCanvas = nativeCanvas; mDensity = Bitmap.getDefaultDensity(); } - + /** - * Construct a canvas with the specified gl context. All drawing through - * this canvas will be redirected to OpenGL. Note: some features may not - * be supported in this mode (e.g. some GL implementations may not support - * antialiasing or certain effects like ColorMatrix or certain Xfermodes). - * However, no exception will be thrown in those cases. + * Returns null. * - * <p>The initial target density of the canvas is the same as the initial - * density of bitmaps as per {@link Bitmap#getDensity() Bitmap.getDensity()}. - * - * @deprecated This constructor is not supported and should not be invoked. + * @deprecated This method is not supported and should not be invoked. */ @Deprecated - public Canvas(GL gl) { - mNativeCanvas = initGL(); - mGL = gl; - mDensity = Bitmap.getDefaultDensity(); + protected GL getGL() { + return null; } /** @@ -143,32 +133,9 @@ public class Canvas { * false otherwise. */ public boolean isHardwareAccelerated() { - return mGL != null; - } - - /** - * Return the GL object associated with this canvas, or null if it is not - * backed by GL. - * - * @deprecated This method is not supported and should not be invoked. - */ - @Deprecated - public GL getGL() { - return mGL; - } - - /** - * Call this to free up OpenGL resources that may be cached or allocated - * on behalf of the Canvas. Any subsequent drawing with a GL-backed Canvas - * will have to recreate those resources. - * - * @deprecated This method is not supported and should not be invoked. - */ - @Deprecated - public static void freeGlCaches() { - freeCaches(); + return false; } - + /** * Specify a bitmap for the canvas to draw into. As a side-effect, also * updates the canvas's target density to match that of the bitmap. @@ -182,7 +149,7 @@ public class Canvas { if (!bitmap.isMutable()) { throw new IllegalStateException(); } - if (mGL != null) { + if (isHardwareAccelerated()) { throw new RuntimeException("Can't set a bitmap device on a GL canvas"); } throwIfRecycled(bitmap); @@ -196,16 +163,12 @@ public class Canvas { * Set the viewport dimensions if this canvas is GL based. If it is not, * this method is ignored and no exception is thrown. * - * @param width The width of the viewport - * @param height The height of the viewport + * @param width The width of the viewport + * @param height The height of the viewport * - * @deprecated This method is not supported and should not be invoked. + * @hide */ - @Deprecated public void setViewport(int width, int height) { - if (mGL != null) { - nativeSetViewport(mNativeCanvas, width, height); - } } /** @@ -1591,26 +1554,26 @@ public class Canvas { @Override protected void finalize() throws Throwable { - super.finalize(); - // If the constructor threw an exception before setting mNativeCanvas, the native finalizer - // must not be invoked. - if (mNativeCanvas != 0) { - finalizer(mNativeCanvas); + try { + super.finalize(); + } finally { + // If the constructor threw an exception before setting mNativeCanvas, + // the native finalizer must not be invoked. + if (mNativeCanvas != 0) { + finalizer(mNativeCanvas); + } } } /** - * Free up as much memory as possible from private caches (e.g. fonts, - * images) + * Free up as much memory as possible from private caches (e.g. fonts, images) * - * @hide - for now + * @hide */ public static native void freeCaches(); private static native int initRaster(int nativeBitmapOrZero); - private static native int initGL(); private static native void native_setBitmap(int nativeCanvas, int bitmap); - private static native void nativeSetViewport(int nCanvas, int w, int h); private static native int native_saveLayer(int nativeCanvas, RectF bounds, int paint, int layerFlags); private static native int native_saveLayer(int nativeCanvas, float l, diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index 0444964..1efe6b5 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -1,33 +1,41 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES:= \ - FontRenderer.cpp \ - GradientCache.cpp \ - LayerCache.cpp \ - Matrix.cpp \ - OpenGLRenderer.cpp \ - Patch.cpp \ - PatchCache.cpp \ - PathCache.cpp \ - Program.cpp \ - ProgramCache.cpp \ - SkiaColorFilter.cpp \ - SkiaShader.cpp \ - TextureCache.cpp +# Only build libhwui when USE_OPENGL_RENDERER is +# defined in the current device/board configuration +ifeq ($(USE_OPENGL_RENDERER),true) + LOCAL_SRC_FILES:= \ + FontRenderer.cpp \ + GradientCache.cpp \ + LayerCache.cpp \ + Matrix.cpp \ + OpenGLRenderer.cpp \ + Patch.cpp \ + PatchCache.cpp \ + PathCache.cpp \ + Program.cpp \ + ProgramCache.cpp \ + SkiaColorFilter.cpp \ + SkiaShader.cpp \ + TextureCache.cpp + + LOCAL_C_INCLUDES += \ + $(JNI_H_INCLUDE) \ + $(LOCAL_PATH)/../../include/utils \ + external/skia/include/core \ + external/skia/include/effects \ + external/skia/include/images \ + external/skia/src/ports \ + external/skia/include/utils -LOCAL_C_INCLUDES += \ - $(JNI_H_INCLUDE) \ - $(LOCAL_PATH)/../../include/utils \ - external/skia/include/core \ - external/skia/include/effects \ - external/skia/include/images \ - external/skia/src/ports \ - external/skia/include/utils + LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER + LOCAL_MODULE_CLASS := SHARED_LIBRARIES + LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia + LOCAL_MODULE := libhwui + LOCAL_MODULE_TAGS := optional + LOCAL_PRELINK_MODULE := false + + include $(BUILD_SHARED_LIBRARY) -LOCAL_MODULE_CLASS := SHARED_LIBRARIES -LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia -LOCAL_MODULE := libhwui -LOCAL_PRELINK_MODULE := false - -include $(BUILD_SHARED_LIBRARY) + include $(call all-makefiles-under,$(LOCAL_PATH)) +endif diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index 1cb5932..3f9698d 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -32,10 +32,8 @@ TextureCache::TextureCache(uint32_t maxByteSize): mSize(0), mMaxSize(maxByteSize) { mCache.setOnEntryRemovedListener(this); - GLint maxTextureSize; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); - LOGD("Maximum texture dimension is %d pixels", maxTextureSize); - mMaxTextureSize = maxTextureSize; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); + LOGD("Maximum texture dimension is %d pixels", mMaxTextureSize); } TextureCache::~TextureCache() { diff --git a/libs/hwui/TextureCache.h b/libs/hwui/TextureCache.h index c7e50a1..452716c 100644 --- a/libs/hwui/TextureCache.h +++ b/libs/hwui/TextureCache.h @@ -82,7 +82,7 @@ private: uint32_t mSize; uint32_t mMaxSize; - GLuint mMaxTextureSize; + GLint mMaxTextureSize; }; // class TextureCache }; // namespace uirenderer diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas.java b/tools/layoutlib/bridge/src/android/graphics/Canvas.java index d5d315e..1e1aba9 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Canvas.java +++ b/tools/layoutlib/bridge/src/android/graphics/Canvas.java @@ -69,11 +69,6 @@ public class Canvas extends _Original_Canvas { throw new UnsupportedOperationException("Can't create Canvas(int)"); } - public Canvas(javax.microedition.khronos.opengles.GL gl) { - mLogger = null; - throw new UnsupportedOperationException("Can't create Canvas(javax.microedition.khronos.opengles.GL)"); - } - // custom constructors for our use. public Canvas(int width, int height, ILayoutLog logger) { mLogger = logger; @@ -1174,15 +1169,6 @@ public class Canvas extends _Original_Canvas { } /* (non-Javadoc) - * @see android.graphics.Canvas#getGL() - */ - @Override - public GL getGL() { - // TODO Auto-generated method stub - return super.getGL(); - } - - /* (non-Javadoc) * @see android.graphics.Canvas#getMatrix() */ @Override @@ -1257,15 +1243,6 @@ public class Canvas extends _Original_Canvas { } /* (non-Javadoc) - * @see android.graphics.Canvas#setViewport(int, int) - */ - @Override - public void setViewport(int width, int height) { - // TODO Auto-generated method stub - super.setViewport(width, height); - } - - /* (non-Javadoc) * @see android.graphics.Canvas#skew(float, float) */ @Override |