diff options
-rw-r--r-- | core/java/android/view/GLES20Canvas.java | 10 | ||||
-rw-r--r-- | core/jni/android_view_GLES20Canvas.cpp | 22 | ||||
-rw-r--r-- | graphics/java/android/graphics/PorterDuff.java | 6 | ||||
-rw-r--r-- | libs/hwui/Android.mk | 20 | ||||
-rw-r--r-- | libs/hwui/Matrix.cpp (renamed from libs/hwui/UIMatrix.cpp) | 2 | ||||
-rw-r--r-- | libs/hwui/Matrix.h (renamed from libs/hwui/UIMatrix.h) | 6 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp (renamed from libs/hwui/UIOpenGLRenderer.cpp) | 24 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.h (renamed from libs/hwui/UIOpenGLRenderer.h) | 18 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java | 31 |
9 files changed, 79 insertions, 60 deletions
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java index 56c2aac..d8fa850 100644 --- a/core/java/android/view/GLES20Canvas.java +++ b/core/java/android/view/GLES20Canvas.java @@ -332,7 +332,7 @@ class GLES20Canvas extends Canvas { @Override public void drawARGB(int a, int r, int g, int b) { - // TODO: Implement + drawColor((a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); } @Override @@ -383,13 +383,15 @@ class GLES20Canvas extends Canvas { @Override public void drawColor(int color) { - // TODO: Implement + drawColor(color, PorterDuff.Mode.SRC_OVER); } @Override public void drawColor(int color, PorterDuff.Mode mode) { - // TODO: Implement + nDrawColor(mRenderer, color, mode.nativeInt); } + + private native void nDrawColor(int renderer, int color, int mode); @Override public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { @@ -478,7 +480,7 @@ class GLES20Canvas extends Canvas { @Override public void drawRGB(int r, int g, int b) { - // TODO: Implement + drawColor(0xFF000000 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); } @Override diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index cd4c936..5766083 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -18,9 +18,11 @@ #include <nativehelper/JNIHelp.h> #include <android_runtime/AndroidRuntime.h> -#include <UIOpenGLRenderer.h> +#include <SkXfermode.h> -#define UI ((UIOpenGLRenderer*) renderer) +#include <OpenGLRenderer.h> + +#define UI ((OpenGLRenderer*) renderer) namespace android { @@ -28,8 +30,8 @@ namespace android { // Constructors // ---------------------------------------------------------------------------- -static UIOpenGLRenderer* android_view_GLES20Renderer_createRenderer(JNIEnv* env, jobject canvas) { - return new UIOpenGLRenderer; +static OpenGLRenderer* android_view_GLES20Renderer_createRenderer(JNIEnv* env, jobject canvas) { + return new OpenGLRenderer; } static void android_view_GLES20Renderer_destroyRenderer(JNIEnv* env, jobject canvas, jint renderer) { @@ -52,6 +54,16 @@ static void android_view_GLES20Renderer_prepare(JNIEnv* env, jobject canvas, jin } // ---------------------------------------------------------------------------- +// Draw color +// ---------------------------------------------------------------------------- + +static void android_view_GLES20Renderer_drawColor(JNIEnv* env, jobject canvas, jint renderer, + jint color, jint mode) { + + UI->drawColor(color, (SkXfermode::Mode) mode); +} + +// ---------------------------------------------------------------------------- // JNI Glue // ---------------------------------------------------------------------------- @@ -62,6 +74,8 @@ static JNINativeMethod gMethods[] = { { "nDestroyRenderer", "(I)V", (void*) android_view_GLES20Renderer_destroyRenderer }, { "nSetViewport", "(III)V", (void*) android_view_GLES20Renderer_setViewport }, { "nPrepare", "(I)V", (void*) android_view_GLES20Renderer_prepare }, + + { "nDrawColor", "(III)V", (void*) android_view_GLES20Renderer_drawColor }, }; int register_android_view_GLES20Canvas(JNIEnv* env) { diff --git a/graphics/java/android/graphics/PorterDuff.java b/graphics/java/android/graphics/PorterDuff.java index 0e405c2..2ef1662 100644 --- a/graphics/java/android/graphics/PorterDuff.java +++ b/graphics/java/android/graphics/PorterDuff.java @@ -61,6 +61,10 @@ public class PorterDuff { Mode(int nativeInt) { this.nativeInt = nativeInt; } - final int nativeInt; + + /** + * @hide + */ + public final int nativeInt; } } diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index 9544fe6..a2fcc41 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -1,13 +1,27 @@ +# Does not build for the simulator +ifneq ($(TARGET_SIMULATOR), true) + LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - UIMatrix.cpp \ - UIOpenGLRenderer.cpp + Matrix.cpp \ + OpenGLRenderer.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_MODULE_CLASS := SHARED_LIBRARIES -LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 +LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia LOCAL_MODULE:= libhwui LOCAL_PRELINK_MODULE := false include $(BUILD_SHARED_LIBRARY) + +endif #simulator diff --git a/libs/hwui/UIMatrix.cpp b/libs/hwui/Matrix.cpp index 954a525..b1eb701 100644 --- a/libs/hwui/UIMatrix.cpp +++ b/libs/hwui/Matrix.cpp @@ -21,7 +21,7 @@ #include <utils/Log.h> -#include "UIMatrix.h" +#include "Matrix.h" namespace android { diff --git a/libs/hwui/UIMatrix.h b/libs/hwui/Matrix.h index 55d7c07..51014a9 100644 --- a/libs/hwui/UIMatrix.h +++ b/libs/hwui/Matrix.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ANDROID_UI_MATRIX_H -#define ANDROID_UI_MATRIX_H +#ifndef ANDROID_MATRIX_H +#define ANDROID_MATRIX_H namespace android { @@ -97,4 +97,4 @@ typedef Matrix4 mat4; }; // namespace android -#endif // ANDROID_UI_MATRIX_H +#endif // ANDROID_MATRIX_H diff --git a/libs/hwui/UIOpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index b6113da..35825d2 100644 --- a/libs/hwui/UIOpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "UIOpenGLRenderer" +#define LOG_TAG "OpenGLRenderer" #include <stdlib.h> #include <stdint.h> @@ -26,20 +26,22 @@ #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> -#include "UIOpenGLRenderer.h" -#include "UIMatrix.h" +#include <SkXfermode.h> + +#include "OpenGLRenderer.h" +#include "Matrix.h" namespace android { -UIOpenGLRenderer::UIOpenGLRenderer() { - LOGD("Create UIOpenGLRenderer"); +OpenGLRenderer::OpenGLRenderer() { + LOGD("Create OpenGLRenderer"); } -UIOpenGLRenderer::~UIOpenGLRenderer() { - LOGD("Destroy UIOpenGLRenderer"); +OpenGLRenderer::~OpenGLRenderer() { + LOGD("Destroy OpenGLRenderer"); } -void UIOpenGLRenderer::setViewport(int width, int height) { +void OpenGLRenderer::setViewport(int width, int height) { glViewport(0, 0, width, height); mat4 ortho; @@ -47,11 +49,15 @@ void UIOpenGLRenderer::setViewport(int width, int height) { ortho.copyTo(mOrthoMatrix); } -void UIOpenGLRenderer::prepare() { +void OpenGLRenderer::prepare() { glDisable(GL_SCISSOR_TEST); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_SCISSOR_TEST); } +void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) { + LOGD("Drawing color"); +} + }; // namespace android diff --git a/libs/hwui/UIOpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index 3b95e6a..1236336 100644 --- a/libs/hwui/UIOpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -14,24 +14,28 @@ * limitations under the License. */ -#ifndef ANDROID_UI_OPENGL_RENDERER_H -#define ANDROID_UI_OPENGL_RENDERER_H +#ifndef ANDROID_OPENGL_RENDERER_H +#define ANDROID_OPENGL_RENDERER_H + +#include <SkXfermode.h> namespace android { -class UIOpenGLRenderer { +class OpenGLRenderer { public: - UIOpenGLRenderer(); - ~UIOpenGLRenderer(); + OpenGLRenderer(); + ~OpenGLRenderer(); void setViewport(int width, int height); void prepare(); + void drawColor(int color, SkXfermode::Mode mode); + private: + // Matrix used for ortho projection in shaders float mOrthoMatrix[16]; - }; }; // namespace android -#endif // ANDROID_UI_OPENGL_RENDERER_H +#endif // ANDROID_OPENGL_RENDERER_H diff --git a/tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java b/tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java index 1ee2dc1..d24f027 100644 --- a/tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java +++ b/tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java @@ -36,46 +36,21 @@ public class HwUiActivity extends Activity { setContentView(new DirtyBitmapView(this)); } + @SuppressWarnings({"UnusedDeclaration"}) static int dipToPx(Context c, int dip) { return (int) (c.getResources().getDisplayMetrics().density * dip + 0.5f); } static class DirtyBitmapView extends View { - private Bitmap mCache; - DirtyBitmapView(Context c) { super(c); - - final int width = dipToPx(c, 100); - final int height = dipToPx(c, 100); - - mCache = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - logGenerationId("Dirty cache created", mCache); - - Canvas canvas = new Canvas(mCache); - logGenerationId("Canvas cache created", mCache); - - canvas.drawColor(0xffff0000); - logGenerationId("Cache filled", mCache); - - Paint p = new Paint(); - p.setColor(0xff0000ff); - - canvas.drawRect(width / 2.0f, height / 2.0f, width, height, p); - logGenerationId("Cache modified", mCache); - } - - private static void logGenerationId(String message, Bitmap b) { - d(LOG_TAG, message); - d(LOG_TAG, " bitmap id=" + b.getGenerationId()); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - - canvas.drawBitmap(mCache, 0, 0, null); - logGenerationId("Cache drawn", mCache); + + canvas.drawRGB(255, 0, 0); } } } |