package com.metaio.sdk;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.PointF;
import android.graphics.Rect;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.EGLConfigChooser;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.SparseArray;
import android.view.Display;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.WindowManager;
import java.nio.Buffer;
import java.nio.IntBuffer;
import java.util.Arrays;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;

@TargetApi(9)
public final class MetaioSurfaceView extends GLSurfaceView
  implements GLSurfaceView.Renderer
{
  private static String mGLDevice;
  private Callback mCallback;

  public MetaioSurfaceView(Context paramContext)
  {
    super(paramContext);
    initialize(getDefaultEGLConfigChooser(), 1);
  }

  public MetaioSurfaceView(Context paramContext, GLSurfaceView.EGLConfigChooser paramEGLConfigChooser)
  {
    super(paramContext);
    initialize(paramEGLConfigChooser, 1);
  }

  public MetaioSurfaceView(Context paramContext, GLSurfaceView.EGLConfigChooser paramEGLConfigChooser, int paramInt)
  {
    super(paramContext);
    initialize(paramEGLConfigChooser, paramInt);
  }

  public MetaioSurfaceView(Context paramContext, boolean paramBoolean)
  {
    super(paramContext);
    initialize(getDefaultEGLConfigChooser(), -3);
  }

  private static GLSurfaceView.EGLConfigChooser getDefaultEGLConfigChooser()
  {
    String[] arrayOfString1 = { "ace", "Desire HD", "DM009SH", "F-01D", "GP707", "GT-I9000", "GT-I9000B", "GT-I9000T", "GT-I9001", "GT-I9003", "GT-P1000", "GT-P1000L", "GT-P1010", "hwu9000", "HTC Flyer P512", "HTC Sensation 4G", "iproj", "IS05", "IS11N", "IS11S", "IS15SH", "KIS PLUS", "lgp970", "LG-MS840", "LG-P920", "LG-P936", "LifeTouch_D1", "ME302KL", "N-04C", "N-05D", "qsd8k_slim", "R800a", "R800x", "saga", "SBM005SH", "SBM007SH", "SC-01C", "SC-02B", "SCH-I400", "SCH-R910", "SGH-I897", "SGH-I997", "SGH-T759", "SGH-T959", "SGH-T959V", "SH03C", "SHI03", "SHI05", "SMT-i9100", "SO-01C", "SO-02C", "SPH-M930BST", "ST25a", "streak", "tg03", "umts_jordan", "umts_primus", "umts_sholes", "umts_venus2", "venue", "vision", "YP-G70" };
    Arrays.sort(arrayOfString1);
    String[] arrayOfString2 = { "LT15i", "LT18i", "X10i", "MK16a" };
    Arrays.sort(arrayOfString2);
    if (Arrays.binarySearch(arrayOfString1, Build.MODEL) >= 0)
      return null;
    if (Arrays.binarySearch(arrayOfString2, Build.MODEL) >= 0)
      return new ConfigChooser(8, 8, 8, 8, 24, 0, 1);
    return new ConfigChooser(8, 8, 8, 8, 24, 0, 4);
  }

  public static GLSurfaceView.EGLConfigChooser getEGLConfigChooser(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6, int paramInt7)
  {
    return new ConfigChooser(paramInt1, paramInt2, paramInt3, paramInt4, paramInt5, paramInt6, paramInt7);
  }

  private Bitmap getFrameBuffer(GL10 paramGL10)
  {
    int i;
    int k;
    int m;
    try
    {
      i = getHeight();
      int j = getWidth();
      int[] arrayOfInt1 = new int[i * j];
      int[] arrayOfInt2 = new int[i * j];
      IntBuffer localIntBuffer = IntBuffer.wrap(arrayOfInt1);
      localIntBuffer.position(0);
      paramGL10.glReadPixels(0, 0, j, i, 6408, 5121, localIntBuffer);
      k = 0;
      break label179;
      while (m < j)
      {
        int n = arrayOfInt1[(m + k * j)];
        int i1 = 0xFF & n >> 16 | (0xFF0000 & n << 16 | n & 0xFF00FF00);
        arrayOfInt2[(m + j * (-1 + (i - k)))] = i1;
        m++;
        continue;
        label135: Bitmap localBitmap = Bitmap.createBitmap(arrayOfInt2, j, i, Bitmap.Config.ARGB_8888);
        return localBitmap;
      }
    }
    catch (Exception localException)
    {
      MetaioDebug.log("MetaioSurfaceView: " + localException.getMessage());
      return null;
    }
    while (true)
    {
      label179: if (k >= i)
        break label135;
      m = 0;
      break;
      k++;
    }
  }

  private void initialize(GLSurfaceView.EGLConfigChooser paramEGLConfigChooser, int paramInt)
  {
    setTag(MetaioSurfaceView.class);
    try
    {
      setEGLContextClientVersion(2);
      if (paramEGLConfigChooser != null)
        setEGLConfigChooser(paramEGLConfigChooser);
      while (true)
      {
        if ((Build.MODEL.contentEquals("embt2")) && (paramInt == 1))
          paramInt = 3;
        getHolder().setFormat(paramInt);
        setRenderer(this);
        return;
        MetaioDebug.log(5, "MetaioSurfaceView: No EGLConfig selected");
      }
    }
    catch (Exception localException)
    {
      MetaioDebug.log(6, "Error initializing MetaioSurfaceView");
      MetaioDebug.printStackTrace(6, localException);
    }
  }

  private static void printDevice(GL10 paramGL10)
  {
    String str1 = paramGL10.glGetString(7936);
    String str2 = paramGL10.glGetString(7937);
    String str3 = paramGL10.glGetString(7938);
    mGLDevice = str1 + ", " + str2 + ", " + str3;
    MetaioDebug.log(4, "GL device: " + mGLDevice);
  }

  public String getGLDeviceInfo()
  {
    return mGLDevice;
  }

  public PointF globalToLocalViewCoordinates(MotionEvent paramMotionEvent, Rect paramRect)
  {
    Display localDisplay = ((WindowManager)getContext().getSystemService("window")).getDefaultDisplay();
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    localDisplay.getMetrics(localDisplayMetrics);
    float f1 = localDisplayMetrics.widthPixels;
    float f2 = localDisplayMetrics.heightPixels - paramRect.top;
    MetaioDebug.log("MetaioSurfaceView.transformGlobalToLocalViewCoordinates: window size: " + f1 + ", " + f2);
    MetaioDebug.log("MetaioSurfaceView.transformGlobalToLocalViewCoordinates: event.getRaw: " + paramMotionEvent.getRawX() + ", " + paramMotionEvent.getRawY());
    float f3 = paramMotionEvent.getRawX() - (localDisplayMetrics.widthPixels - f1);
    float f4 = paramMotionEvent.getRawY() - (localDisplayMetrics.heightPixels - f2);
    MetaioDebug.log("MetaioSurfaceView.transformGlobalToLocalViewCoordinates: window coordinates: " + f3 + ", " + f4);
    float f5 = (getWidth() - f1) / 2.0F;
    float f6 = (getHeight() - f2) / 2.0F;
    MetaioDebug.log("MetaioSurfaceView.transformGlobalToLocalViewCoordinates: offset: " + f5 + ", " + f6);
    float f7 = f3 * getWidth() / f1;
    float f8 = f4 * getHeight() / f2;
    MetaioDebug.log("MetaioSurfaceView.transformGlobalToLocalViewCoordinates: SurfaceView coordinates: " + f7 + ", " + f8);
    return new PointF(f7, f8);
  }

  public void onDrawFrame(GL10 paramGL10)
  {
    try
    {
      if (this.mCallback != null)
        this.mCallback.onDrawFrame();
      int i = paramGL10.glGetError();
      if (i != 0)
      {
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = Integer.valueOf(i);
        MetaioDebug.log(6, String.format("OpenGL error: 0x%04x", arrayOfObject));
      }
      return;
    }
    catch (Exception localException)
    {
      while (true)
      {
        MetaioDebug.log(6, "Exception in MetaioSurfaceView.Callback.onDrawFrame implementation");
        MetaioDebug.printStackTrace(6, localException);
      }
    }
  }

  public void onPause()
  {
    super.onPause();
    MetaioDebug.log("MetaioSurfaceView.onPause");
  }

  public void onResume()
  {
    super.onResume();
    MetaioDebug.log("MetaioSurfaceView.onResume");
  }

  public void onSurfaceChanged(GL10 paramGL10, int paramInt1, int paramInt2)
  {
    MetaioDebug.log("MetaioSurfaceView.onSurfaceChanged: " + paramInt1 + ", " + paramInt2);
    paramGL10.glViewport(0, 0, paramInt1, paramInt2);
    try
    {
      if (this.mCallback != null)
        this.mCallback.onSurfaceChanged(paramInt1, paramInt2);
      return;
    }
    catch (Exception localException)
    {
      MetaioDebug.log(6, "Exception in MetaioSurfaceView.Callback.onSurfaceChanged implementation");
      MetaioDebug.printStackTrace(6, localException);
    }
  }

  public void onSurfaceCreated(GL10 paramGL10, EGLConfig paramEGLConfig)
  {
    MetaioDebug.log("MetaioSurfaceView.onSurfaceCreated");
    printDevice(paramGL10);
    try
    {
      if (this.mCallback != null)
        this.mCallback.onSurfaceCreated();
      return;
    }
    catch (Exception localException)
    {
      MetaioDebug.log(6, "Exception in MetaioSurfaceView.Callback.onSurfaceCreated implementation");
      MetaioDebug.printStackTrace(6, localException);
    }
  }

  public void registerCallback(Callback paramCallback)
  {
    this.mCallback = paramCallback;
  }

  public void surfaceChanged(SurfaceHolder paramSurfaceHolder, int paramInt1, int paramInt2, int paramInt3)
  {
    MetaioDebug.log("MetaioSurfaceView.surfaceChanged: " + paramInt1 + ", " + paramInt2 + ", " + paramInt3);
    super.surfaceChanged(paramSurfaceHolder, paramInt1, paramInt2, paramInt3);
  }

  public void surfaceCreated(SurfaceHolder paramSurfaceHolder)
  {
    MetaioDebug.log("MetaioSurfaceView.surfaceCreated");
    super.surfaceCreated(paramSurfaceHolder);
  }

  public void surfaceDestroyed(SurfaceHolder paramSurfaceHolder)
  {
    super.surfaceDestroyed(paramSurfaceHolder);
    MetaioDebug.log("MetaioSurfaceView.surfaceDestroyed");
    try
    {
      if (this.mCallback != null)
        this.mCallback.onSurfaceDestroyed();
      paramSurfaceHolder.removeCallback(this);
      this.mCallback = null;
      return;
    }
    catch (Exception localException)
    {
      while (true)
      {
        MetaioDebug.log(6, "Exception in MetaioSurfaceView.Callback.onSurfaceDetsroyed implementation");
        MetaioDebug.printStackTrace(6, localException);
      }
    }
  }

  public static abstract interface Callback
  {
    public abstract void onDrawFrame();

    public abstract void onSurfaceChanged(int paramInt1, int paramInt2);

    public abstract void onSurfaceCreated();

    public abstract void onSurfaceDestroyed();
  }

  private static final class ConfigChooser
    implements GLSurfaceView.EGLConfigChooser
  {
    private static final int EGL_OPENGL_ES2_BIT = 4;
    private static final SparseArray<String> mAttributes = new SparseArray();
    protected int mAlphaSize;
    protected int mBlueSize;
    protected int mDepthSize;
    protected int mGreenSize;
    protected int mRedSize;
    protected int mSamples;
    protected int mStencilSize;

    static
    {
      mAttributes.put(12328, "EGL_CONFIG_ID");
      mAttributes.put(12320, "EGL_BUFFER_SIZE");
      mAttributes.put(12321, "EGL_ALPHA_SIZE");
      mAttributes.put(12322, "EGL_BLUE_SIZE");
      mAttributes.put(12323, "EGL_GREEN_SIZE");
      mAttributes.put(12324, "EGL_RED_SIZE");
      mAttributes.put(12325, "EGL_DEPTH_SIZE");
      mAttributes.put(12326, "EGL_STENCIL_SIZE");
      mAttributes.put(12327, "EGL_CONFIG_CAVEAT");
      mAttributes.put(12329, "EGL_LEVEL");
      mAttributes.put(12330, "EGL_MAX_PBUFFER_HEIGHT");
      mAttributes.put(12331, "EGL_MAX_PBUFFER_PIXELS");
      mAttributes.put(12332, "EGL_MAX_PBUFFER_WIDTH");
      mAttributes.put(12333, "EGL_NATIVE_RENDERABLE");
      mAttributes.put(12334, "EGL_NATIVE_VISUAL_ID");
      mAttributes.put(12335, "EGL_NATIVE_VISUAL_TYPE");
      mAttributes.put(12337, "EGL_SAMPLES");
      mAttributes.put(12338, "EGL_SAMPLE_BUFFERS");
      mAttributes.put(12339, "EGL_SURFACE_TYPE");
      mAttributes.put(12340, "EGL_TRANSPARENT_TYPE");
      mAttributes.put(12343, "EGL_TRANSPARENT_RED_VALUE");
      mAttributes.put(12342, "EGL_TRANSPARENT_GREEN_VALUE");
      mAttributes.put(12341, "EGL_TRANSPARENT_BLUE_VALUE");
      mAttributes.put(12345, "EGL_BIND_TO_TEXTURE_RGB");
      mAttributes.put(12346, "EGL_BIND_TO_TEXTURE_RGBA");
      mAttributes.put(12347, "EGL_MIN_SWAP_INTERVAL");
      mAttributes.put(12348, "EGL_MAX_SWAP_INTERVAL");
      mAttributes.put(12349, "EGL_LUMINANCE_SIZE");
      mAttributes.put(12350, "EGL_ALPHA_MASK_SIZE");
      mAttributes.put(12351, "EGL_COLOR_BUFFER_TYPE");
      mAttributes.put(12352, "EGL_RENDERABLE_TYPE");
      mAttributes.put(12354, "EGL_CONFORMANT");
    }

    public ConfigChooser(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6, int paramInt7)
    {
      this.mRedSize = paramInt1;
      this.mGreenSize = paramInt2;
      this.mBlueSize = paramInt3;
      this.mAlphaSize = paramInt4;
      this.mDepthSize = paramInt5;
      this.mStencilSize = paramInt6;
      this.mSamples = paramInt7;
    }

    public static String inflateConfig(EGL10 paramEGL10, EGLDisplay paramEGLDisplay, EGLConfig paramEGLConfig)
    {
      int[] arrayOfInt = new int[1];
      Object localObject1 = "";
      int i = 0;
      if (i < mAttributes.size())
      {
        int j = mAttributes.keyAt(i);
        String str = (String)mAttributes.valueAt(i);
        if (paramEGL10.eglGetConfigAttrib(paramEGLDisplay, paramEGLConfig, j, arrayOfInt));
        for (Object localObject2 = ((String)localObject1).concat(str + ", " + arrayOfInt[0] + ";"); ; localObject2 = localObject1)
        {
          i++;
          localObject1 = localObject2;
          break;
          MetaioDebug.log(5, "Failed to retrieve EGLConfig parameter: " + str);
          while (paramEGL10.eglGetError() != 12288);
        }
      }
      return localObject1;
    }

    public static void printConfigs(EGL10 paramEGL10, EGLDisplay paramEGLDisplay, EGLConfig[] paramArrayOfEGLConfig)
    {
      MetaioDebug.log(4, "EGLConfigs supported:" + paramArrayOfEGLConfig.length);
      int i = paramArrayOfEGLConfig.length;
      for (int j = 0; j < i; j++)
        MetaioDebug.log(4, inflateConfig(paramEGL10, paramEGLDisplay, paramArrayOfEGLConfig[j]));
    }

    public EGLConfig chooseConfig(EGL10 paramEGL10, EGLDisplay paramEGLDisplay)
    {
      int[] arrayOfInt1 = new int[17];
      arrayOfInt1[0] = 12324;
      arrayOfInt1[1] = this.mRedSize;
      arrayOfInt1[2] = 12323;
      arrayOfInt1[3] = this.mGreenSize;
      arrayOfInt1[4] = 12322;
      arrayOfInt1[5] = this.mBlueSize;
      arrayOfInt1[6] = 12321;
      arrayOfInt1[7] = this.mAlphaSize;
      arrayOfInt1[8] = 12325;
      arrayOfInt1[9] = this.mDepthSize;
      arrayOfInt1[10] = 12326;
      arrayOfInt1[11] = this.mStencilSize;
      arrayOfInt1[12] = 12337;
      arrayOfInt1[13] = this.mSamples;
      arrayOfInt1[14] = 12352;
      arrayOfInt1[15] = 4;
      arrayOfInt1[16] = 12344;
      int[] arrayOfInt2 = new int[1];
      if (!paramEGL10.eglChooseConfig(paramEGLDisplay, arrayOfInt1, null, 0, arrayOfInt2))
        MetaioDebug.log(6, "eglChooseConfig failed at MetaioSurfaceView:" + java.lang.Thread.currentThread().getStackTrace()[3].getLineNumber());
      int i = arrayOfInt2[0];
      int[] arrayOfInt4;
      if (i <= 0)
      {
        MetaioDebug.log(5, "EGLConfig with specified atrributes not found, trying coverage multisampling!");
        arrayOfInt4 = new int[17];
        arrayOfInt4[0] = 12324;
        arrayOfInt4[1] = this.mRedSize;
        arrayOfInt4[2] = 12323;
        arrayOfInt4[3] = this.mGreenSize;
        arrayOfInt4[4] = 12322;
        arrayOfInt4[5] = this.mBlueSize;
        arrayOfInt4[6] = 12321;
        arrayOfInt4[7] = this.mAlphaSize;
        arrayOfInt4[8] = 12325;
        arrayOfInt4[9] = 16;
        arrayOfInt4[10] = 12352;
        arrayOfInt4[11] = 4;
        arrayOfInt4[12] = 12512;
        arrayOfInt4[13] = 1;
        arrayOfInt4[14] = 12513;
        arrayOfInt4[15] = 2;
        arrayOfInt4[16] = 12344;
        if (!paramEGL10.eglChooseConfig(paramEGLDisplay, arrayOfInt4, null, 0, arrayOfInt2))
          MetaioDebug.log(6, "eglChooseConfig failed at MetaioSurfaceView:" + java.lang.Thread.currentThread().getStackTrace()[3].getLineNumber());
        if (arrayOfInt2[0] <= 0)
        {
          MetaioDebug.log(5, "EGLConfig with specified atrributes not found, trying minimum attribute values!");
          arrayOfInt4 = new int[] { 12324, 5, 12323, 6, 12322, 5, 12321, 8, 12325, 16, 12352, 4, 12344 };
        }
        if (!paramEGL10.eglChooseConfig(paramEGLDisplay, arrayOfInt4, null, 0, arrayOfInt2))
          MetaioDebug.log(6, "eglChooseConfig failed at MetaioSurfaceView:" + java.lang.Thread.currentThread().getStackTrace()[3].getLineNumber());
        i = arrayOfInt2[0];
      }
      for (int[] arrayOfInt3 = arrayOfInt4; ; arrayOfInt3 = arrayOfInt1)
      {
        if (i <= 0)
        {
          MetaioDebug.log(6, "No EGLConfig found that matches the given parameters");
          return null;
        }
        EGLConfig[] arrayOfEGLConfig = new EGLConfig[i];
        paramEGL10.eglChooseConfig(paramEGLDisplay, arrayOfInt3, arrayOfEGLConfig, i, arrayOfInt2);
        printConfigs(paramEGL10, paramEGLDisplay, arrayOfEGLConfig);
        MetaioDebug.log("EGLConfig choosen: " + inflateConfig(paramEGL10, paramEGLDisplay, arrayOfEGLConfig[0]));
        return arrayOfEGLConfig[0];
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.metaio.sdk.MetaioSurfaceView
 * JD-Core Version:    0.6.2
 */