Beispiel #1
0
 @Override
 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
   Surface surface = holder.getSurface();
   if (surface != null && surface.isValid()) {
     evaluatePredict(START_PRD_SURFACE_VALID);
   }
 }
Beispiel #2
0
  private void evaluatePredict(int mask) {
    Leg.i(TAG, "evaluatePredict(" + mask + ")");
    calculatePredict(mask);

    Leg.i(TAG, "calculated predict: " + mPredict);
    if ((mPredict & START_PRD_SB_SV) == START_PRD_SB_SV) {
      Leg.i(TAG, "prediction: foreground surface");
      Surface surface = mSurfaceHolder.getSurface();
      if (surface != null && surface.isValid()) {
        mPlaybackService.setForegroundSurfaceHolder(mSurfaceHolder);
      } else {
        mPlaybackService.setForegroundSurfaceHolder(null);
      }
    }

    if ((mPredict & START_PRD_SI_SB_SV) == START_PRD_SI_SB_SV) {
      Leg.i(TAG, "prediction: send start playback message");
      mHandler.removeMessages(START_PLAY_BACK);
      mHandler.removeMessages(STOP_PLAY_BACK);
      if (!mPlaybackService.isPlaying()) {
        mHandler.obtainMessage(STOP_PLAY_BACK).sendToTarget();
        mHandler.obtainMessage(START_PLAY_BACK).sendToTarget();
      }
    }
  }
  /**
   * Called from native code to share a surface texture with another child process. Through using
   * the callback object the browser is used as a proxy to route the call to the correct process.
   *
   * @param pid Process handle of the child process to share the SurfaceTexture with.
   * @param surfaceObject The Surface or SurfaceTexture to share with the other child process.
   * @param primaryID Used to route the call to the correct client instance.
   * @param secondaryID Used to route the call to the correct client instance.
   */
  @SuppressWarnings("unused")
  @CalledByNative
  private void establishSurfaceTexturePeer(
      int pid, Object surfaceObject, int primaryID, int secondaryID) {
    if (mCallback == null) {
      Log.e(TAG, "No callback interface has been provided.");
      return;
    }

    Surface surface = null;
    boolean needRelease = false;
    if (surfaceObject instanceof Surface) {
      surface = (Surface) surfaceObject;
    } else if (surfaceObject instanceof SurfaceTexture) {
      surface = new Surface((SurfaceTexture) surfaceObject);
      needRelease = true;
    } else {
      Log.e(TAG, "Not a valid surfaceObject: %s", surfaceObject);
      return;
    }
    try {
      mCallback.establishSurfacePeer(pid, surface, primaryID, secondaryID);
    } catch (RemoteException e) {
      Log.e(TAG, "Unable to call establishSurfaceTexturePeer: %s", e);
      return;
    } finally {
      if (needRelease) {
        surface.release();
      }
    }
  }
  private static void unregisterSurfaceTextureSurface(int surfaceTextureId, int clientId) {
    Pair<Integer, Integer> key = new Pair<Integer, Integer>(surfaceTextureId, clientId);
    Surface surface = sSurfaceTextureSurfaceMap.remove(key);
    if (surface == null) return;

    assert surface.isValid();
    surface.release();
  }
 private void maybeStartPlayback() {
   Surface surface = mSurfaceView.getHolder().getSurface();
   if (mVideoRenderer == null || surface == null || !surface.isValid()) {
     return;
   }
   mPlayer.sendMessage(mVideoRenderer, MSG_SET_SURFACE, surface);
   if (mAutoPlay) {
     mPlayer.setPlayWhenReady(true);
     mAutoPlay = false;
   }
 }
  @CalledByNative
  private static SurfaceWrapper getSurfaceTextureSurface(int surfaceTextureId, int clientId) {
    Pair<Integer, Integer> key = new Pair<Integer, Integer>(surfaceTextureId, clientId);

    Surface surface = sSurfaceTextureSurfaceMap.get(key);
    if (surface == null) {
      Log.e(TAG, "Invalid Id for surface texture.");
      return null;
    }
    assert surface.isValid();
    return new SurfaceWrapper(surface);
  }
  private boolean captureScreenshotTextureAndSetViewport() {
    if (!attachEglContext()) {
      return false;
    }
    try {
      if (!mTexNamesGenerated) {
        GLES10.glGenTextures(1, mTexNames, 0);
        if (checkGlErrors("glGenTextures")) {
          return false;
        }
        mTexNamesGenerated = true;
      }

      final SurfaceTexture st = new SurfaceTexture(mTexNames[0]);
      final Surface s = new Surface(st);
      try {
        SurfaceControl.screenshot(
            SurfaceControl.getBuiltInDisplay(SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s);
      } finally {
        s.release();
      }

      st.updateTexImage();
      st.getTransformMatrix(mTexMatrix);

      // Set up texture coordinates for a quad.
      // We might need to change this if the texture ends up being
      // a different size from the display for some reason.
      mTexCoordBuffer.put(0, 0f);
      mTexCoordBuffer.put(1, 0f);
      mTexCoordBuffer.put(2, 0f);
      mTexCoordBuffer.put(3, 1f);
      mTexCoordBuffer.put(4, 1f);
      mTexCoordBuffer.put(5, 1f);
      mTexCoordBuffer.put(6, 1f);
      mTexCoordBuffer.put(7, 0f);

      // Set up our viewport.
      GLES10.glViewport(0, 0, mDisplayWidth, mDisplayHeight);
      GLES10.glMatrixMode(GLES10.GL_PROJECTION);
      GLES10.glLoadIdentity();
      GLES10.glOrthof(0, mDisplayWidth, 0, mDisplayHeight, 0, 1);
      GLES10.glMatrixMode(GLES10.GL_MODELVIEW);
      GLES10.glLoadIdentity();
      GLES10.glMatrixMode(GLES10.GL_TEXTURE);
      GLES10.glLoadIdentity();
      GLES10.glLoadMatrixf(mTexMatrix, 0);
    } finally {
      detachEglContext();
    }
    return true;
  }
 private void maybeStartPlayback() {
   Log.d(TAG, "maybeStartPlayback");
   Surface surface = surfaceView.getHolder().getSurface();
   if (videoRenderer == null || surface == null || !surface.isValid()) {
     // We're not ready yet.
     return;
   }
   player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
   if (autoPlay) {
     player.setPlayWhenReady(true);
     autoPlay = false;
   }
 }
Beispiel #9
0
  private void openVideo() {
    if (mUri == null || mSurface == null) {
      return;
    }

    if (mEnableMusicPause) {
      sendMusicPauseRequest();
    }

    release(false);
    try {
      mPlayer = new MediaPlayer();
      mPlayer.setOnPreparedListener(mPreparedListener);
      mPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mPlayer.setOnCompletionListener(mCompletionListener);
      mPlayer.setOnErrorListener(mErrorListener);
      mPlayer.setDataSource(mCtx, mUri);
      mPlayer.setSurface(mSurface);
      mSurface.release();
      mSurface = null;
      mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mPlayer.setParameter(CLEAR_MOTION_KEY, CLEAR_MOTION_DISABLE);
      mPlayer.prepareAsync();
      setCurrentState(STATE_PREPARING);
    } catch (IOException ex) {
      Log.e(TAG, "IOException : " + ex);
      setAllState(STATE_ERROR);
      mErrorListener.onError(mPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
    } catch (IllegalArgumentException ex) {
      Log.e(TAG, "IllegalArgumentException : " + ex);
      setAllState(STATE_ERROR);
      mErrorListener.onError(mPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
    }
  }
  /** onClick handler for "play"/"stop" button. */
  public void clickPlayStop(@SuppressWarnings("unused") View unused) {
    if (mShowStopLabel) {
      Log.d(TAG, "stopping movie");
      stopPlayback();
      // Don't update the controls here -- let the task thread do it after the movie has
      // actually stopped.
      // mShowStopLabel = false;
      // updateControls();
    } else {
      if (mPlayTask != null) {
        Log.w(TAG, "movie already playing");
        return;
      }

      Log.d(TAG, "starting movie");
      SpeedControlCallback callback = new SpeedControlCallback();
      SurfaceHolder holder = mSurfaceView.getHolder();
      Surface surface = holder.getSurface();

      // Don't leave the last frame of the previous video hanging on the screen.
      // Looks weird if the aspect ratio changes.
      clearSurface(surface);

      MoviePlayer player = null;
      try {
        player =
            new MoviePlayer(
                new File(getFilesDir(), mMovieFiles[mSelectedMovie]), surface, callback);
      } catch (IOException ioe) {
        Log.e(TAG, "Unable to play movie", ioe);
        surface.release();
        return;
      }

      AspectFrameLayout layout = (AspectFrameLayout) findViewById(R.id.playMovie_afl);
      int width = player.getVideoWidth();
      int height = player.getVideoHeight();
      layout.setAspectRatio((double) width / height);
      // holder.setFixedSize(width, height);

      mPlayTask = new MoviePlayer.PlayTask(player, this);

      mShowStopLabel = true;
      updateControls();
      mPlayTask.execute();
    }
  }
  @SuppressWarnings("unused")
  @CalledByNative
  private void createSurfaceTextureSurface(
      int surfaceTextureId, int clientId, SurfaceTexture surfaceTexture) {
    if (mCallback == null) {
      Log.e(TAG, "No callback interface has been provided.");
      return;
    }

    Surface surface = new Surface(surfaceTexture);
    try {
      mCallback.registerSurfaceTextureSurface(surfaceTextureId, clientId, surface);
    } catch (RemoteException e) {
      Log.e(TAG, "Unable to call registerSurfaceTextureSurface: %s", e);
    }
    surface.release();
  }
  private void surfaceRender() {
    synchronized (this) {
      if (mLocalSurface == null
          || !mLocalSurface.isValid()
          || mBitmap == null
          || mByteBuffer == null) return;

      try {
        Canvas c = mLocalSurface.lockCanvas(null);
        mBitmap.copyPixelsFromBuffer(mByteBuffer);
        c.drawBitmap(mBitmap, 0, 0, null);
        mLocalSurface.unlockCanvasAndPost(c);
      } catch (Exception e) {
        Log.e("surfaceRender", e);
      }
    }
  }
  /** Takes a screenshot of the current display and shows an animation. */
  void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) {
    // We need to orient the screenshot correctly (and the Surface api seems to take screenshots
    // only in the natural orientation of the device :!)
    mDisplay.getRealMetrics(mDisplayMetrics);
    float[] dims = {mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels};
    // float degrees = getDegreesForRotation(mDisplay.getRotation());
    int value = mDisplay.getRotation();
    String hwRotation = SystemProperties.get("ro.sf.hwrotation", "0");
    if (hwRotation.equals("270") || hwRotation.equals("90")) {
      value = (value + 3) % 4;
    }
    float degrees = getDegreesForRotation(value);
    boolean requiresRotation = (degrees > 0);
    if (requiresRotation) {
      // Get the dimensions of the device in its native orientation
      mDisplayMatrix.reset();
      mDisplayMatrix.preRotate(-degrees);
      mDisplayMatrix.mapPoints(dims);
      dims[0] = Math.abs(dims[0]);
      dims[1] = Math.abs(dims[1]);
    }

    // Take the screenshot
    mScreenBitmap = Surface.screenshot((int) dims[0], (int) dims[1]);
    if (mScreenBitmap == null) {
      notifyScreenshotError(mContext, mNotificationManager);
      finisher.run();
      return;
    }

    if (requiresRotation) {
      // Rotate the screenshot to the current orientation
      Bitmap ss =
          Bitmap.createBitmap(
              mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels, Bitmap.Config.ARGB_8888);
      Canvas c = new Canvas(ss);
      c.translate(ss.getWidth() / 2, ss.getHeight() / 2);
      c.rotate(degrees);
      c.translate(-dims[0] / 2, -dims[1] / 2);
      c.drawBitmap(mScreenBitmap, 0, 0, null);
      c.setBitmap(null);
      mScreenBitmap = ss;
    }

    // Optimizations
    mScreenBitmap.setHasAlpha(false);
    mScreenBitmap.prepareToDraw();

    // Start the post-screenshot animation
    startAnimation(
        finisher,
        mDisplayMetrics.widthPixels,
        mDisplayMetrics.heightPixels,
        statusBarVisible,
        navBarVisible);
  }
      /** NOTE: This has to be called within a surface transaction. */
      public void drawIfNeeded() {
        synchronized (mWindowManagerService.mWindowMap) {
          if (!mInvalidated) {
            return;
          }
          mInvalidated = false;
          Canvas canvas = null;
          try {
            // Empty dirty rectangle means unspecified.
            if (mDirtyRect.isEmpty()) {
              mBounds.getBounds(mDirtyRect);
            }
            mDirtyRect.inset(-mHalfBorderWidth, -mHalfBorderWidth);
            canvas = mSurface.lockCanvas(mDirtyRect);
            if (DEBUG_VIEWPORT_WINDOW) {
              Slog.i(LOG_TAG, "Dirty rect: " + mDirtyRect);
            }
          } catch (IllegalArgumentException iae) {
            /* ignore */
          } catch (Surface.OutOfResourcesException oore) {
            /* ignore */
          }
          if (canvas == null) {
            return;
          }
          if (DEBUG_VIEWPORT_WINDOW) {
            Slog.i(LOG_TAG, "Bounds: " + mBounds);
          }
          canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);
          mPaint.setAlpha(mAlpha);
          Path path = mBounds.getBoundaryPath();
          canvas.drawPath(path, mPaint);

          mSurface.unlockCanvasAndPost(canvas);

          if (mAlpha > 0) {
            mSurfaceControl.show();
          } else {
            mSurfaceControl.hide();
          }
        }
      }
  public boolean stepAnimation(long now) {
    if (mEnterAnimation == null && mExitAnimation == null) {
      return false;
    }

    if (!mStarted) {
      if (mEnterAnimation != null) {
        mEnterAnimation.setStartTime(now);
      }
      if (mExitAnimation != null) {
        mExitAnimation.setStartTime(now);
      }
      mStarted = true;
    }

    mExitTransformation.clear();
    boolean moreExit = false;
    if (mExitAnimation != null) {
      moreExit = mExitAnimation.getTransformation(now, mExitTransformation);
      if (DEBUG) Slog.v(TAG, "Stepped exit: " + mExitTransformation);
      if (!moreExit) {
        if (DEBUG) Slog.v(TAG, "Exit animation done!");
        mExitAnimation.cancel();
        mExitAnimation = null;
        mExitTransformation.clear();
        if (mSurface != null) {
          mSurface.hide();
        }
      }
    }

    mEnterTransformation.clear();
    boolean moreEnter = false;
    if (mEnterAnimation != null) {
      moreEnter = mEnterAnimation.getTransformation(now, mEnterTransformation);
      if (!moreEnter) {
        mEnterAnimation.cancel();
        mEnterAnimation = null;
        mEnterTransformation.clear();
        if (mBlackFrame != null) {
          mBlackFrame.hide();
        }
      } else {
        if (mBlackFrame != null) {
          mBlackFrame.setMatrix(mEnterTransformation.getMatrix());
        }
      }
    }

    mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
    setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha());

    return moreEnter || moreExit;
  }
 @Override // async task thread
 protected Void doInBackground(Void... params) {
   try {
     mPlayer.setLoopMode(mLoop);
     mPlayer.play(mCallback);
   } catch (IOException ioe) {
     Log.e(TAG, "movie playback failed", ioe);
   } finally {
     mSurface.release();
   }
   return null;
 }
  /** onClick handler for "play"/"stop" button. */
  public void clickPlayStop(@SuppressWarnings("unused") View unused) {
    if (mShowStopLabel) {
      Log.d(TAG, "stopping movie");
      stopPlayback();
      // Don't update the controls here -- let the async task do it after the movie has
      // actually stopped.
      // mShowStopLabel = false;
      // updateControls();
    } else {
      if (mPlayTask != null) {
        Log.w(TAG, "movie already playing");
        return;
      }
      Log.d(TAG, "starting movie");
      SpeedControlCallback callback = new SpeedControlCallback();
      if (((CheckBox) findViewById(R.id.locked60fps_checkbox)).isChecked()) {
        callback.setFixedPlaybackRate(60);
      }
      SurfaceTexture st = mTextureView.getSurfaceTexture();
      Surface surface = new Surface(st);
      MoviePlayer player = null;
      try {
        player = new MoviePlayer(new File(getFilesDir(), mMovieFiles[mSelectedMovie]), surface);
      } catch (IOException ioe) {
        Log.e(TAG, "Unable to play movie", ioe);
        surface.release();
        return;
      }
      adjustAspectRatio(player.getVideoWidth(), player.getVideoHeight());
      mPlayTask = new PlayMovieTask(player, surface, callback);
      if (((CheckBox) findViewById(R.id.loopPlayback_checkbox)).isChecked()) {
        mPlayTask.setLoopMode(true);
      }

      mShowStopLabel = true;
      updateControls();
      mPlayTask.execute();
    }
  }
 private void setSnapshotTransformInTransaction(Matrix matrix, float alpha) {
   if (mSurface != null) {
     matrix.getValues(mTmpFloats);
     mSurface.setPosition(mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
     mSurface.setMatrix(
         mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
         mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
     mSurface.setAlpha(alpha);
     if (DEBUG_TRANSFORMS) {
       float[] srcPnts = new float[] {0, 0, mWidth, mHeight};
       float[] dstPnts = new float[4];
       matrix.mapPoints(dstPnts, srcPnts);
       /** M:Change the tag to WindowManager */
       Slog.i(
           WindowManagerService.TAG,
           "Original  : ("
               + srcPnts[0]
               + ","
               + srcPnts[1]
               + ")-("
               + srcPnts[2]
               + ","
               + srcPnts[3]
               + ")");
       Slog.i(
           WindowManagerService.TAG,
           "Transformed: ("
               + dstPnts[0]
               + ","
               + dstPnts[1]
               + ")-("
               + dstPnts[2]
               + ","
               + dstPnts[3]
               + ")");
     }
   }
 }
Beispiel #19
0
  private void pushSurfaceAndVideoTrack(boolean blockForSurfacePush) {
    if (rendererBuildingState != RenderBuildingState.BUILT) {
      return;
    }

    if (blockForSurfacePush) {
      player.blockingSendMessage(
          videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    } else {
      player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    }

    pushTrackSelection(RENDER_VIDEO_INDEX, surface != null && surface.isValid());
  }
 private void releaseEncoder() {
   // Release encoder
   if (VERBOSE) {
     Log.v(TAG, "releasing encoder");
   }
   if (mEncoder != null) {
     mEncoder.stop();
     mEncoder.release();
     if (mRecordingSurface != null) {
       mRecordingSurface.release();
     }
     mEncoder = null;
   }
 }
 void setSnapshotTransform(Matrix matrix, float alpha) {
   if (mSurface != null) {
     matrix.getValues(mTmpFloats);
     mSurface.setPosition(mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
     mSurface.setMatrix(
         mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
         mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
     mSurface.setAlpha(alpha);
     if (DEBUG) {
       float[] srcPnts = new float[] {0, 0, mWidth, mHeight};
       float[] dstPnts = new float[4];
       matrix.mapPoints(dstPnts, srcPnts);
       Slog.i(
           TAG,
           "Original  : ("
               + srcPnts[0]
               + ","
               + srcPnts[1]
               + ")-("
               + srcPnts[2]
               + ","
               + srcPnts[3]
               + ")");
       Slog.i(
           TAG,
           "Transformed: ("
               + dstPnts[0]
               + ","
               + dstPnts[1]
               + ")-("
               + dstPnts[2]
               + ","
               + dstPnts[3]
               + ")");
     }
   }
 }
 public void onRotationChangedLocked(DisplayContent displayContent, int rotation) {
   if (DEBUG_ROTATION) {
     Slog.i(
         LOG_TAG,
         "Rotaton: "
             + Surface.rotationToString(rotation)
             + " displayId: "
             + displayContent.getDisplayId());
   }
   /// M:[ALPS01397351]Fix system server JE @{
   // mMagnifedViewport.onRotationChangedLocked();
   mHandler.sendEmptyMessage(MyHandler.MESSAGE_ON_ROTATION_CHANGED);
   /// @}
   mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_ROTATION_CHANGED);
 }
Beispiel #23
0
 private void destroySurface() {
   if (mSurfaceControl != null) {
     mSurfaceLayout.dispose();
     mSurfaceLayout = null;
     SurfaceControl.openTransaction();
     try {
       mSurfaceControl.destroy();
       mSurface.release();
     } finally {
       SurfaceControl.closeTransaction();
     }
     mSurfaceControl = null;
     mSurfaceVisible = false;
     mSurfaceAlpha = 0f;
   }
 }
 public void kill() {
   if (mSurface != null) {
     if (WindowManagerService.SHOW_TRANSACTIONS || WindowManagerService.SHOW_SURFACE_ALLOC)
       Slog.i(WindowManagerService.TAG, "  FREEZE " + mSurface + ": DESTROY");
     mSurface.destroy();
     mSurface = null;
   }
   if (mBlackFrame != null) {
     mBlackFrame.kill();
   }
   if (mExitAnimation != null) {
     mExitAnimation.cancel();
     mExitAnimation = null;
   }
   if (mEnterAnimation != null) {
     mEnterAnimation.cancel();
     mEnterAnimation = null;
   }
 }
      public ViewportWindow(Context context) {
        SurfaceControl surfaceControl = null;
        try {
          mWindowManager.getDefaultDisplay().getRealSize(mTempPoint);
          surfaceControl =
              new SurfaceControl(
                  mWindowManagerService.mFxSession,
                  SURFACE_TITLE,
                  mTempPoint.x,
                  mTempPoint.y,
                  PixelFormat.TRANSLUCENT,
                  SurfaceControl.HIDDEN);
        } catch (OutOfResourcesException oore) {
          /* ignore */
        }
        mSurfaceControl = surfaceControl;
        mSurfaceControl.setLayerStack(mWindowManager.getDefaultDisplay().getLayerStack());
        mSurfaceControl.setLayer(
            mWindowManagerService.mPolicy.windowTypeToLayerLw(
                    WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY)
                * WindowManagerService.TYPE_LAYER_MULTIPLIER);
        mSurfaceControl.setPosition(0, 0);
        mSurface.copyFrom(mSurfaceControl);

        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorActivatedHighlight, typedValue, true);
        final int borderColor = context.getResources().getColor(typedValue.resourceId);

        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(mBorderWidth);
        mPaint.setColor(borderColor);

        Interpolator interpolator = new DecelerateInterpolator(2.5f);
        final long longAnimationDuration =
            context.getResources().getInteger(com.android.internal.R.integer.config_longAnimTime);

        mShowHideFrameAnimator =
            ObjectAnimator.ofInt(this, PROPERTY_NAME_ALPHA, MIN_ALPHA, MAX_ALPHA);
        mShowHideFrameAnimator.setInterpolator(interpolator);
        mShowHideFrameAnimator.setDuration(longAnimationDuration);
        mInvalidated = true;
      }
  void updateSurfacesInTransaction() {
    if (!mStarted) {
      return;
    }

    if (mSurface != null) {
      if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
        if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
        mSurface.hide();
      }
    }

    if (mCustomBlackFrame != null) {
      if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
        if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
        mCustomBlackFrame.hide();
      } else {
        mCustomBlackFrame.setMatrix(mFrameTransformation.getMatrix());
      }
    }

    if (mExitingBlackFrame != null) {
      if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
        if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding exiting frame");
        mExitingBlackFrame.hide();
      } else {
        mExitFrameFinalMatrix.setConcat(mExitTransformation.getMatrix(), mFrameInitialMatrix);
        mExitingBlackFrame.setMatrix(mExitFrameFinalMatrix);
      }
    }

    if (mEnteringBlackFrame != null) {
      if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) {
        if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding entering frame");
        mEnteringBlackFrame.hide();
      } else {
        mEnteringBlackFrame.setMatrix(mEnterTransformation.getMatrix());
      }
    }

    setSnapshotTransformInTransaction(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
  }
 private void teardownTorch() {
   setListenForScreenOff(false);
   dispatchStateChange(false);
   if (mCameraDevice != null) {
     mCameraDevice.close();
     mCameraDevice = null;
   }
   mOpeningCamera = false;
   mSession = null;
   mFlashlightRequest = null;
   if (mSurface != null) {
     mSurface.release();
   }
   mSurface = null;
   if (mSurfaceTexture != null) {
     mSurfaceTexture.release();
   }
   mSurfaceTexture = null;
   mTorchCameraId = -1;
 }
Beispiel #28
0
  private boolean createSurface() {
    if (mSurfaceSession == null) {
      mSurfaceSession = new SurfaceSession();
    }

    SurfaceControl.openTransaction();
    try {
      if (mSurfaceControl == null) {
        try {
          int flags;
          if (mMode == MODE_FADE) {
            flags = SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN;
          } else {
            flags = SurfaceControl.OPAQUE | SurfaceControl.HIDDEN;
          }
          mSurfaceControl =
              new SurfaceControl(
                  mSurfaceSession,
                  "ElectronBeam",
                  mDisplayWidth,
                  mDisplayHeight,
                  PixelFormat.OPAQUE,
                  flags);
        } catch (OutOfResourcesException ex) {
          Slog.e(TAG, "Unable to create surface.", ex);
          return false;
        }
      }

      mSurfaceControl.setLayerStack(mDisplayLayerStack);
      mSurfaceControl.setSize(mDisplayWidth, mDisplayHeight);
      mSurface = new Surface();
      mSurface.copyFrom(mSurfaceControl);

      mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManager, mSurfaceControl, mHWRotation);
      mSurfaceLayout.onDisplayTransaction();
    } finally {
      SurfaceControl.closeTransaction();
    }
    return true;
  }
 private void release() {
   Logging.d(TAG, "Java releaseDecoder");
   checkOnMediaCodecThread();
   try {
     mediaCodec.stop();
     mediaCodec.release();
   } catch (IllegalStateException e) {
     Logging.e(TAG, "release failed", e);
   }
   mediaCodec = null;
   mediaCodecThread = null;
   if (useSurface) {
     surface.release();
     if (textureID != 0) {
       Logging.d(TAG, "Delete video decoder TextureID " + textureID);
       GLES20.glDeleteTextures(1, new int[] {textureID}, 0);
       textureID = 0;
     }
     eglBase.release();
     eglBase = null;
   }
 }
 public void releaseSurface() {
   mSurfaceControl.release();
   mSurface.release();
 }