Java Code Examples for android.opengl.GLSurfaceView#setPreserveEGLContextOnPause()

The following examples show how to use android.opengl.GLSurfaceView#setPreserveEGLContextOnPause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VrShellImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@UsedByReflection("VrShellDelegate.java")
public VrShellImpl(Activity activity) {
    super(activity);
    mActivity = activity;
    mContentViewCoreContainer = new FrameLayout(getContext()) {
        @Override
        public boolean dispatchTouchEvent(MotionEvent event) {
            return true;
        }
    };
    addView(mContentViewCoreContainer, 0, new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT));
    mGlSurfaceView = new GLSurfaceView(getContext());
    mGlSurfaceView.setEGLContextClientVersion(2);
    mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0);
    mGlSurfaceView.setPreserveEGLContextOnPause(true);
    mGlSurfaceView.setRenderer(this);
    setPresentationView(mGlSurfaceView);

    if (setAsyncReprojectionEnabled(true)) {
        AndroidCompat.setSustainedPerformanceMode(mActivity, true);
    }
}
 
Example 2
Source File: RoomChatPresenter.java    From VideoMeeting with Apache License 2.0 6 votes vote down vote up
public RoomChatPresenter(IRoomChatView view) {
    mView = view;
    mSocketAddress = "http://" + App.getInstance().getString(R.string.stream_host);
    mSocketAddress += (":" + App.getInstance().getString(R.string.stream_port) + "/");

    GLSurfaceView surfaceView = mView.getSurfaceView();
    surfaceView.setPreserveEGLContextOnPause(true);
    surfaceView.setKeepScreenOn(true);
    VideoRendererGui.setView(surfaceView, new Runnable() {
        @Override
        public void run() {
            // SurfaceView 准备完毕
            L.d("eglContextReadyCallback");
            init();
        }
    });

    localRender = VideoRendererGui.create(
            0, 0,
            50, 50, scalingType, true);

}
 
Example 3
Source File: JanusActivity.java    From janus-gateway-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
    java.lang.System.setProperty("java.net.preferIPv4Stack", "true");
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_janus);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    vsv = (GLSurfaceView) findViewById(R.id.glview);
    vsv.setPreserveEGLContextOnPause(true);
    vsv.setKeepScreenOn(true);
    VideoRendererGui.setView(vsv, new MyInit());

    localRender = VideoRendererGui.create(72, 72, 25, 25, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, false);
    remoteRender = VideoRendererGui.create(0, 0, 25, 25, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true);
}
 
Example 4
Source File: VideoChatActivity.java    From Socket.io-FLSocketIM-Android with MIT License 5 votes vote down vote up
@Override
protected void initData() {
    super.initData();

    Bundle bundle = getIntent().getExtras();
    String fromUser = bundle.getString("fromUser");
    String toUser = bundle.getString("toUser");
    String room = bundle.getString("room");
    this.fromUser = fromUser;
    this.toUser = toUser;
    this.room = room;
    int type = bundle.getInt("type");
    videoType = type == 0?ChatVideoType.videoTypeCaller:ChatVideoType.videoTypeCallee;
    videoView = new GLSurfaceView(mContext);
    videoView.setPreserveEGLContextOnPause(true);
    videoView.setKeepScreenOn(true);
    VideoRendererGui.setView(videoView, new Runnable() {
        @Override
        public void run() {

            initHelper();
        }
    });
    FrameLayout layout = findViewById(R.id.video_view_back);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    layout.addView(videoView, layoutParams);

    /*
    * 两者初始化顺序会影响最终渲染层的层次结构
    * */
    remoteRender = VideoRendererGui.create(0, 0, 100, 100, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true);
    localRender = VideoRendererGui.create(66, 0, 33, 33, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true);

}
 
Example 5
Source File: VideoRendererGui.java    From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private VideoRendererGui(GLSurfaceView surface) {
  this.surface = surface;
  // Create an OpenGL ES 2.0 context.
  surface.setPreserveEGLContextOnPause(true);
  surface.setEGLContextClientVersion(2);
  surface.setRenderer(this);
  surface.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

  yuvImageRenderers = new ArrayList<YuvImageRenderer>();
}
 
Example 6
Source File: MainActivity.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setImmersiveSticky();
  getWindow()
      .getDecorView()
      .setOnSystemUiVisibilityChangeListener(
          new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
              if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                setImmersiveSticky();
              }
            }
          });

  // Enable VR mode, if the device supports it.
  AndroidCompat.setVrModeEnabled(this, true);

  // Get the GvrLayout.
  gvrLayout = new GvrLayout(this);

  // Enable scan line racing, if possible.
  if (gvrLayout.setAsyncReprojectionEnabled(true)) {
    Log.d(TAG, "Successfully enabled scanline racing.");
    // Scanline racing decouples the app framerate from the display framerate,
    // allowing immersive interaction even at the throttled clockrates set by
    // sustained performance mode.
    AndroidCompat.setSustainedPerformanceMode(this, true);
  } else {
    Log.w(TAG, "Failed to enable scanline racing.");
  }

  // Configure the GLSurfaceView.
  surfaceView = new GLSurfaceView(this);
  surfaceView.setEGLContextClientVersion(2);
  surfaceView.setEGLConfigChooser(8, 8, 8, 0, 0, 0);
  surfaceView.setPreserveEGLContextOnPause(true);
  surfaceView.setRenderer(renderer);

  // Set the GLSurfaceView as the GvrLayout's presentation view.
  gvrLayout.setPresentationView(surfaceView);

  // Enable and configure the back button in the UI layout.
  gvrLayout
      .getUiLayout()
      .setBackButtonListener(
          new Runnable() {
            @Override
            public void run() {
              onBackPressed();
            }
          });

  // Add the GvrLayout to the View hierarchy.
  setContentView(gvrLayout);

  assetManager = getResources().getAssets();

  nativeOnCreate(assetManager, gvrLayout.getGvrApi().getNativeGvrContext());

  // Prevent screen from dimming/locking.
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
 
Example 7
Source File: OGLESContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * <code>createView</code> creates the GLSurfaceView that the renderer will
 * draw to. <p> The result GLSurfaceView will receive input events and
 * forward them to the Application. Any rendering will be done into the
 * GLSurfaceView. Only one GLSurfaceView can be created at this time. The
 * given configType specifies how to determine the display configuration.
 *
 * @return GLSurfaceView The newly created view
 */
public GLSurfaceView createView(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ConfigurationInfo info = am.getDeviceConfigurationInfo();
    // NOTE: We assume all ICS devices have OpenGL ES 2.0.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // below 4.0, check OpenGL ES 2.0 support.
        if (info.reqGlEsVersion < 0x20000) {
            throw new UnsupportedOperationException("OpenGL ES 2.0 or better is not supported on this device");
        }
    } else if (Build.VERSION.SDK_INT < 9){
        throw new UnsupportedOperationException("jME3 requires Android 2.3 or later");
    }

    // Start to set up the view
    GLSurfaceView view = new GLSurfaceView(context);
    logger.log(Level.INFO, "Android Build Version: {0}", Build.VERSION.SDK_INT);
    if (androidInput == null) {
        if (Build.VERSION.SDK_INT >= 14) {
            androidInput = new AndroidInputHandler14();
        } else if (Build.VERSION.SDK_INT >= 9){
            androidInput = new AndroidInputHandler();
        }
    }
    androidInput.setView(view);
    androidInput.loadSettings(settings);

    // setEGLContextClientVersion must be set before calling setRenderer
    // this means it cannot be set in AndroidConfigChooser (too late)
    // use proper openGL ES version
    view.setEGLContextClientVersion(info.reqGlEsVersion>>16);

    view.setFocusableInTouchMode(true);
    view.setFocusable(true);

    // setFormat must be set before AndroidConfigChooser is called by the surfaceview.
    // if setFormat is called after ConfigChooser is called, then execution
    // stops at the setFormat call without a crash.
    // We look at the user setting for alpha bits and set the surfaceview
    // PixelFormat to either Opaque, Transparent, or Translucent.
    // ConfigChooser will do its best to honor the alpha requested by the user
    // For best rendering performance, use Opaque (alpha bits = 0).
    int curAlphaBits = settings.getAlphaBits();
    logger.log(Level.FINE, "curAlphaBits: {0}", curAlphaBits);
    if (curAlphaBits >= 8) {
        logger.log(Level.FINE, "Pixel Format: TRANSLUCENT");
        view.getHolder().setFormat(PixelFormat.TRANSLUCENT);
        view.setZOrderOnTop(true);
    } else if (curAlphaBits >= 1) {
        logger.log(Level.FINE, "Pixel Format: TRANSPARENT");
        view.getHolder().setFormat(PixelFormat.TRANSPARENT);
    } else {
        logger.log(Level.FINE, "Pixel Format: OPAQUE");
        view.getHolder().setFormat(PixelFormat.OPAQUE);
    }

    AndroidConfigChooser configChooser = new AndroidConfigChooser(settings);
    view.setEGLConfigChooser(configChooser);
    view.setRenderer(this);

    // Attempt to preserve the EGL Context on app pause/resume.
    // Not destroying and recreating the EGL context
    // will help with resume time by reusing the existing context to avoid
    // reloading all the OpenGL objects.
    if (Build.VERSION.SDK_INT >= 11) {
        view.setPreserveEGLContextOnPause(true);
    }

    return view;
}