Fix the simulator build.

Change-Id: Ie404f7c2c308f0657f273af19a56e8c039b61898
This commit is contained in:
Romain Guy
2010-06-22 13:11:24 -07:00
parent 102fb89b9a
commit 85bf02fc16
9 changed files with 80 additions and 61 deletions

View File

@ -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,14 +383,16 @@ 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) {
// TODO: Implement
@ -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

View File

@ -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) {
@ -51,6 +53,16 @@ static void android_view_GLES20Renderer_prepare(JNIEnv* env, jobject canvas, jin
UI->prepare();
}
// ----------------------------------------------------------------------------
// 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) {

View File

@ -61,6 +61,10 @@ public class PorterDuff {
Mode(int nativeInt) {
this.nativeInt = nativeInt;
}
final int nativeInt;
/**
* @hide
*/
public final int nativeInt;
}
}

View File

@ -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

View File

@ -21,7 +21,7 @@
#include <utils/Log.h>
#include "UIMatrix.h"
#include "Matrix.h"
namespace android {

View File

@ -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

View File

@ -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

View File

@ -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();
private:
float mOrthoMatrix[16];
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

View File

@ -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);
}
}
}