private void updateScreenBitmap()

in stetho/src/main/java/com/facebook/stetho/inspector/screencast/ScreencastDispatcher.java [76:106]


    private void updateScreenBitmap() {
      if (!mIsRunning) {
        return;
      }
      Activity activity = mActivityTracker.tryGetTopActivity();
      if (activity == null) {
        return;
      }
      // This stuff needs to happen in the UI thread
      View rootView = activity.getWindow().getDecorView();
      try {
        if (mBitmap == null) {
          int viewWidth = rootView.getWidth();
          int viewHeight = rootView.getHeight();
          float scale = Math.min((float) mRequest.maxWidth / (float) viewWidth,
              (float) mRequest.maxHeight / (float) viewHeight);
          int destWidth = (int) (viewWidth * scale);
          int destHeight = (int) (viewHeight * scale);
          mBitmap = Bitmap.createBitmap(destWidth, destHeight, Bitmap.Config.RGB_565);
          mCanvas = new Canvas(mBitmap);
          Matrix matrix = new Matrix();
          mTempSrc.set(0, 0, viewWidth, viewHeight);
          mTempDst.set(0, 0, destWidth, destHeight);
          matrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER);
          mCanvas.setMatrix(matrix);
        }
        rootView.draw(mCanvas);
      } catch (OutOfMemoryError e) {
        LogUtil.w("Out of memory trying to allocate screencast Bitmap.");
      }
    }