Updates to the Android SampleApp
authordjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 13 Jun 2011 16:58:40 +0000 (16:58 +0000)
committerdjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 13 Jun 2011 16:58:40 +0000 (16:58 +0000)
http://codereview.appspot.com/4602049/

git-svn-id: http://skia.googlecode.com/svn/trunk@1567 2bbb7eff-a529-9590-31e7-b0007b416f81

android_sample/SampleApp/Android.mk
android_sample/SampleApp/AndroidManifest.xml
android_sample/SampleApp/jni/sample-jni.cpp
android_sample/SampleApp/res/menu/sample.xml [new file with mode: 0644]
android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java
android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java [new file with mode: 0644]
gpu/src/android/GrGLDefaultInterface_android.cpp [new file with mode: 0644]
include/utils/android/AndroidKeyToSkKey.h
include/views/SkOSWindow_Android.h
samplecode/SampleApp.cpp
samplecode/samplecode_files.mk

index 4df3def..59f6993 100644 (file)
@@ -30,14 +30,13 @@ LOCAL_C_INCLUDES += \
     external/skia/include/effects \
     external/skia/include/images \
     external/skia/include/utils \
-    $(LOCAL_PATH)/skia_extra/include/views \
-    $(LOCAL_PATH)/skia_extra/samplecode \
-    $(LOCAL_PATH)/skia_extra/include/xml \
+    external/skia/include/utils/android \
+    external/skia/include/views \
+    external/skia/samplecode \
+    external/skia/include/xml \
     external/skia/include/gpu \
     external/skia/src/core \
     external/skia/gpu/include \
-    frameworks/base/core/jni/android/graphics \
-    frameworks/base/native/include/android \
     $(LOCAL_PATH)/jni
 
 LOCAL_SHARED_LIBRARIES := \
@@ -55,16 +54,16 @@ LOCAL_PRELINK_MODULE := false
 LOCAL_MODULE := libskia-sample
 
 LOCAL_SRC_FILES := \
-    skia_extra/src/ports/SkXMLParser_empty.cpp \
+    ../../src/ports/SkXMLParser_empty.cpp \
     jni/sample-jni.cpp
 
-include $(LOCAL_PATH)/skia_extra/src/views/views_files.mk
-LOCAL_SRC_FILES += $(addprefix skia_extra/src/views/, $(SOURCE))
+include external/skia/src/views/views_files.mk
+LOCAL_SRC_FILES += $(addprefix ../../src/views/, $(SOURCE))
 
-include $(LOCAL_PATH)/skia_extra/src/xml/xml_files.mk
-LOCAL_SRC_FILES += $(addprefix skia_extra/src/xml/, $(SOURCE))
+include external/skia/src/xml/xml_files.mk
+LOCAL_SRC_FILES += $(addprefix ../../src/xml/, $(SOURCE))
 
-include $(LOCAL_PATH)/skia_extra/samplecode/samplecode_files.mk
-LOCAL_SRC_FILES += $(addprefix skia_extra/samplecode/, $(SOURCE))
+include external/skia/samplecode/samplecode_files.mk
+LOCAL_SRC_FILES += $(addprefix ../../samplecode/, $(SOURCE))
 
 include $(BUILD_SHARED_LIBRARY)
index e323246..071ae03 100644 (file)
@@ -21,7 +21,7 @@
     <application android:label="@string/app_name"
                  android:debuggable="true">
         <activity android:name=".SampleApp"
-                  android:theme="@android:style/Theme.Holo.NoActionBar"
+                  android:theme="@android:style/Theme.Holo.Light"
                   android:label="@string/app_name">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
index f8490b8..86d07a8 100644 (file)
 #include <jni.h>
 
 #include "SkCanvas.h"
-#include "GraphicsJNI.h"
 #include "SkEvent.h"
 #include "SkWindow.h"
 #include "SkApplication.h"
-#include "AndroidKeyToSkKey.h"
+#include "utils/android/AndroidKeyToSkKey.h"
+
+#include "SkDevice.h"
+#include "SkGpuCanvas.h"
+#include "GrContext.h"
 
 ///////////////////////////////////////////
 ///////////////// Globals /////////////////
@@ -70,8 +73,7 @@ void SkOSWindow::onHandleInval(const SkIRect& rect)
     if (!gActivityGlue.m_env || !gWindowGlue.m_inval || !gWindowGlue.m_obj) {
         return;
     }
-    gActivityGlue.m_env->CallVoidMethod(gWindowGlue.m_obj, gWindowGlue.m_inval,
-            rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
+    gActivityGlue.m_env->CallVoidMethod(gWindowGlue.m_obj, gWindowGlue.m_inval);
 }
 
 ///////////////////////////////////////////
@@ -95,8 +97,8 @@ static jmethodID GetJMethod(JNIEnv* env, jclass clazz, const char name[],
 }
 
 extern "C" {
-JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_drawToCanvas(
-        JNIEnv* env, jobject thiz, jobject jcanvas);
+JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_draw(
+        JNIEnv* env, jobject thiz);
 JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_init(
         JNIEnv* env, jobject thiz);
 JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_term(
@@ -111,6 +113,8 @@ JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_handleClick(
         JNIEnv* env, jobject thiz, jint x, jint y, jint state);
 JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_createOSWindow(
         JNIEnv* env, jobject thiz, jobject jsampleView);
+JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_zoom(
+        JNIEnv* env, jobject thiz, jfloat factor);
 };
 
 JNIEXPORT bool JNICALL Java_com_skia_sampleapp_SampleApp_handleKeyDown(
@@ -160,10 +164,10 @@ JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_createOSWindow(
 {
     gWindow = create_sk_window(NULL);
     // Only using a method on View.
-    jclass clazz = gActivityGlue.m_env->FindClass("android/view/View");
+    jclass clazz = gActivityGlue.m_env->FindClass("android/opengl/GLSurfaceView");
     gWindowGlue.m_obj = gActivityGlue.m_env->NewWeakGlobalRef(jsampleView);
-    gWindowGlue.m_inval = GetJMethod(gActivityGlue.m_env, clazz, "invalidate",
-            "(IIII)V");
+    gWindowGlue.m_inval = GetJMethod(gActivityGlue.m_env, clazz, "requestRender",
+            "()V");
     gActivityGlue.m_env->DeleteLocalRef(clazz);
 }
 
@@ -198,11 +202,42 @@ JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_term(JNIEnv* env,
 }
 
 
-JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_drawToCanvas(
-        JNIEnv* env, jobject thiz, jobject jcanvas)
+JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_draw(
+        JNIEnv* env, jobject thiz)
 {
     if (!gWindow) return;
     gWindow->update(NULL);
-    SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
-    canvas->drawBitmap(gWindow->getBitmap(), 0, 0);
+
+    // Copy the bitmap to the screen in raster mode
+    if (!gWindow->drawsToHardware()) {
+
+        SkBitmap bitmap = gWindow->getBitmap();
+
+        GrContext* context = gWindow->getGrContext();
+        if (!context) {
+            context = GrContext::Create(kOpenGL_Shaders_GrEngine, NULL);
+            if (!context || !gWindow->setGrContext(context)) {
+                return;
+            }
+            context->unref();
+        }
+        GrRenderTarget* renderTarget = context->createRenderTargetFrom3DApiState();
+        SkGpuCanvas* gpuCanvas = new SkGpuCanvas(context, renderTarget);
+
+        SkDevice* device = gpuCanvas->createDevice(SkBitmap::kARGB_8888_Config,
+                                          bitmap.width(), bitmap.height(),
+                                          false, false);
+        gpuCanvas->setDevice(device)->unref();
+        gpuCanvas->drawBitmap(bitmap, 0, 0);
+
+        SkSafeUnref(renderTarget);
+        SkSafeUnref(gpuCanvas);
+    }
 }
+
+JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_zoom(
+        JNIEnv* env, jobject thiz, jfloat factor)
+{
+    gWindow->changeZoomLevel(factor);
+}
+
diff --git a/android_sample/SampleApp/res/menu/sample.xml b/android_sample/SampleApp/res/menu/sample.xml
new file mode 100644 (file)
index 0000000..49f7ebb
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 Skia
+
+     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.
+-->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:id="@+id/next"
+        android:showAsAction="always"
+        android:icon="@*android:drawable/ic_btn_find_next"
+        />
+    <item
+        android:id="@+id/overview"
+        android:title="@string/overview"
+        />
+<!--
+        android:icon="@drawable/ic_menu_new_window"
+-->
+</menu>
index b02c4d7..fe73360 100644 (file)
@@ -19,94 +19,151 @@ package com.skia.sampleapp;
 import android.app.Activity;
 import android.content.Context;
 import android.graphics.Canvas;
+import android.opengl.GLSurfaceView;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
 import android.util.AttributeSet;
 import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
 public class SampleApp extends Activity
 {
     private TextView mTitle;
-
-    public class SampleView extends View {
-        public SampleView(Context context) {
-            super(context);
-            createOSWindow(this);
-        }
-
-        @Override
-        protected void onDraw(Canvas canvas) {
-            drawToCanvas(canvas);
-        }
-
-        @Override
-        protected void onSizeChanged(int w, int h, int oldw, int oldh) {
-            updateSize(w, h);
-        }
-
-        @Override
-        public boolean onTouchEvent(MotionEvent event) {
-            final int x = (int) event.getX();
-            final int y = (int) event.getY();
-            final int action = event.getAction();
-            handleClick(x, y, action);
-            return true;
-        }
-    }
+    private SampleView mView;
 
     @Override
-    public void onCreate(Bundle savedInstanceState)
-    {
+    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        init();
         setContentView(R.layout.layout);
         mTitle = (TextView) findViewById(R.id.title_view);
         LinearLayout holder = (LinearLayout) findViewById(R.id.holder);
-        View view = new SampleView(this);
-        holder.addView(view, new LinearLayout.LayoutParams(
+        mView = new SampleView(this);
+
+        holder.addView(mView, new LinearLayout.LayoutParams(
                 ViewGroup.LayoutParams.MATCH_PARENT,
                 ViewGroup.LayoutParams.MATCH_PARENT));
+        
+        mTitle.setVisibility(View.GONE);
+        getActionBar().setDisplayShowHomeEnabled(false);
+        
     }
 
     @Override
-    public void onDestroy()
-    {
-        term();
+    public void onDestroy() {
+        mView.queueEvent(new Runnable() {
+            @Override
+            public void run() {
+                term();
+            }
+        });
         super.onDestroy();
     }
 
     @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        getMenuInflater().inflate(R.menu.sample, menu);
+        return true;
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case R.id.overview:
+                mView.queueEvent(new Runnable() {
+                    @Override
+                    public void run() {
+                        handleKeyDown(KeyEvent.KEYCODE_BACK, 0);
+                    }
+                });
+                return true;
+            case R.id.next:
+                mView.queueEvent(new Runnable() {
+                    @Override
+                    public void run() {
+                        handleKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, 0);
+                    }
+                });
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
+        final int keycode = event.getKeyCode();
+        if (keycode == KeyEvent.KEYCODE_BACK) {
+            if (event.getAction() == KeyEvent.ACTION_UP) {
+                finish();
+            }
+            return true;
+        }
         switch (event.getAction()) {
             case KeyEvent.ACTION_DOWN:
-                int uni = event.getUnicodeChar(event.getMetaState());
-                return handleKeyDown(event.getKeyCode(), uni);
+                final int uni = event.getUnicodeChar(event.getMetaState());
+                mView.queueEvent(new Runnable() {
+                    @Override
+                    public void run() {
+                        handleKeyDown(keycode, uni);
+                    }
+                });
+                
+                return true;
             case KeyEvent.ACTION_UP:
-                return handleKeyUp(event.getKeyCode());
+                mView.queueEvent(new Runnable() {
+                    @Override
+                    public void run() {
+                        handleKeyUp(keycode);
+                    }
+                });
+                return true;
             default:
                 return false;
         }
     }
 
+    private static final int SET_TITLE = 1;
+    
+    private Handler mHandler = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case SET_TITLE:
+                    mTitle.setText((String) msg.obj);
+                    SampleApp.this.getActionBar().setSubtitle((String) msg.obj);
+                    break;
+                default:
+                    break;
+            }
+        }
+    };
+    
     @Override
     public void setTitle(CharSequence title) {
-        mTitle.setText(title);
+        mHandler.obtainMessage(SET_TITLE, title).sendToTarget();
     }
 
-    private native void drawToCanvas(Canvas canvas);
-    private native void init();
-    private native void term();
+    native void draw();
+    native void init();
+    native void term();
     // Currently depends on init having already been called.
-    private native void createOSWindow(SampleView view);
-    private native void updateSize(int w, int h);
-    private native void handleClick(int x, int y, int state);
-    private native boolean handleKeyDown(int key, int uni);
-    private native boolean handleKeyUp(int key);
+    native void createOSWindow(GLSurfaceView view);
+    native void updateSize(int w, int h);
+    native void handleClick(int x, int y, int state);
+    native boolean handleKeyDown(int key, int uni);
+    native boolean handleKeyUp(int key);
+    native void zoom(float factor);
 
     static {
         System.loadLibrary("skia-sample");
diff --git a/android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java b/android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java
new file mode 100644 (file)
index 0000000..0d76dce
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2011 Skia
+ *
+ * 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 com.skia.sampleapp;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.opengl.GLSurfaceView;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.AttributeSet;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.ScaleGestureDetector;
+import android.view.ScaleGestureDetector.OnScaleGestureListener;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+public class SampleView extends GLSurfaceView implements OnScaleGestureListener {
+    
+    private final SampleApp mApp;
+    private ScaleGestureDetector mDetector;
+    public SampleView(SampleApp app) {
+        super(app);
+        mApp = app;
+        setEGLContextClientVersion(2);
+        setEGLConfigChooser(8,8,8,8,0,8);
+        setRenderer(new SampleView.Renderer());
+        setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
+        mDetector = new ScaleGestureDetector(app, this);
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent event) {
+        mDetector.onTouchEvent(event);
+        if (mDetector.isInProgress()) {
+            return true;
+        }
+
+        final int x = (int) event.getX();
+        final int y = (int) event.getY();
+        final int action = event.getAction();
+        queueEvent(new Runnable() {
+           @Override
+           public void run() {
+               mApp.handleClick(x, y, action);
+           }
+        });
+        
+        return true;
+    }
+    // ScaleGestureDetector.OnScaleGestureListener implementation
+    @Override
+    public boolean onScaleBegin(ScaleGestureDetector detector) {
+        return true;
+    }
+
+    @Override
+    public boolean onScale(ScaleGestureDetector detector) {
+        if (detector.getScaleFactor() != 1) {
+            final float difference = detector.getCurrentSpan() - detector.getPreviousSpan();
+            queueEvent(new Runnable() {
+                @Override
+                public void run() {
+                    mApp.zoom(difference * .03f);
+                }
+            });
+
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void onScaleEnd(ScaleGestureDetector detector) {
+
+    }
+
+    private class Renderer implements GLSurfaceView.Renderer {
+        public void onDrawFrame(GL10 gl) {
+            mApp.draw();
+        }
+        
+        public void onSurfaceChanged(GL10 gl, int width, int height) {
+            mApp.updateSize(width, height);
+        }
+        
+        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+            gl.glClearStencil(0);
+            gl.glClear(gl.GL_STENCIL_BUFFER_BIT);
+            mApp.init();
+            mApp.createOSWindow(SampleView.this);
+        }
+    }
+}
\ No newline at end of file
diff --git a/gpu/src/android/GrGLDefaultInterface_android.cpp b/gpu/src/android/GrGLDefaultInterface_android.cpp
new file mode 100644 (file)
index 0000000..e52277e
--- /dev/null
@@ -0,0 +1,138 @@
+// Modified from chromium/src/webkit/glue/gl_bindings_skia_cmd_buffer.cc
+
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "GrGLInterface.h"
+
+#ifndef GL_GLEXT_PROTOTYPES
+#define GL_GLEXT_PROTOTYPES
+#endif
+
+#include "gl2.h"
+#include "gl2ext.h"
+/*
+#include "gpu/GLES2/gl2.h"
+#include "gpu/GLES2/gl2ext.h"
+*/
+void GrGLSetDefaultGLInterface() {
+  static GrGLInterface cmd_buffer_interface = {
+    kES2_GrGLBinding,
+
+    glActiveTexture,
+    glAttachShader,
+    glBindAttribLocation,
+    glBindBuffer,
+    glBindTexture,
+    glBlendColor,
+    glBlendFunc,
+    glBufferData,
+    glBufferSubData,
+    glClear,
+    glClearColor,
+    glClearStencil,
+    NULL,  // glClientActiveTexture
+    NULL,  // glColor4ub
+    glColorMask,
+    NULL,  // glColorPointer
+    glCompileShader,
+    glCompressedTexImage2D,
+    glCreateProgram,
+    glCreateShader,
+    glCullFace,
+    glDeleteBuffers,
+    glDeleteProgram,
+    glDeleteShader,
+    glDeleteTextures,
+    glDepthMask,
+    glDisable,
+    NULL,  // glDisableClientState
+    glDisableVertexAttribArray,
+    glDrawArrays,
+    glDrawElements,
+    glEnable,
+    NULL,  // glEnableClientState
+    glEnableVertexAttribArray,
+    glFrontFace,
+    glGenBuffers,
+    glGenTextures,
+    glGetBufferParameteriv,
+    glGetError,
+    glGetIntegerv,
+    glGetProgramInfoLog,
+    glGetProgramiv,
+    glGetShaderInfoLog,
+    glGetShaderiv,
+    glGetString,
+    glGetUniformLocation,
+    glLineWidth,
+    glLinkProgram,
+    NULL,  // glLoadMatrixf
+    NULL,  // glMatrixMode
+    glPixelStorei,
+    NULL,  // glPointSize
+    glReadPixels,
+    glScissor,
+    NULL,  // glShadeModel
+    glShaderSource,
+    glStencilFunc,
+    glStencilFuncSeparate,
+    glStencilMask,
+    glStencilMaskSeparate,
+    glStencilOp,
+    glStencilOpSeparate,
+    NULL,  // glTexCoordPointer
+    NULL,  // glTexEnvi
+    glTexImage2D,
+    glTexParameteri,
+    glTexSubImage2D,
+    glUniform1f,
+    glUniform1i,
+    glUniform1fv,
+    glUniform1iv,
+    glUniform2f,
+    glUniform2i,
+    glUniform2fv,
+    glUniform2iv,
+    glUniform3f,
+    glUniform3i,
+    glUniform3fv,
+    glUniform3iv,
+    glUniform4f,
+    glUniform4i,
+    glUniform4fv,
+    glUniform4iv,
+    glUniformMatrix2fv,
+    glUniformMatrix3fv,
+    glUniformMatrix4fv,
+    glUseProgram,
+    glVertexAttrib4fv,
+    glVertexAttribPointer,
+    NULL,  // glVertexPointer
+    glViewport,
+    glBindFramebuffer,
+    glBindRenderbuffer,
+    glCheckFramebufferStatus,
+    glDeleteFramebuffers,
+    glDeleteRenderbuffers,
+    glFramebufferRenderbuffer,
+    glFramebufferTexture2D,
+    glGenFramebuffers,
+    glGenRenderbuffers,
+    glRenderbufferStorage,
+    NULL,  // glRenderbufferStorageMultisampleEXT,
+    NULL,  // glBlitFramebufferEXT,
+    NULL,  // glResolveMultisampleFramebuffer
+    glMapBufferOES,
+    glUnmapBufferOES,
+    NULL,
+    GrGLInterface::kStaticInitEndGuard
+  };
+  static bool host_StubGL_initialized = false;
+  if (!host_StubGL_initialized) {
+    GrGLSetGLInterface(&cmd_buffer_interface);
+    host_StubGL_initialized = true;
+  }
+}
+
index 7b0a035..ad93661 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _ANDROID_TO_SKIA_KEYCODES_H
 #define _ANDROID_TO_SKIA_KEYCODES_H
 
-#include "keycodes.h"
+#include "android/keycodes.h"
 #include "SkKey.h"
 
 // Convert an Android keycode to an SkKey.  This is an incomplete list, only
@@ -32,6 +32,8 @@ SkKey AndroidKeycodeToSkKey(int keycode) {
             return kUp_SkKey;
         case AKEYCODE_DPAD_DOWN:
             return kDown_SkKey;
+        case AKEYCODE_BACK:
+            return kBack_SkKey;
         default:
             return kNONE_SkKey;
     }
index 38a4cf8..569f3f7 100644 (file)
 #include "SkWindow.h"
 #include "SkEvent.h"
 
+class GrContext;
+
 class SkOSWindow : public SkWindow {
 public:
     SkOSWindow(void*) {}
     ~SkOSWindow() {}
-    bool attachGL() { return false; }
+    bool attachGL() { return true; }
     void detachGL() {}
     void presentGL() {}
-
+    virtual bool drawsToHardware() { return false; }
+    virtual bool setGrContext(GrContext*) { return false; }
+    virtual GrContext* getGrContext() { return NULL; }
+    virtual void changeZoomLevel(float delta) {}
 protected:
     // overrides from SkWindow
     virtual void onHandleInval(const SkIRect&);
index f05fe6e..aba105b 100644 (file)
@@ -251,6 +251,11 @@ public:
     virtual ~SampleWindow();
 
     virtual void draw(SkCanvas* canvas);
+#ifdef ANDROID
+    virtual bool drawsToHardware() { return fCanvasType == kGPU_CanvasType; }
+    virtual bool setGrContext(GrContext*);
+    virtual GrContext* getGrContext();
+#endif
 
 protected:
     virtual void onDraw(SkCanvas* canvas);
@@ -287,7 +292,7 @@ private:
     SkPath fClipPath;
 
     SkTouchGesture fGesture;
-    int      fZoomLevel;
+    SkScalar fZoomLevel;
     SkScalar fZoomScale;
 
     enum CanvasType {
@@ -325,7 +330,10 @@ private:
     int fScrollTestX, fScrollTestY;
 
     bool make3DReady();
-    void changeZoomLevel(int delta);
+#ifdef ANDROID
+    virtual
+#endif
+    void changeZoomLevel(float delta);
 
     void loadView(SkView*);
     void updateTitle();
@@ -350,6 +358,23 @@ private:
     typedef SkOSWindow INHERITED;
 };
 
+#ifdef ANDROID
+bool SampleWindow::setGrContext(GrContext* context)
+{
+    if (fGrContext) {
+        fGrContext->unref();
+    }
+    fGrContext = context;
+    fGrContext->ref();
+    return true;
+}
+
+GrContext* SampleWindow::getGrContext()
+{
+    return fGrContext;
+}
+#endif
+
 bool SampleWindow::zoomIn()
 {
     // Arbitrarily decided
@@ -928,18 +953,20 @@ static SkBitmap::Config cycle_configs(SkBitmap::Config c) {
     return gConfigCycle[c];
 }
 
-void SampleWindow::changeZoomLevel(int delta) {
-    fZoomLevel += delta;
+void SampleWindow::changeZoomLevel(float delta) {
+    fZoomLevel += SkFloatToScalar(delta);
     if (fZoomLevel > 0) {
-        fZoomLevel = SkMin32(fZoomLevel, MAX_ZOOM_LEVEL);
-        fZoomScale = SkIntToScalar(fZoomLevel + 1);
+        fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL);
+        fZoomScale = fZoomLevel + SK_Scalar1;
     } else if (fZoomLevel < 0) {
-        fZoomLevel = SkMax32(fZoomLevel, MIN_ZOOM_LEVEL);
-        fZoomScale = SK_Scalar1 / (1 - fZoomLevel);
+        fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL);
+        fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel);
     } else {
         fZoomScale = SK_Scalar1;
     }
 
+    this->updateTitle();
+
     this->inval(NULL);
 }
 
@@ -1153,20 +1180,20 @@ bool SampleWindow::onHandleKey(SkKey key) {
             return true;
         case kUp_SkKey:
             if (USE_ARROWS_FOR_ZOOM) {
-                this->changeZoomLevel(1);
+                this->changeZoomLevel(1.f);
             } else {
                 fNClip = !fNClip;
                 this->inval(NULL);
+                this->updateTitle();
             }
-            this->updateTitle();
             return true;
         case kDown_SkKey:
             if (USE_ARROWS_FOR_ZOOM) {
-                this->changeZoomLevel(-1);
+                this->changeZoomLevel(-1.f);
             } else {
                 this->setConfig(cycle_configs(this->getBitmap().config()));
+                this->updateTitle();
             }
-            this->updateTitle();
             return true;
         case kOK_SkKey:
             if (false) {
@@ -1333,7 +1360,7 @@ void SampleWindow::updateTitle() {
     title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL);
 
     if (fZoomLevel) {
-        title.prependf("{%d} ", fZoomLevel);
+        title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel));
     }
     
     if (fMeasureFPS) {
index 1d6920d..cb757de 100644 (file)
@@ -20,12 +20,10 @@ SOURCE := \
     SampleShaderText.cpp \
     SamplePolyToPoly.cpp \
     SampleBlur.cpp \
-    SampleEffects.cpp \
     SampleHairline.cpp \
     SampleCircle.cpp \
     SampleOvalTest.cpp \
     SampleLines.cpp \
-    SampleCull.cpp \
     SampleOverflow.cpp \
     SampleStrokePath.cpp \
     SampleSlides.cpp \
@@ -57,19 +55,9 @@ SOURCE := \
     SampleFilter.cpp \
     OverView.cpp \
     SampleFuzz.cpp \
-    SampleShaders.cpp
-#    SampleSVG.cpp \
-    SampleTests.cpp \
-    SampleTestGL.cpp \
-    SampleTriangles.cpp \
-    SampleSkLayer.cpp \
-    SampleGM.cpp \
-    SampleText.cpp \
-    SampleTextBox.cpp \
+    SampleShaders.cpp \
     SampleImage.cpp \
     SampleMovie.cpp \
-    SampleAnimator.cpp \
-    SampleUnitMapper.cpp \
     SampleImageDir.cpp \
     SampleWarp.cpp \
     SamplePageFlip.cpp \