Skip to content

Commit

Permalink
Merge pull request #76 from ashqal/textureview
Browse files Browse the repository at this point in the history
#75 GLTextureView worked, but not support setPreserveEGLContextOnPause
  • Loading branch information
ashqal authored Jul 13, 2016
2 parents dd4165f + 09d413f commit d0202ed
Show file tree
Hide file tree
Showing 8 changed files with 1,916 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public void onClick(MotionEvent e) {
}
})
.pinchEnabled(true)
.build(R.id.surface_view);
.build(R.id.gl_view);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);

// set content view
setContentView(R.layout.activity_md_multi);
setContentView(R.layout.activity_md_using_surface_view);

// init VR Library
mVRLibrary = createVRLibrary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void onClick(MotionEvent e) {
Toast.makeText(VideoPlayerActivity.this, "onClick!", Toast.LENGTH_SHORT).show();
}
})
.build(R.id.surface_view);
.build(R.id.gl_view);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.opengl.GLSurfaceView
android:id="@+id/surface_view"
android:id="@+id/gl_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Expand Down
56 changes: 56 additions & 0 deletions app/src/main/res/layout/activity_md_using_texture_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MD360PlayerActivity">

<FrameLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.apps.muzei.render.GLTextureView
android:id="@+id/gl_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatSpinner
android:layout_marginLeft="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:id="@+id/spinner_interactive"
android:layout_width="100dp"
android:minWidth="100dp"
android:layout_height="wrap_content"/>

<android.support.v7.widget.AppCompatSpinner
android:layout_marginLeft="8dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:id="@+id/spinner_display"
android:layout_width="100dp"
android:minWidth="100dp"
android:layout_height="wrap_content"/>

<android.support.v7.widget.AppCompatSpinner
android:layout_marginLeft="8dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:id="@+id/spinner_projection"
android:layout_width="100dp"
android:minWidth="100dp"
android:layout_height="wrap_content"/>
</LinearLayout>

<ProgressBar
android:layout_centerInParent="true"
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</RelativeLayout>
98 changes: 98 additions & 0 deletions vrlib/src/main/java/com/asha/vrlib/MDGLScreenWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.asha.vrlib;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.View;

import com.google.android.apps.muzei.render.GLTextureView;

/**
* Created by hzqiujiadi on 16/7/11.
* hzqiujiadi [email protected]
*/
public abstract class MDGLScreenWrapper {
abstract public View getView();
abstract public void setRenderer(GLSurfaceView.Renderer renderer);
abstract public void init(Context context);
abstract public void onResume();
abstract public void onPause();

public static MDGLScreenWrapper wrap(GLSurfaceView glSurfaceView){
return new MDGLSurfaceViewImpl(glSurfaceView);
}

public static MDGLScreenWrapper wrap(GLTextureView glTextureView){
return new MDGLTextureViewImpl(glTextureView);
}

private static class MDGLTextureViewImpl extends MDGLScreenWrapper {

GLTextureView glTextureView;

public MDGLTextureViewImpl(GLTextureView glTextureView) {
this.glTextureView = glTextureView;
}

@Override
public View getView() {
return glTextureView;
}

@Override
public void setRenderer(GLSurfaceView.Renderer renderer) {
glTextureView.setRenderer(renderer);
}

@Override
public void init(Context context) {
glTextureView.setEGLContextClientVersion(2);
// not supported
// glTextureView.setPreserveEGLContextOnPause(true);
}

@Override
public void onResume() {
glTextureView.onResume();
}

@Override
public void onPause() {
glTextureView.onPause();
}
}

private static class MDGLSurfaceViewImpl extends MDGLScreenWrapper {

GLSurfaceView glSurfaceView;

private MDGLSurfaceViewImpl(GLSurfaceView glSurfaceView) {
this.glSurfaceView = glSurfaceView;
}

@Override
public View getView() {
return glSurfaceView;
}

@Override
public void setRenderer(GLSurfaceView.Renderer renderer) {
glSurfaceView.setRenderer(renderer);
}

@Override
public void init(Context context) {
glSurfaceView.setEGLContextClientVersion(2);
glSurfaceView.setPreserveEGLContextOnPause(true);
}

@Override
public void onResume() {
glSurfaceView.onResume();
}

@Override
public void onPause() {
glSurfaceView.onPause();
}
}
}
67 changes: 43 additions & 24 deletions vrlib/src/main/java/com/asha/vrlib/MDVRLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.asha.vrlib.texture.MD360BitmapTexture;
import com.asha.vrlib.texture.MD360Texture;
import com.asha.vrlib.texture.MD360VideoTexture;
import com.google.android.apps.muzei.render.GLTextureView;

import java.util.List;

Expand Down Expand Up @@ -58,7 +59,7 @@ public class MDVRLibrary {
private DisplayModeManager mDisplayModeManager;
private ProjectionModeManager mProjectionModeManager;

private GLSurfaceView mGLSurfaceView;
private MDGLScreenWrapper mScreenWrapper;
private MD360Texture mTexture;
private MDTouchHelper mTouchHelper;

Expand All @@ -73,7 +74,7 @@ private MDVRLibrary(Builder builder) {
initModeManager(builder);

// init glSurfaceViews
initOpenGL(builder.activity, builder.glSurfaceView, mTexture);
initOpenGL(builder.activity, builder.screenWrapper, mTexture);

mTouchHelper = new MDTouchHelper(builder.activity);
mTouchHelper.setPinchEnabled(builder.pinchEnabled);
Expand Down Expand Up @@ -118,11 +119,11 @@ private void initModeManager(Builder builder) {
mInteractiveModeManager.prepare(builder.activity, builder.notSupportCallback);
}

private void initOpenGL(Context context, GLSurfaceView glSurfaceView, MD360Texture texture) {
private void initOpenGL(Context context, MDGLScreenWrapper screenWrapper, MD360Texture texture) {
if (GLUtil.supportsEs2(context)) {
screenWrapper.init(context);
// Request an OpenGL ES 2.0 compatible context.
glSurfaceView.setEGLContextClientVersion(2);
` glSurfaceView.setPreserveEGLContextOnPause(true);

MD360Renderer renderer = MD360Renderer.with(context)
.setTexture(texture)
.setDisplayModeManager(mDisplayModeManager)
Expand All @@ -131,10 +132,10 @@ private void initOpenGL(Context context, GLSurfaceView glSurfaceView, MD360Textu
.build();

// Set the renderer to our demo renderer, defined below.
glSurfaceView.setRenderer(renderer);
mGLSurfaceView = glSurfaceView;
screenWrapper.setRenderer(renderer);
this.mScreenWrapper = screenWrapper;
} else {
glSurfaceView.setVisibility(View.GONE);
this.mScreenWrapper.getView().setVisibility(View.GONE);
Toast.makeText(context, "OpenGLES2 not supported.", Toast.LENGTH_SHORT).show();
}
}
Expand Down Expand Up @@ -196,16 +197,20 @@ public void onTextureResize(float width, float height){

public void onResume(Context context){
mInteractiveModeManager.onResume(context);
if (mGLSurfaceView != null){
mGLSurfaceView.onResume();
if (mScreenWrapper != null){
mScreenWrapper.onResume();
}
}

public void onPause(Context context){
mInteractiveModeManager.onPause(context);

if (mGLSurfaceView != null){
mGLSurfaceView.onPause();
if (mScreenWrapper != null){
mScreenWrapper.onPause();
}

if (mTexture != null){
mTexture.destroy();
}

}
Expand Down Expand Up @@ -281,7 +286,7 @@ public static class Builder {
public MD360DirectorFactory directorFactory;
public int motionDelay = SensorManager.SENSOR_DELAY_GAME;
public SensorEventListener sensorListener;
public GLSurfaceView glSurfaceView;
public MDGLScreenWrapper screenWrapper;

private Builder(Activity activity) {
this.activity = activity;
Expand Down Expand Up @@ -411,24 +416,38 @@ public Builder directorFactory(MD360DirectorFactory directorFactory){
return this;
}

public MDVRLibrary build(GLSurfaceView glSurfaceView){
notNull(texture,"You must call video/bitmap function in before build");
if (this.directorFactory == null) directorFactory = new MD360DirectorFactory.DefaultImpl();
this.glSurfaceView = glSurfaceView;
return new MDVRLibrary(this);
}

/**
* build it!
*
* @param glSurfaceViewId will find the GLSurfaceView by glSurfaceViewId in the giving {@link #activity}
* @param glViewId will find the GLSurfaceView by glViewId in the giving {@link #activity}
* or find the GLTextureView by glViewId
* @return vr lib
*/
public MDVRLibrary build(int glSurfaceViewId){
this.glSurfaceView = (GLSurfaceView) activity.findViewById(glSurfaceViewId);
return build(this.glSurfaceView);
public MDVRLibrary build(int glViewId){
View view = activity.findViewById(glViewId);
if (view instanceof GLSurfaceView){
return build((GLSurfaceView) view);
} else if(view instanceof GLTextureView){
return build((GLTextureView) view);
} else {
throw new RuntimeException("Please ensure the glViewId is instance of GLSurfaceView or GLTextureView");
}
}

public MDVRLibrary build(GLSurfaceView glSurfaceView){
return build(MDGLScreenWrapper.wrap(glSurfaceView));
}

public MDVRLibrary build(GLTextureView glTextureView){
return build(MDGLScreenWrapper.wrap(glTextureView));
}

private MDVRLibrary build(MDGLScreenWrapper screenWrapper){
notNull(texture,"You must call video/bitmap function in before build");
if (this.directorFactory == null) directorFactory = new MD360DirectorFactory.DefaultImpl();
this.screenWrapper = screenWrapper;
return new MDVRLibrary(this);
}
}

interface ContentType{
Expand Down
Loading

0 comments on commit d0202ed

Please sign in to comment.