/*--------- onDrawFrame ---------------------------------------------------------------*/ public void onDrawFrame(GL10 gl) { Log.d(TAG + "class MyRenderer", "onDrawFrame"); boolean result = MidasNative.render(); if (result) { parentView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); } else { parentView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); } while (mPreRenderRunnables.size() > 0) { mPreRenderRunnables.remove(0).run(); } }
@Override public void onSetScript() { mSurfaceView = new GLSurfaceView(mActivity); mSurfaceView.setPreserveEGLContextOnPause(true); mSurfaceView.setEGLContextClientVersion(3); mSurfaceView.setEGLContextFactory(mContextFactory); mSurfaceView.setEGLConfigChooser(mConfigChooser); mSurfaceView.setEGLWindowSurfaceFactory(mWindowSurfaceFactory); mSurfaceView.setRenderer(mRenderer); mSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mActivity.setContentView(mSurfaceView); final DisplayMetrics metrics = new DisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); final VrAppSettings appSettings = mActivity.getAppSettings(); final int screenWidthPixels = Math.max(metrics.widthPixels, metrics.heightPixels); final int screenHeightPixels = Math.min(metrics.widthPixels, metrics.heightPixels); final int frameBufferWidth = appSettings.getFramebufferPixelsWide(); final int frameBufferHeight = appSettings.getFramebufferPixelsHigh(); final SurfaceHolder holder = mSurfaceView.getHolder(); holder.setFormat(PixelFormat.TRANSLUCENT); if ((-1 != frameBufferHeight) && (-1 != frameBufferWidth)) { if ((screenWidthPixels != frameBufferWidth) && (screenHeightPixels != frameBufferHeight)) { Log.v(TAG, "--- window configuration ---"); Log.v(TAG, "--- width: %d", frameBufferWidth); Log.v(TAG, "--- height: %d", frameBufferHeight); // a different resolution of the native window requested holder.setFixedSize((int) frameBufferWidth, (int) frameBufferHeight); Log.v(TAG, "----------------------------"); } } }
/** * Sets the up camera to be connected to GPUImage to get a filtered preview. * * @param camera the camera * @param degrees by how many degrees the image should be rotated * @param flipHorizontal if the image should be flipped horizontally * @param flipVertical if the image should be flipped vertically */ public void setUpCamera( final Camera camera, final int degrees, final boolean flipHorizontal, final boolean flipVertical) { mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { setUpCameraGingerbread(camera); } else { camera.setPreviewCallback(mRenderer); camera.startPreview(); } Rotation rotation = Rotation.NORMAL; switch (degrees) { case 90: rotation = Rotation.ROTATION_90; break; case 180: rotation = Rotation.ROTATION_180; break; case 270: rotation = Rotation.ROTATION_270; break; } mRenderer.setRotationCamera(rotation, flipHorizontal, flipVertical); }
/** * Sets the GLSurfaceView which will display the preview. * * @param view the GLSurfaceView */ public void setGLSurfaceView(final GLSurfaceView view) { mGlSurfaceView = view; mGlSurfaceView.setEGLContextClientVersion(2); mGlSurfaceView.setRenderer(mRenderer); mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mGlSurfaceView.requestRender(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camera_capture); File outputFile = new File(Environment.getExternalStorageDirectory(), "camera-test.mp4"); TextView fileText = (TextView) findViewById(R.id.cameraOutputFile_text); fileText.setText(outputFile.toString()); Spinner spinner = (Spinner) findViewById(R.id.cameraFilter_spinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.cameraFilterNames, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner. spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); // Define a handler that receives camera-control messages from other threads. All calls // to Camera must be made on the same thread. Note we create this before the renderer // thread, so we know the fully-constructed object will be visible. mCameraHandler = new CameraHandler(this); mRecordingEnabled = sVideoEncoder.isRecording(); // Configure the GLSurfaceView. This will start the Renderer thread, with an // appropriate EGL context. mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView); mGLView.setEGLContextClientVersion(2); // select GLES 2.0 mRenderer = new CameraSurfaceRenderer(mCameraHandler, sVideoEncoder, outputFile); mGLView.setRenderer(mRenderer); mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); Log.d(TAG, "onCreate complete: " + this); }
@Override protected void onResume() { super.onResume(); if (mRajRenderer == null) return; mSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mSurfaceView.onResume(); mRajRenderer.onVisibilityChanged(true); }
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>(); }
/** * Sets the GLSurfaceView which will display the preview. * * @param view the GLSurfaceView */ public void setGLSurfaceView(final GLSurfaceView view) { mGlSurfaceView = view; // 设置OpenGl版本号为2 mGlSurfaceView.setEGLContextClientVersion(2); // 设置颜色缓存为RGBA,位数都为8,深度缓存位数为16,蒙版缓存位数为0 mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); mGlSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888); mGlSurfaceView.setRenderer(mRenderer); // 脏模式,需要重绘时手动调用requestRender() mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mGlSurfaceView.requestRender(); }
@Override public void setContinuousRendering(boolean isContinuous) { synchronized (continue_lock) { if (view != null) { this.isContinuous = isContinuous; int renderMode = isContinuous ? GLSurfaceView.RENDERMODE_CONTINUOUSLY : GLSurfaceView.RENDERMODE_WHEN_DIRTY; if (view instanceof GLSurfaceViewCupcake) ((GLSurfaceViewCupcake) view).setRenderMode(renderMode); if (view instanceof GLSurfaceView) ((GLSurfaceView) view).setRenderMode(renderMode); } } }
public void resetSurfaceView() { removeViewInLayout(surfaceView); surfaceView = null; surfaceView = new GLSurfaceView(getContext()); // surfaceView.setBackgroundColor(Color.WHITE); surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); surfaceView.setZOrderOnTop(true); surfaceView.setRenderer(renderer); surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); addViewInLayout( surfaceView, -1, new AbsListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT), false); }
// -------------------------------------------------------------------------------------------------------------------- // Internals private void setupSurfaceView(Context context) { surfaceView = new GLSurfaceView(getContext()); cards = new FlipCards(this, flipOrientation == VERTICAL); renderer = new FlipRenderer(this, cards); surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); surfaceView.setZOrderOnTop(true); surfaceView.setRenderer(renderer); surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); addViewInLayout( surfaceView, -1, new AbsListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT), false); }
@Override public void setContinuousRendering(boolean isContinuous) { if (view != null) { this.isContinuous = isContinuous; int renderMode = isContinuous ? GLSurfaceView.RENDERMODE_CONTINUOUSLY : GLSurfaceView.RENDERMODE_WHEN_DIRTY; // jw: changed // view.setRenderMode(renderMode); if (view instanceof GLSurfaceViewCupcake) ((GLSurfaceViewCupcake) view).setRenderMode(renderMode); else if (view instanceof GLSurfaceViewAPI18) ((GLSurfaceViewAPI18) view).setRenderMode(renderMode); else if (view instanceof GLSurfaceView) ((GLSurfaceView) view).setRenderMode(renderMode); else throw new RuntimeException("unimplemented"); mean.clear(); } }
public void updateGLViews(SessionUIPresenter presenter) { // _on_pause = false; for (int i = 0; i < _renders.size(); i++) { RenderViewData d = _renders.valueAt(i); LogSdk.d(TAG, "updating GLview " + d._view_id + " for user " + d._user); GLSurfaceView glview = (GLSurfaceView) presenter.findViewById(d._view_id); if (glview == null) { LogSdk.e(TAG, "NULL GL view!!! " + d._view_id); continue; } try { glview.setEGLContextClientVersion(2); d._render = new VideoRenderer(glview); glview.setRenderer(d._render); glview.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); // .RENDERMODE_CONTINUOUSLY); } catch (IllegalStateException e) { } } }
/** * Sets the up camera to be connected to GPUImage to get a filtered preview. * * @param camera the camera * @param degrees by how many degrees the image should be rotated * @param flipHorizontal if the image should be flipped horizontally * @param flipVertical if the image should be flipped vertically */ public void setUpCamera( final Camera camera, boolean userFront, final boolean flipHorizontal, final boolean flipVertical) { try { mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); Rotation rotation = Rotation.ROTATION_90; if (userFront) { rotation = Rotation.ROTATION_270; } else { rotation = Rotation.ROTATION_90; } mRenderer.setRotationCamera(rotation, flipHorizontal, flipVertical); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { setUpCameraGingerbread(camera); } else { camera.setPreviewCallback(mRenderer); camera.startPreview(); } } catch (Exception e) { e.printStackTrace(); } }
@Override protected void onResume() { super.onResume(); int screenw; int width; setContentView(R.layout.main); setTitle(getResources().getString(R.string.app_name)); setTitleColor(0xFFFF5555); init(); screenw = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay() .getWidth(); mTextDisplay[0] = (TextView) findViewById(R.id.text1); mTextDisplay[1] = (TextView) findViewById(R.id.text2); mRootViewGroup = (ViewGroup) mTextDisplay[0].getParent(); width = (screenw * 1 / 2); for (int i = 0; i < mTextDisplay.length; i++) { mTextDisplay[i].setTextColor(mTextColor); mTextDisplay[i].setWidth(width); mTextDisplay[i].setText(""); } mTextDisplay[0].setText(""); updatePreferences(); mToggleButtonStartStop = (ToggleButton) findViewById(R.id.startStopSwitch); mToggleButtonStartStop.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { if (mToggleButtonStartStop.isChecked()) { startPreview(); } else { stopPreview(); } } }); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); int cameraIndex = Integer.decode( prefs.getString(getResources().getString(R.string.shared_prefs_camera_list), "0")); mCamera = Camera.open(cameraIndex); mCamSurface = new CameraSurface(this, mCamera); mRootViewGroup.addView(mCamSurface); mRenderer = new CameraSampleRenderer(this); mGLSurface = mRenderer.getGLSurfaceView(); mGLSurface.setZOrderMediaOverlay(true); mGLSurface.setVisibility(View.VISIBLE); mGLSurface.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mRootViewGroup.addView(mGLSurface); bringControlsToFront(); startPreview(); System.gc(); }
public NavitGraphics2( Activity activity, NavitGraphics2 parent, int x, int y, int w, int h, int alpha, int wraparound, int use_camera) { if (parent == null) { this.activity = activity; flb = new FloatBuffer[10000]; view = new GLSurfaceView(activity) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawBitmap(draw_bitmap, pos_x, pos_y, null); if (overlay_disabled == 0) { Object overlays_array[]; overlays_array = overlays.toArray(); for (Object overlay : overlays_array) { NavitGraphics2 overlay_graphics = (NavitGraphics2) overlay; if (overlay_graphics.overlay_disabled == 0) { int x = overlay_graphics.pos_x; int y = overlay_graphics.pos_y; if (overlay_graphics.pos_wraparound != 0 && x < 0) x += bitmap_w; if (overlay_graphics.pos_wraparound != 0 && y < 0) y += bitmap_h; canvas.drawBitmap(overlay_graphics.draw_bitmap, x, y, null); } } } } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); draw_canvas = new Canvas(draw_bitmap); bitmap_w = w; bitmap_h = h; SizeChangedCallback(SizeChangedCallbackID, w, h); } @Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); int action = event.getAction(); int x = (int) event.getX(); int y = (int) event.getY(); if (action == MotionEvent.ACTION_DOWN) { // Log.e("NavitGraphics", "onTouch down"); ButtonCallback(ButtonCallbackID, 1, 1, x, y); } if (action == MotionEvent.ACTION_UP) { // Log.e("NavitGraphics", "onTouch up"); ButtonCallback(ButtonCallbackID, 0, 1, x, y); // if (++count == 3) // Debug.stopMethodTracing(); } if (action == MotionEvent.ACTION_MOVE) { // Log.e("NavitGraphics", "onTouch move"); MotionCallback(MotionCallbackID, x, y); } return true; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { int i; String s = null; boolean handled = true; i = event.getUnicodeChar(); Log.e("NavitGraphics", "onKeyDown " + keyCode + " " + i); // Log.e("NavitGraphics","Unicode "+event.getUnicodeChar()); if (i == 0) { if (keyCode == android.view.KeyEvent.KEYCODE_DEL) { s = java.lang.String.valueOf((char) 8); } else if (keyCode == android.view.KeyEvent.KEYCODE_MENU) { s = java.lang.String.valueOf((char) 1); } else if (keyCode == android.view.KeyEvent.KEYCODE_SEARCH) { s = java.lang.String.valueOf((char) 19); } else if (keyCode == android.view.KeyEvent.KEYCODE_BACK) { s = java.lang.String.valueOf((char) 27); } else if (keyCode == android.view.KeyEvent.KEYCODE_CALL) { s = java.lang.String.valueOf((char) 3); } else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_UP) { s = java.lang.String.valueOf((char) 21); handled = false; } else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_DOWN) { s = java.lang.String.valueOf((char) 4); handled = false; } else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_CENTER) { s = java.lang.String.valueOf((char) 13); } else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_DOWN) { s = java.lang.String.valueOf((char) 16); } else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_LEFT) { s = java.lang.String.valueOf((char) 2); } else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_RIGHT) { s = java.lang.String.valueOf((char) 6); } else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_UP) { s = java.lang.String.valueOf((char) 14); } } else if (i == 10) { s = java.lang.String.valueOf((char) 13); } else { s = java.lang.String.valueOf((char) i); } if (s != null) { KeypressCallback(KeypressCallbackID, s); } return handled; } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { Log.e("NavitGraphics", "onKeyUp " + keyCode); return true; } @Override public boolean onTrackballEvent(MotionEvent event) { Log.e( "NavitGraphics", "onTrackball " + event.getAction() + " " + event.getX() + " " + event.getY()); String s = null; if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) { s = java.lang.String.valueOf((char) 13); } if (event.getAction() == android.view.MotionEvent.ACTION_MOVE) { trackball_x += event.getX(); trackball_y += event.getY(); Log.e("NavitGraphics", "trackball " + trackball_x + " " + trackball_y); if (trackball_x <= -1) { s = java.lang.String.valueOf((char) 2); trackball_x += 1; } if (trackball_x >= 1) { s = java.lang.String.valueOf((char) 6); trackball_x -= 1; } if (trackball_y <= -1) { s = java.lang.String.valueOf((char) 16); trackball_y += 1; } if (trackball_y >= 1) { s = java.lang.String.valueOf((char) 14); trackball_y -= 1; } } if (s != null) { KeypressCallback(KeypressCallbackID, s); } return true; } @Override protected void onFocusChanged( boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); Log.e("NavitGraphics", "FocusChange " + gainFocus); } }; view.setFocusable(true); view.setFocusableInTouchMode(true); renderer = new ClearRenderer(); renderer.flb = new FloatBuffer[1000]; renderer.flb_len = 0; view.setRenderer(renderer); view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); relativelayout = new RelativeLayout(activity); if (use_camera != 0) { SetCamera(use_camera); } relativelayout.addView(view); activity.setContentView(relativelayout); view.requestFocus(); } else { draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); bitmap_w = w; bitmap_h = h; pos_x = x; pos_y = y; pos_wraparound = wraparound; draw_canvas = new Canvas(draw_bitmap); parent.overlays.add(this); } parent_graphics = parent; }