diff options
| -rw-r--r-- | libs/audioflinger/AudioFlinger.cpp | 20 | ||||
| -rw-r--r-- | libs/surfaceflinger/Layer.cpp | 63 | ||||
| -rw-r--r-- | libs/surfaceflinger/LayerBase.cpp | 52 | ||||
| -rw-r--r-- | libs/surfaceflinger/LayerBase.h | 5 | ||||
| -rw-r--r-- | libs/surfaceflinger/SurfaceFlinger.cpp | 6 | ||||
| -rw-r--r-- | opengl/tests/gl_basic/Android.mk | 17 | ||||
| -rw-r--r-- | opengl/tests/gl_basic/gl_basic.cpp | 357 | ||||
| -rw-r--r-- | opengl/tests/gl_jni/jni/gl_code.cpp | 116 | ||||
| -rw-r--r-- | opengl/tests/gl_jni/src/com/android/gljni/GLJNIActivity.java | 17 | ||||
| -rw-r--r-- | opengl/tests/gl_jni/src/com/android/gljni/GLJNILib.java | 1 | ||||
| -rw-r--r-- | opengl/tests/gl_jni/src/com/android/gljni/GLJNIView.java | 6 | ||||
| -rw-r--r-- | vpn/java/android/net/vpn/VpnType.java | 20 |
12 files changed, 552 insertions, 128 deletions
diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp index 6500791412..2ed5d3b242 100644 --- a/libs/audioflinger/AudioFlinger.cpp +++ b/libs/audioflinger/AudioFlinger.cpp @@ -74,6 +74,8 @@ static const int8_t kMaxTrackStartupRetries = 50; static const int kDumpLockRetries = 50; static const int kDumpLockSleep = 20000; +static const nsecs_t kWarningThrottle = seconds(5); + #define AUDIOFLINGER_SECURITY_ENABLED 1 @@ -1170,7 +1172,10 @@ bool AudioFlinger::MixerThread::threadLoop() size_t enabledTracks = 0; nsecs_t standbyTime = systemTime(); size_t mixBufferSize = mFrameCount * mFrameSize; - nsecs_t maxPeriod = seconds(mFrameCount) / mSampleRate * 2; + // FIXME: Relaxed timing because of a certain device that can't meet latency + // Should be reduced to 2x after the vendor fixes the driver issue + nsecs_t maxPeriod = seconds(mFrameCount) / mSampleRate * 3; + nsecs_t lastWarning = 0; while (!exitPending()) { @@ -1183,7 +1188,9 @@ bool AudioFlinger::MixerThread::threadLoop() if (checkForNewParameters_l()) { mixBufferSize = mFrameCount * mFrameSize; - maxPeriod = seconds(mFrameCount) / mSampleRate * 2; + // FIXME: Relaxed timing because of a certain device that can't meet latency + // Should be reduced to 2x after the vendor fixes the driver issue + maxPeriod = seconds(mFrameCount) / mSampleRate * 3; } const SortedVector< wp<Track> >& activeTracks = mActiveTracks; @@ -1260,10 +1267,15 @@ bool AudioFlinger::MixerThread::threadLoop() mNumWrites++; mInWrite = false; mStandby = false; - nsecs_t delta = systemTime() - mLastWriteTime; + nsecs_t now = systemTime(); + nsecs_t delta = now - mLastWriteTime; if (delta > maxPeriod) { - LOGW("write blocked for %llu msecs, thread %p", ns2ms(delta), this); mNumDelayedWrites++; + if ((now - lastWarning) > kWarningThrottle) { + LOGW("write blocked for %llu msecs, %d delayed writes, thread %p", + ns2ms(delta), mNumDelayedWrites, this); + lastWarning = now; + } } } else { usleep(sleepTime); diff --git a/libs/surfaceflinger/Layer.cpp b/libs/surfaceflinger/Layer.cpp index 2894bf0b6a..07222eca8e 100644 --- a/libs/surfaceflinger/Layer.cpp +++ b/libs/surfaceflinger/Layer.cpp @@ -294,8 +294,8 @@ sp<SurfaceBuffer> Layer::requestBuffer(int index, int usage) this, index, w, h, strerror(-err)); } else { LOGD_IF(DEBUG_RESIZE, - "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d", - this, index, w, h); + "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p", + this, index, w, h, buffer->handle); } if (err == NO_ERROR && buffer->handle != 0) { @@ -318,22 +318,18 @@ uint32_t Layer::doTransaction(uint32_t flags) const Layer::State& front(drawingState()); const Layer::State& temp(currentState()); - // Index of the back buffer - const bool backbufferChanged = (front.w != temp.w) || (front.h != temp.h); - if (backbufferChanged) { + if ((front.requested_w != temp.requested_w) || + (front.requested_h != temp.requested_h)) { // the size changed, we need to ask our client to request a new buffer LOGD_IF(DEBUG_RESIZE, "resize (layer=%p), requested (%dx%d), " "drawing (%d,%d), (%dx%d), (%dx%d)", - this, int(temp.w), int(temp.h), - int(drawingState().w), int(drawingState().h), + this, + int(temp.requested_w), int(temp.requested_h), + int(front.requested_w), int(front.requested_h), int(mBuffers[0]->getWidth()), int(mBuffers[0]->getHeight()), int(mBuffers[1]->getWidth()), int(mBuffers[1]->getHeight())); - // record the new size, form this point on, when the client request a - // buffer, it'll get the new size. - setDrawingSize(temp.w, temp.h); - // we're being resized and there is a freeze display request, // acquire a freeze lock, so that the screen stays put // until we've redrawn at the new size; this is to avoid @@ -346,9 +342,16 @@ uint32_t Layer::doTransaction(uint32_t flags) } } - // recompute the visible region - flags |= Layer::eVisibleRegion; - this->contentDirty = true; + // this will make sure LayerBase::doTransaction doesn't update + // the drawing state's size + Layer::State& editDraw(mDrawingState); + editDraw.requested_w = temp.requested_w; + editDraw.requested_h = temp.requested_h; + + // record the new size, form this point on, when the client request a + // buffer, it'll get the new size. + setDrawingSize(temp.requested_w, temp.requested_h); + // all buffers need reallocation lcblk->reallocate(); } @@ -392,11 +395,35 @@ void Layer::lockPageFlip(bool& recomputeVisibleRegions) const Region dirty(lcblk->getDirtyRegion(buf)); mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() ); - const Layer::State& front(drawingState()); - if (newFrontBuffer->getWidth() == front.w && - newFrontBuffer->getHeight() ==front.h) { - mFreezeLock.clear(); + if (newFrontBuffer->getWidth() == front.requested_w && + newFrontBuffer->getHeight() == front.requested_h) + { + if ((front.w != front.requested_w) || + (front.h != front.requested_h)) + { + // Here we pretend the transaction happened by updating the + // current and drawing states. Drawing state is only accessed + // in this thread, no need to have it locked + Layer::State& editDraw(mDrawingState); + editDraw.w = editDraw.requested_w; + editDraw.h = editDraw.requested_h; + + // We also need to update the current state so that we don't + // end-up doing too much work during the next transaction. + // NOTE: We actually don't need hold the transaction lock here + // because State::w and State::h are only accessed from + // this thread + Layer::State& editTemp(currentState()); + editTemp.w = editDraw.w; + editTemp.h = editDraw.h; + + // recompute visible region + recomputeVisibleRegions = true; + + // we now have the correct size, unfreeze the screen + mFreezeLock.clear(); + } } // FIXME: signal an event if we have more buffers waiting diff --git a/libs/surfaceflinger/LayerBase.cpp b/libs/surfaceflinger/LayerBase.cpp index a351253d8d..d83c8429eb 100644 --- a/libs/surfaceflinger/LayerBase.cpp +++ b/libs/surfaceflinger/LayerBase.cpp @@ -34,12 +34,6 @@ #include "DisplayHardware/DisplayHardware.h" -// We don't honor the premultiplied alpha flags, which means that -// premultiplied surface may be composed using a non-premultiplied -// equation. We do this because it may be a lot faster on some hardware -// The correct value is HONOR_PREMULTIPLIED_ALPHA = 1 -#define HONOR_PREMULTIPLIED_ALPHA 0 - namespace android { // --------------------------------------------------------------------------- @@ -89,26 +83,22 @@ void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags) if (flags & ISurfaceComposer::eNonPremultiplied) mPremultipliedAlpha = false; - mCurrentState.z = 0; - mCurrentState.w = w; - mCurrentState.h = h; - mCurrentState.alpha = 0xFF; - mCurrentState.flags = layerFlags; - mCurrentState.sequence = 0; + mCurrentState.z = 0; + mCurrentState.w = w; + mCurrentState.h = h; + mCurrentState.requested_w = w; + mCurrentState.requested_h = h; + mCurrentState.alpha = 0xFF; + mCurrentState.flags = layerFlags; + mCurrentState.sequence = 0; mCurrentState.transform.set(0, 0); // drawing state & current state are identical mDrawingState = mCurrentState; } -void LayerBase::commitTransaction(bool skipSize) { - const uint32_t w = mDrawingState.w; - const uint32_t h = mDrawingState.h; +void LayerBase::commitTransaction() { mDrawingState = mCurrentState; - if (skipSize) { - mDrawingState.w = w; - mDrawingState.h = h; - } } void LayerBase::forceVisibilityTransaction() { // this can be called without SurfaceFlinger.mStateLock, but if we @@ -144,10 +134,10 @@ bool LayerBase::setLayer(uint32_t z) { return true; } bool LayerBase::setSize(uint32_t w, uint32_t h) { - if (mCurrentState.w == w && mCurrentState.h == h) + if (mCurrentState.requested_w == w && mCurrentState.requested_h == h) return false; - mCurrentState.w = w; - mCurrentState.h = h; + mCurrentState.requested_w = w; + mCurrentState.requested_h = h; requestTransaction(); return true; } @@ -204,13 +194,25 @@ uint32_t LayerBase::doTransaction(uint32_t flags) const Layer::State& front(drawingState()); const Layer::State& temp(currentState()); - if (temp.sequence != front.sequence) { + if ((front.requested_w != temp.requested_w) || + (front.requested_h != temp.requested_h)) { + // resize the layer, set the physical size to the requested size + Layer::State& editTemp(currentState()); + editTemp.w = temp.requested_w; + editTemp.h = temp.requested_h; + } + + if ((front.w != temp.w) || (front.h != temp.h)) { // invalidate and recompute the visible regions if needed - flags |= eVisibleRegion; + flags |= Layer::eVisibleRegion; this->contentDirty = true; } if (temp.sequence != front.sequence) { + // invalidate and recompute the visible regions if needed + flags |= eVisibleRegion; + this->contentDirty = true; + const bool linearFiltering = mUseLinearFiltering; mUseLinearFiltering = false; if (!(mFlags & DisplayHardware::SLOW_CONFIG)) { @@ -223,7 +225,7 @@ uint32_t LayerBase::doTransaction(uint32_t flags) } // Commit the transaction - commitTransaction(flags & eRestartTransaction); + commitTransaction(); return flags; } diff --git a/libs/surfaceflinger/LayerBase.h b/libs/surfaceflinger/LayerBase.h index 233737db15..16ee542246 100644 --- a/libs/surfaceflinger/LayerBase.h +++ b/libs/surfaceflinger/LayerBase.h @@ -88,6 +88,8 @@ public: struct State { uint32_t w; uint32_t h; + uint32_t requested_w; + uint32_t requested_h; uint32_t z; uint8_t alpha; uint8_t flags; @@ -107,7 +109,7 @@ public: bool setTransparentRegionHint(const Region& opaque); bool setFlags(uint8_t flags, uint8_t mask); - void commitTransaction(bool skipSize); + void commitTransaction(); bool requestTransaction(); void forceVisibilityTransaction(); @@ -211,7 +213,6 @@ public: enum { // flags for doTransaction() eVisibleRegion = 0x00000002, - eRestartTransaction = 0x00000008 }; diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp index 4ee176c92a..e468b237f5 100644 --- a/libs/surfaceflinger/SurfaceFlinger.cpp +++ b/libs/surfaceflinger/SurfaceFlinger.cpp @@ -594,12 +594,6 @@ void SurfaceFlinger::handleTransactionLocked( const uint32_t flags = layer->doTransaction(0); if (flags & Layer::eVisibleRegion) mVisibleRegionsDirty = true; - - if (flags & Layer::eRestartTransaction) { - // restart the transaction, but back-off a little - layer->setTransactionFlags(eTransactionNeeded); - setTransactionFlags(eTraversalNeeded, ms2ns(8)); - } } } diff --git a/opengl/tests/gl_basic/Android.mk b/opengl/tests/gl_basic/Android.mk new file mode 100644 index 0000000000..6b6341fc35 --- /dev/null +++ b/opengl/tests/gl_basic/Android.mk @@ -0,0 +1,17 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + gl_basic.cpp + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libEGL \ + libGLESv1_CM \ + libui + +LOCAL_MODULE:= test-opengl-gl_basic + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_EXECUTABLE) diff --git a/opengl/tests/gl_basic/gl_basic.cpp b/opengl/tests/gl_basic/gl_basic.cpp new file mode 100644 index 0000000000..7dc2378edc --- /dev/null +++ b/opengl/tests/gl_basic/gl_basic.cpp @@ -0,0 +1,357 @@ +// Simple OpenGL ES 1.x application showing how to initialize and draw something. + +#include <EGL/egl.h>
+#include <GLES/gl.h> +#include <GLES/glext.h> + +#include <ui/FramebufferNativeWindow.h> +#include <ui/EGLUtils.h> + +#include <stdio.h>
+#include <stdlib.h> +#include <math.h> + +using namespace android; +
+EGLDisplay eglDisplay;
+EGLSurface eglSurface;
+EGLContext eglContext;
+GLuint texture;
+
+#define FIXED_ONE 0x10000 +#define ITERATIONS 50
+
+int init_gl_surface(void);
+void free_gl_surface(void);
+void init_scene(void);
+void render();
+void create_texture(void); +int readTimer(void);
+ +static void gluLookAt(float eyeX, float eyeY, float eyeZ, + float centerX, float centerY, float centerZ, float upX, float upY, + float upZ) +{ + // See the OpenGL GLUT documentation for gluLookAt for a description + // of the algorithm. We implement it in a straightforward way: + + float fx = centerX - eyeX; + float fy = centerY - eyeY; + float fz = centerZ - eyeZ; + + // Normalize f + float rlf = 1.0f / sqrtf(fx*fx + fy*fy + fz*fz); + fx *= rlf; + fy *= rlf; + fz *= rlf; + + // Normalize up + float rlup = 1.0f / sqrtf(upX*upX + upY*upY + upZ*upZ); + upX *= rlup; + upY *= rlup; + upZ *= rlup; + + // compute s = f x up (x means "cross product") + + float sx = fy * upZ - fz * upY; + float sy = fz * upX - fx * upZ; + float sz = fx * upY - fy * upX; + + // compute u = s x f + float ux = sy * fz - sz * fy; + float uy = sz * fx - sx * fz; + float uz = sx * fy - sy * fx; + + float m[16] ; + m[0] = sx; + m[1] = ux; + m[2] = -fx; + m[3] = 0.0f; + + m[4] = sy; + m[5] = uy; + m[6] = -fy; + m[7] = 0.0f; + + m[8] = sz; + m[9] = uz; + m[10] = -fz; + m[11] = 0.0f; + + m[12] = 0.0f; + m[13] = 0.0f; + m[14] = 0.0f; + m[15] = 1.0f; + + glMultMatrixf(m); + glTranslatef(-eyeX, -eyeY, -eyeZ); +} + + +void printEGLConfiguration(EGLDisplay dpy, EGLConfig config) { + +#define X(VAL) {VAL, #VAL} + struct {EGLint attribute; const char* name;} names[] = { + X(EGL_BUFFER_SIZE), + X(EGL_ALPHA_SIZE), + X(EGL_BLUE_SIZE), + X(EGL_GREEN_SIZE), + X(EGL_RED_SIZE), + X(EGL_DEPTH_SIZE), + X(EGL_STENCIL_SIZE), + X(EGL_CONFIG_CAVEAT), + X(EGL_CONFIG_ID), + X(EGL_LEVEL), + X(EGL_MAX_PBUFFER_HEIGHT), + X(EGL_MAX_PBUFFER_PIXELS), + X(EGL_MAX_PBUFFER_WIDTH), + X(EGL_NATIVE_RENDERABLE), + X(EGL_NATIVE_VISUAL_ID), + X(EGL_NATIVE_VISUAL_TYPE), + X(EGL_PRESERVED_RESOURCES), + X(EGL_SAMPLES), + X(EGL_SAMPLE_BUFFERS), + X(EGL_SURFACE_TYPE), + X(EGL_TRANSPARENT_TYPE), + X(EGL_TRANSPARENT_RED_VALUE), + X(EGL_TRANSPARENT_GREEN_VALUE), + X(EGL_TRANSPARENT_BLUE_VALUE), + X(EGL_BIND_TO_TEXTURE_RGB), + X(EGL_BIND_TO_TEXTURE_RGBA), + X(EGL_MIN_SWAP_INTERVAL), + X(EGL_MAX_SWAP_INTERVAL), + X(EGL_LUMINANCE_SIZE), + X(EGL_ALPHA_MASK_SIZE), + X(EGL_COLOR_BUFFER_TYPE), + X(EGL_RENDERABLE_TYPE), + X(EGL_CONFORMANT), + }; +#undef X + + for (size_t j = 0; j < sizeof(names) / sizeof(names[0]); j++) { + EGLint value = -1; + EGLint returnVal = eglGetConfigAttrib(dpy, config, names[j].attribute, &value); + EGLint error = eglGetError(); + if (returnVal && error == EGL_SUCCESS) { + printf(" %s: ", names[j].name); + printf("%d (0x%x)", value, value); + } + } + printf("\n"); +} + +static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) { + if (returnVal != EGL_TRUE) { + fprintf(stderr, "%s() returned %d\n", op, returnVal); + } + + for (EGLint error = eglGetError(); error != EGL_SUCCESS; error + = eglGetError()) { + fprintf(stderr, "after %s() eglError %s (0x%x)\n", op, EGLUtils::strerror(error), + error); + } +} + +int printEGLConfigurations(EGLDisplay dpy) { + EGLint numConfig = 0; + EGLint returnVal = eglGetConfigs(dpy, NULL, 0, &numConfig); + checkEglError("eglGetConfigs", returnVal); + if (!returnVal) { + return false; + } + + printf("Number of EGL configurations: %d\n", numConfig); + + EGLConfig* configs = (EGLConfig*) malloc(sizeof(EGLConfig) * numConfig); + if (! configs) { + printf("Could not allocate configs.\n"); + return false; + } + + returnVal = eglGetConfigs(dpy, configs, numConfig, &numConfig); + checkEglError("eglGetConfigs", returnVal); + if (!returnVal) { + free(configs); + return false; + } + + for(int i = 0; i < numConfig; i++) { + printf("Configuration %d\n", i); + printEGLConfiguration(dpy, configs[i]); + } + + free(configs); + return true; +} +
+int main(int argc, char **argv)
+{
+ int q; + int start, end;
+ + printf("Initializing EGL...\n"); +
+ if(!init_gl_surface())
+ {
+ printf("GL initialisation failed - exiting\n");
+ return 0;
+ }
+
+ init_scene();
+
+ create_texture();
+
+ printf("Running...\n"); + + while(true) { + render(); + }
+
+ free_gl_surface();
+
+ return 0;
+}
+
+int init_gl_surface(void)
+{
+ EGLint numConfigs = 1;
+ EGLConfig myConfig = {0};
+ EGLint attrib[] =
+ {
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_NONE
+ };
+
+ if ( (eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY )
+ {
+ printf("eglGetDisplay failed\n");
+ return 0;
+ } +
+ if ( eglInitialize(eglDisplay, NULL, NULL) != EGL_TRUE )
+ {
+ printf("eglInitialize failed\n");
+ return 0;
+ } + + if (! printEGLConfigurations(eglDisplay)) { + printf("printEGLConfigurations failed.\n"); + return 0; + }
+ EGLNativeWindowType window = android_createDisplaySurface();
+ EGLUtils::selectConfigForNativeWindow(eglDisplay, attrib, window, &myConfig);
+
+ if ( (eglSurface = eglCreateWindowSurface(eglDisplay, myConfig, + window, 0)) == EGL_NO_SURFACE )
+ {
+ printf("eglCreateWindowSurface failed\n");
+ return 0;
+ }
+
+ if ( (eglContext = eglCreateContext(eglDisplay, myConfig, 0, 0)) == EGL_NO_CONTEXT )
+ {
+ printf("eglCreateContext failed\n");
+ return 0;
+ }
+
+ if ( eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) != EGL_TRUE )
+ {
+ printf("eglMakeCurrent failed\n");
+ return 0;
+ }
+
+ return 1;
+}
+
+void free_gl_surface(void)
+{
+ if (eglDisplay != EGL_NO_DISPLAY)
+ {
+ eglMakeCurrent( EGL_NO_DISPLAY, EGL_NO_SURFACE,
+ EGL_NO_SURFACE, EGL_NO_CONTEXT );
+ eglDestroyContext( eglDisplay, eglContext );
+ eglDestroySurface( eglDisplay, eglSurface );
+ eglTerminate( eglDisplay );
+ eglDisplay = EGL_NO_DISPLAY;
+ }
+}
+
+void init_scene(void)
+{
+ glDisable(GL_DITHER); + glEnable(GL_CULL_FACE); + + float ratio = 320.0f / 480.0f; + glViewport(0, 0, 320, 480); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustumf(-ratio, ratio, -1, 1, 1, 10); + + glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity(); + gluLookAt( + 0, 0, 3, // eye + 0, 0, 0, // center + 0, 1, 0); // up +
+ glEnable(GL_TEXTURE_2D);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY); +}
+
+void create_texture(void)
+{
+ const unsigned int on = 0xff0000ff; + const unsigned int off = 0xffffffff; + const unsigned int pixels[] = + { + on, off, on, off, on, off, on, off, + off, on, off, on, off, on, off, on, + on, off, on, off, on, off, on, off, + off, on, off, on, off, on, off, on, + on, off, on, off, on, off, on, off, + off, on, off, on, off, on, off, on, + on, off, on, off, on, off, on, off, + off, on, off, on, off, on, off, on, + };
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+}
+
+void render()
+{
+ int i, j; + int quads = 1;
+
+ const GLfloat vertices[] = {
+ -1, -1, 0,
+ 1, -1, 0,
+ 1, 1, 0,
+ -1, 1, 0
+ };
+
+ const GLfixed texCoords[] = {
+ 0, 0,
+ FIXED_ONE, 0,
+ FIXED_ONE, FIXED_ONE,
+ 0, FIXED_ONE
+ };
+
+ const GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; +
+ glVertexPointer(3, GL_FLOAT, 0, vertices);
+ glTexCoordPointer(2, GL_FIXED, 0, texCoords); + + glClearColor(1.0, 1.0, 1.0, 1.0); + + int nelem = sizeof(indices)/sizeof(indices[0]); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + glDrawElements(GL_TRIANGLES, nelem, GL_UNSIGNED_SHORT, indices); + eglSwapBuffers(eglDisplay, eglSurface);
+}
+ diff --git a/opengl/tests/gl_jni/jni/gl_code.cpp b/opengl/tests/gl_jni/jni/gl_code.cpp index b85a433000..33b25ab6c7 100644 --- a/opengl/tests/gl_jni/jni/gl_code.cpp +++ b/opengl/tests/gl_jni/jni/gl_code.cpp @@ -2,16 +2,19 @@ #include <nativehelper/jni.h> #define LOG_TAG "GLJNI gl_code.cpp" -#include <utils/Log.h>
+#include <utils/Log.h> + #include <GLES/gl.h> -#include <stdio.h>
+#include <stdio.h> + #include <stdlib.h> #include <math.h> -
-GLuint texture;
-
-#define FIXED_ONE 0x10000
+ +GLuint texture; +GLfloat background; + +#define FIXED_ONE 0x10000 static void printGLString(const char *name, GLenum s) { const char *v = (const char *) glGetString(s); @@ -77,38 +80,38 @@ static void gluLookAt(float eyeX, float eyeY, float eyeZ, glTranslatef(-eyeX, -eyeY, -eyeZ); } -void init_scene(int width, int height)
+void init_scene(int width, int height) { printGLString("Version", GL_VERSION); printGLString("Vendor", GL_VENDOR); printGLString("Renderer", GL_RENDERER); - printGLString("Extensions", GL_EXTENSIONS);
+ printGLString("Extensions", GL_EXTENSIONS); + glDisable(GL_DITHER); glEnable(GL_CULL_FACE); - float ratio = width / height; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glFrustumf(-ratio, ratio, -1, 1, 1, 10);
+ glFrustumf(-ratio, ratio, -1, 1, 1, 10); + glMatrixMode(GL_MODELVIEW); - glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); gluLookAt( 0, 0, 3, // eye 0, 0, 0, // center 0, 1, 0); // up -
- glEnable(GL_TEXTURE_2D);
- glEnableClientState(GL_VERTEX_ARRAY);
+ + glEnable(GL_TEXTURE_2D); + glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); -}
-
-void create_texture()
-{
+} + +void create_texture() +{ const unsigned int on = 0xff0000ff; const unsigned int off = 0xffffffff; const unsigned int pixels[] = @@ -121,48 +124,47 @@ void create_texture() off, on, off, on, off, on, off, on, on, off, on, off, on, off, on, off, off, on, off, on, off, on, off, on, - };
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
- glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ }; + + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } extern "C" { JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_init(JNIEnv * env, jobject obj, jint width, jint height); JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_step(JNIEnv * env, jobject obj); + JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_changeBackground(JNIEnv * env, jobject obj); }; -
-
-JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_init(JNIEnv * env, jobject obj, jint width, jint height)
-{
- init_scene(width, height);
- create_texture();
-}
- -JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_step(JNIEnv * env, jobject obj)
-{
- const GLfloat vertices[] = {
- -1, -1, 0,
- 1, -1, 0,
- 1, 1, 0,
- -1, 1, 0
- };
-
- const GLfixed texCoords[] = {
- 0, 0,
- FIXED_ONE, 0,
- FIXED_ONE, FIXED_ONE,
- 0, FIXED_ONE
- };
-
- const GLushort quadIndices[] = { 0, 1, 2, 0, 2, 3 }; - glVertexPointer(3, GL_FLOAT, 0, vertices);
- glTexCoordPointer(2, GL_FIXED, 0, texCoords); +JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_init(JNIEnv * env, jobject obj, jint width, jint height) +{ + init_scene(width, height); + create_texture(); +} + +JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_step(JNIEnv * env, jobject obj) +{ + const GLfloat vertices[] = { + -1, -1, 0, + 1, -1, 0, + 1, 1, 0, + -1, 1, 0 + }; + + const GLfixed texCoords[] = { + 0, 0, + FIXED_ONE, 0, + FIXED_ONE, FIXED_ONE, + 0, FIXED_ONE + }; + const GLushort quadIndices[] = { 0, 1, 2, 0, 2, 3 }; + glVertexPointer(3, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FIXED, 0, texCoords); int nelem = sizeof(quadIndices)/sizeof(quadIndices[0]); static float grey; @@ -170,8 +172,12 @@ JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_step(JNIEnv * env, jobjec if (grey > 1.0f) { grey = 0.0f; } - glClearColor(grey, grey, grey, 1.0f); + glClearColor(background, grey, grey, 1.0f); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - glDrawElements(GL_TRIANGLES, nelem, GL_UNSIGNED_SHORT, quadIndices);
-}
+ glDrawElements(GL_TRIANGLES, nelem, GL_UNSIGNED_SHORT, quadIndices); +} +JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_changeBackground(JNIEnv * env, jobject obj) +{ + background = 1.0f - background; +}
\ No newline at end of file diff --git a/opengl/tests/gl_jni/src/com/android/gljni/GLJNIActivity.java b/opengl/tests/gl_jni/src/com/android/gljni/GLJNIActivity.java index df1f957df8..c6f53134f9 100644 --- a/opengl/tests/gl_jni/src/com/android/gljni/GLJNIActivity.java +++ b/opengl/tests/gl_jni/src/com/android/gljni/GLJNIActivity.java @@ -18,28 +18,27 @@ package com.android.gljni; import android.app.Activity; import android.os.Bundle; -import android.util.Log; -import android.view.WindowManager; - -import java.io.File; - public class GLJNIActivity extends Activity { GLJNIView mView; - @Override protected void onCreate(Bundle icicle) { + @Override + protected void onCreate(Bundle icicle) { super.onCreate(icicle); mView = new GLJNIView(getApplication()); - setContentView(mView); + mView.setFocusableInTouchMode(true); + setContentView(mView); } - @Override protected void onPause() { + @Override + protected void onPause() { super.onPause(); mView.onPause(); } - @Override protected void onResume() { + @Override + protected void onResume() { super.onResume(); mView.onResume(); } diff --git a/opengl/tests/gl_jni/src/com/android/gljni/GLJNILib.java b/opengl/tests/gl_jni/src/com/android/gljni/GLJNILib.java index 86627256b6..f56d2af95b 100644 --- a/opengl/tests/gl_jni/src/com/android/gljni/GLJNILib.java +++ b/opengl/tests/gl_jni/src/com/android/gljni/GLJNILib.java @@ -30,4 +30,5 @@ public class GLJNILib { */ public static native void init(int width, int height); public static native void step(); + public static native void changeBackground(); } diff --git a/opengl/tests/gl_jni/src/com/android/gljni/GLJNIView.java b/opengl/tests/gl_jni/src/com/android/gljni/GLJNIView.java index 9ea10597b6..9a2c8c4548 100644 --- a/opengl/tests/gl_jni/src/com/android/gljni/GLJNIView.java +++ b/opengl/tests/gl_jni/src/com/android/gljni/GLJNIView.java @@ -80,5 +80,11 @@ class GLJNIView extends GLSurfaceView { // Do nothing. } } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + GLJNILib.changeBackground(); + return true; + } } diff --git a/vpn/java/android/net/vpn/VpnType.java b/vpn/java/android/net/vpn/VpnType.java index c7df9438c7..356f8b1b0c 100644 --- a/vpn/java/android/net/vpn/VpnType.java +++ b/vpn/java/android/net/vpn/VpnType.java @@ -16,26 +16,28 @@ package android.net.vpn; +import com.android.internal.R; + /** * Enumeration of all supported VPN types. * {@hide} */ public enum VpnType { - PPTP("PPTP", "", PptpProfile.class), - L2TP("L2TP", "", L2tpProfile.class), - L2TP_IPSEC_PSK("L2TP/IPSec PSK", "Pre-shared key based L2TP/IPSec VPN", + PPTP("PPTP", R.string.pptp_vpn_description, PptpProfile.class), + L2TP("L2TP", R.string.l2tp_vpn_description, L2tpProfile.class), + L2TP_IPSEC_PSK("L2TP/IPSec PSK", R.string.l2tp_ipsec_psk_vpn_description, L2tpIpsecPskProfile.class), - L2TP_IPSEC("L2TP/IPSec CRT", "Certificate based L2TP/IPSec VPN", + L2TP_IPSEC("L2TP/IPSec CRT", R.string.l2tp_ipsec_crt_vpn_description, L2tpIpsecProfile.class); private String mDisplayName; - private String mDescription; + private int mDescriptionId; private Class<? extends VpnProfile> mClass; - VpnType(String displayName, String description, + VpnType(String displayName, int descriptionId, Class<? extends VpnProfile> klass) { mDisplayName = displayName; - mDescription = description; + mDescriptionId = descriptionId; mClass = klass; } @@ -43,8 +45,8 @@ public enum VpnType { return mDisplayName; } - public String getDescription() { - return mDescription; + public int getDescriptionId() { + return mDescriptionId; } public Class<? extends VpnProfile> getProfileClass() { |