Ejemplo n.º 1
0
  private View createGLSurfaceView(
      Activity activity, boolean useGL2, final ResolutionStrategy resolutionStrategy) {
    EGLConfigChooser configChooser = getEglConfigChooser();
    if (useGL2 && checkGL20()) {
      //			GLSurfaceView20 view = new GLSurfaceView20(activity, resolutionStrategy);
      GLSurfaceView20 view = new GLSurfaceView20(activity, true, 16, 0, resolutionStrategy);
      Log.v("launcher", "create gl");
      //			view.setZOrderOnTop(true);
      if (configChooser != null) view.setEGLConfigChooser(configChooser);
      else
        view.setEGLConfigChooser(
            config.r, config.g, config.b, config.a, config.depth, config.stencil);
      // view.pauseEglHelper = config.pauseEglHelper;
      view.setRenderer(this);
      return view;
    } else {
      config.useGL20 = false;
      configChooser = getEglConfigChooser();
      int sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK);
      if (sdkVersion >= 11) {
        GLSurfaceView view =
            new GLSurfaceView(activity) {

              @Override
              protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                ResolutionStrategy.MeasuredDimension measures =
                    resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec);
                setMeasuredDimension(measures.width, measures.height);
              }
            };
        if (configChooser != null) view.setEGLConfigChooser(configChooser);
        else
          view.setEGLConfigChooser(
              config.r, config.g, config.b, config.a, config.depth, config.stencil);
        // view.pauseEglHelper = config.pauseEglHelper;
        view.setRenderer(this);
        return view;
      } else {
        GLSurfaceViewCupcake view = new GLSurfaceViewCupcake(activity, resolutionStrategy);
        if (configChooser != null) view.setEGLConfigChooser(configChooser);
        else
          view.setEGLConfigChooser(
              config.r, config.g, config.b, config.a, config.depth, config.stencil);
        view.setRenderer(this);
        return view;
      }
    }
  }
  // Grabbed from original AndroidGraphics class, with modifications:
  //	+ overrided getHolder in created GLSurfaceView instances
  // + Activity changed to Context (as it should be in AndroidGraphics I think;p)
  private View createGLSurfaceView(
      Context context, boolean useGL2, final ResolutionStrategy resolutionStrategy) {
    EGLConfigChooser configChooser = getEglConfigChooser();

    if (useGL2 && checkGL20()) {
      GLSurfaceView20 view =
          new GLSurfaceView20(context, resolutionStrategy) {
            // -> specific for live wallpapers
            @Override
            public SurfaceHolder getHolder() {
              return getSurfaceHolder();
            }

            public void onDestroy() {
              onDetachedFromWindow(); // calls GLSurfaceView.mGLThread.requestExitAndWait();
            }
            // <- specific for live wallpapers
          };

      if (configChooser != null) view.setEGLConfigChooser(configChooser);
      else
        view.setEGLConfigChooser(
            config.r, config.g, config.b, config.a, config.depth, config.stencil);
      view.setRenderer(this);
      return view;
    } else {
      config.useGL20 = false;
      configChooser = getEglConfigChooser();
      int sdkVersion = android.os.Build.VERSION.SDK_INT;

      if (sdkVersion >= 11) {
        GLSurfaceView view =
            new GLSurfaceView(context) {
              @Override
              protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                ResolutionStrategy.MeasuredDimension measures =
                    resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec);
                setMeasuredDimension(measures.width, measures.height);
              }
              // -> specific for live wallpapers
              @Override
              public SurfaceHolder getHolder() {
                return getSurfaceHolder();
              }

              public void onDestroy() {
                onDetachedFromWindow(); // calls GLSurfaceView.mGLThread.requestExitAndWait();
              }
              // <- specific for live wallpapers
            };
        if (configChooser != null) view.setEGLConfigChooser(configChooser);
        else
          view.setEGLConfigChooser(
              config.r, config.g, config.b, config.a, config.depth, config.stencil);
        view.setRenderer(this);
        return view;
      } else {
        if (config.useGLSurfaceViewAPI18) {
          GLSurfaceViewAPI18 view =
              new GLSurfaceViewAPI18(context, resolutionStrategy) {
                // -> specific for live wallpapers
                @Override
                public SurfaceHolder getHolder() {
                  return getSurfaceHolder();
                }
                // <- specific for live wallpapers
              };
          if (configChooser != null) view.setEGLConfigChooser(configChooser);
          else
            view.setEGLConfigChooser(
                config.r, config.g, config.b, config.a, config.depth, config.stencil);
          view.setRenderer(this);
          return view;
        } else {
          GLSurfaceViewCupcake view =
              new GLSurfaceViewCupcake(context, resolutionStrategy) {
                // -> specific for live wallpapers
                @Override
                public SurfaceHolder getHolder() {
                  return getSurfaceHolder();
                }
                // <- specific for live wallpapers
              };
          if (configChooser != null) view.setEGLConfigChooser(configChooser);
          else
            view.setEGLConfigChooser(
                config.r, config.g, config.b, config.a, config.depth, config.stencil);
          view.setRenderer(this);
          return view;
        }
      }
    }
  }