Search in sources :

Example 1 with HardwareCanvas

use of android.view.HardwareCanvas in project android_frameworks_base by ParanoidAndroid.

the class WebViewClassic method drawContent.

private void drawContent(Canvas canvas) {
    if (mDrawHistory) {
        canvas.scale(mZoomManager.getScale(), mZoomManager.getScale());
        canvas.drawPicture(mHistoryPicture);
        return;
    }
    if (mNativeClass == 0)
        return;
    boolean animateZoom = mZoomManager.isFixedLengthAnimationInProgress();
    boolean animateScroll = ((!mScroller.isFinished() || mVelocityTracker != null) && (mTouchMode != TOUCH_DRAG_MODE || mHeldMotionless != MOTIONLESS_TRUE));
    if (mTouchMode == TOUCH_DRAG_MODE) {
        if (mHeldMotionless == MOTIONLESS_PENDING) {
            mPrivateHandler.removeMessages(DRAG_HELD_MOTIONLESS);
            mHeldMotionless = MOTIONLESS_FALSE;
        }
        if (mHeldMotionless == MOTIONLESS_FALSE) {
            mPrivateHandler.sendMessageDelayed(mPrivateHandler.obtainMessage(DRAG_HELD_MOTIONLESS), MOTIONLESS_TIME);
            mHeldMotionless = MOTIONLESS_PENDING;
        }
    }
    int saveCount = canvas.save();
    if (animateZoom) {
        mZoomManager.animateZoom(canvas);
    } else if (!canvas.isHardwareAccelerated()) {
        canvas.scale(mZoomManager.getScale(), mZoomManager.getScale());
    }
    boolean UIAnimationsRunning = false;
    // We may in the future decide to do that independently.
    if (mNativeClass != 0 && !canvas.isHardwareAccelerated() && nativeEvaluateLayersAnimations(mNativeClass)) {
        UIAnimationsRunning = true;
        // If we have unfinished (or unstarted) animations,
        // we ask for a repaint. We only need to do this in software
        // rendering (with hardware rendering we already have a different
        // method of requesting a repaint)
        mWebViewCore.sendMessage(EventHub.NOTIFY_ANIMATION_STARTED);
        invalidate();
    }
    // decide which adornments to draw
    int extras = DRAW_EXTRAS_NONE;
    if (!mFindIsUp && mShowTextSelectionExtra) {
        extras = DRAW_EXTRAS_SELECTION;
    }
    calcOurContentVisibleRectF(mVisibleContentRect);
    if (canvas.isHardwareAccelerated()) {
        Rect invScreenRect = mIsWebViewVisible ? mInvScreenRect : null;
        Rect screenRect = mIsWebViewVisible ? mScreenRect : null;
        int functor = nativeCreateDrawGLFunction(mNativeClass, invScreenRect, screenRect, mVisibleContentRect, getScale(), extras);
        ((HardwareCanvas) canvas).callDrawGLFunction(functor);
        if (mHardwareAccelSkia != getSettings().getHardwareAccelSkiaEnabled()) {
            mHardwareAccelSkia = getSettings().getHardwareAccelSkiaEnabled();
            nativeUseHardwareAccelSkia(mHardwareAccelSkia);
        }
    } else {
        DrawFilter df = null;
        if (mZoomManager.isZoomAnimating() || UIAnimationsRunning) {
            df = mZoomFilter;
        } else if (animateScroll) {
            df = mScrollFilter;
        }
        canvas.setDrawFilter(df);
        nativeDraw(canvas, mVisibleContentRect, mBackgroundColor, extras);
        canvas.setDrawFilter(null);
    }
    canvas.restoreToCount(saveCount);
    drawTextSelectionHandles(canvas);
    if (extras == DRAW_EXTRAS_CURSOR_RING) {
        if (mTouchMode == TOUCH_SHORTPRESS_START_MODE) {
            mTouchMode = TOUCH_SHORTPRESS_MODE;
        }
    }
}
Also used : Rect(android.graphics.Rect) HardwareCanvas(android.view.HardwareCanvas) DrawFilter(android.graphics.DrawFilter) PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 2 with HardwareCanvas

use of android.view.HardwareCanvas in project android_frameworks_base by ParanoidAndroid.

the class Editor method drawHardwareAccelerated.

private void drawHardwareAccelerated(Canvas canvas, Layout layout, Path highlight, Paint highlightPaint, int cursorOffsetVertical) {
    final long lineRange = layout.getLineRangeForDraw(canvas);
    int firstLine = TextUtils.unpackRangeStartFromLong(lineRange);
    int lastLine = TextUtils.unpackRangeEndFromLong(lineRange);
    if (lastLine < 0)
        return;
    layout.drawBackground(canvas, highlight, highlightPaint, cursorOffsetVertical, firstLine, lastLine);
    if (layout instanceof DynamicLayout) {
        if (mTextDisplayLists == null) {
            mTextDisplayLists = new DisplayList[ArrayUtils.idealObjectArraySize(0)];
        }
        DynamicLayout dynamicLayout = (DynamicLayout) layout;
        int[] blockEndLines = dynamicLayout.getBlockEndLines();
        int[] blockIndices = dynamicLayout.getBlockIndices();
        final int numberOfBlocks = dynamicLayout.getNumberOfBlocks();
        final int indexFirstChangedBlock = dynamicLayout.getIndexFirstChangedBlock();
        int endOfPreviousBlock = -1;
        int searchStartIndex = 0;
        for (int i = 0; i < numberOfBlocks; i++) {
            int blockEndLine = blockEndLines[i];
            int blockIndex = blockIndices[i];
            final boolean blockIsInvalid = blockIndex == DynamicLayout.INVALID_BLOCK_INDEX;
            if (blockIsInvalid) {
                blockIndex = getAvailableDisplayListIndex(blockIndices, numberOfBlocks, searchStartIndex);
                // Note how dynamic layout's internal block indices get updated from Editor
                blockIndices[i] = blockIndex;
                searchStartIndex = blockIndex + 1;
            }
            DisplayList blockDisplayList = mTextDisplayLists[blockIndex];
            if (blockDisplayList == null) {
                blockDisplayList = mTextDisplayLists[blockIndex] = mTextView.getHardwareRenderer().createDisplayList("Text " + blockIndex);
            } else {
                if (blockIsInvalid)
                    blockDisplayList.clear();
            }
            final boolean blockDisplayListIsInvalid = !blockDisplayList.isValid();
            if (i >= indexFirstChangedBlock || blockDisplayListIsInvalid) {
                final int blockBeginLine = endOfPreviousBlock + 1;
                final int top = layout.getLineTop(blockBeginLine);
                final int bottom = layout.getLineBottom(blockEndLine);
                int left = 0;
                int right = mTextView.getWidth();
                if (mTextView.getHorizontallyScrolling()) {
                    float min = Float.MAX_VALUE;
                    float max = Float.MIN_VALUE;
                    for (int line = blockBeginLine; line <= blockEndLine; line++) {
                        min = Math.min(min, layout.getLineLeft(line));
                        max = Math.max(max, layout.getLineRight(line));
                    }
                    left = (int) min;
                    right = (int) (max + 0.5f);
                }
                // Rebuild display list if it is invalid
                if (blockDisplayListIsInvalid) {
                    final HardwareCanvas hardwareCanvas = blockDisplayList.start(right - left, bottom - top);
                    try {
                        // drawText is always relative to TextView's origin, this translation
                        // brings this range of text back to the top left corner of the viewport
                        hardwareCanvas.translate(-left, -top);
                        layout.drawText(hardwareCanvas, blockBeginLine, blockEndLine);
                    // No need to untranslate, previous context is popped after
                    // drawDisplayList
                    } finally {
                        blockDisplayList.end();
                        // Same as drawDisplayList below, handled by our TextView's parent
                        blockDisplayList.setClipToBounds(false);
                    }
                }
                // Valid disply list whose index is >= indexFirstChangedBlock
                // only needs to update its drawing location.
                blockDisplayList.setLeftTopRightBottom(left, top, right, bottom);
            }
            ((HardwareCanvas) canvas).drawDisplayList(blockDisplayList, null, 0);
            endOfPreviousBlock = blockEndLine;
        }
        dynamicLayout.setIndexFirstChangedBlock(numberOfBlocks);
    } else {
        // Boring layout is used for empty and hint text
        layout.drawText(canvas, firstLine, lastLine);
    }
}
Also used : DisplayList(android.view.DisplayList) HardwareCanvas(android.view.HardwareCanvas) DynamicLayout(android.text.DynamicLayout) Paint(android.graphics.Paint)

Example 3 with HardwareCanvas

use of android.view.HardwareCanvas in project XobotOS by xamarin.

the class WebView method drawCoreAndCursorRing.

private void drawCoreAndCursorRing(Canvas canvas, int color, boolean drawCursorRing) {
    if (mDrawHistory) {
        canvas.scale(mZoomManager.getScale(), mZoomManager.getScale());
        canvas.drawPicture(mHistoryPicture);
        return;
    }
    if (mNativeClass == 0)
        return;
    boolean animateZoom = mZoomManager.isFixedLengthAnimationInProgress();
    boolean animateScroll = ((!mScroller.isFinished() || mVelocityTracker != null) && (mTouchMode != TOUCH_DRAG_MODE || mHeldMotionless != MOTIONLESS_TRUE)) || mDeferTouchMode == TOUCH_DRAG_MODE;
    if (mTouchMode == TOUCH_DRAG_MODE) {
        if (mHeldMotionless == MOTIONLESS_PENDING) {
            mPrivateHandler.removeMessages(DRAG_HELD_MOTIONLESS);
            mPrivateHandler.removeMessages(AWAKEN_SCROLL_BARS);
            mHeldMotionless = MOTIONLESS_FALSE;
        }
        if (mHeldMotionless == MOTIONLESS_FALSE) {
            mPrivateHandler.sendMessageDelayed(mPrivateHandler.obtainMessage(DRAG_HELD_MOTIONLESS), MOTIONLESS_TIME);
            mHeldMotionless = MOTIONLESS_PENDING;
        }
    }
    int saveCount = canvas.save();
    if (animateZoom) {
        mZoomManager.animateZoom(canvas);
    } else if (!canvas.isHardwareAccelerated()) {
        canvas.scale(mZoomManager.getScale(), mZoomManager.getScale());
    }
    boolean UIAnimationsRunning = false;
    // We may in the future decide to do that independently.
    if (mNativeClass != 0 && nativeEvaluateLayersAnimations(mNativeClass)) {
        UIAnimationsRunning = true;
        // method of requesting a repaint)
        if (!canvas.isHardwareAccelerated())
            invalidate();
    }
    // decide which adornments to draw
    int extras = DRAW_EXTRAS_NONE;
    if (mFindIsUp) {
        extras = DRAW_EXTRAS_FIND;
    } else if (mSelectingText && !USE_JAVA_TEXT_SELECTION) {
        extras = DRAW_EXTRAS_SELECTION;
        nativeSetSelectionPointer(mNativeClass, mDrawSelectionPointer, mZoomManager.getInvScale(), mSelectX, mSelectY - getTitleHeight());
    } else if (drawCursorRing) {
        extras = DRAW_EXTRAS_CURSOR_RING;
    }
    if (DebugFlags.WEB_VIEW) {
        Log.v(LOGTAG, "mFindIsUp=" + mFindIsUp + " mSelectingText=" + mSelectingText + " nativePageShouldHandleShiftAndArrows()=" + nativePageShouldHandleShiftAndArrows() + " animateZoom=" + animateZoom + " extras=" + extras);
    }
    if (canvas.isHardwareAccelerated()) {
        int functor = nativeGetDrawGLFunction(mNativeClass, mGLViewportEmpty ? null : mGLRectViewport, mGLViewportEmpty ? null : mViewRectViewport, getScale(), extras);
        ((HardwareCanvas) canvas).callDrawGLFunction(functor);
        if (mHardwareAccelSkia != getSettings().getHardwareAccelSkiaEnabled()) {
            mHardwareAccelSkia = getSettings().getHardwareAccelSkiaEnabled();
            nativeUseHardwareAccelSkia(mHardwareAccelSkia);
        }
    } else {
        DrawFilter df = null;
        if (mZoomManager.isZoomAnimating() || UIAnimationsRunning) {
            df = mZoomFilter;
        } else if (animateScroll) {
            df = mScrollFilter;
        }
        canvas.setDrawFilter(df);
        // XXX: Revisit splitting content.  Right now it causes a
        // synchronization problem with layers.
        int content = nativeDraw(canvas, color, extras, false);
        canvas.setDrawFilter(null);
        if (!mBlockWebkitViewMessages && content != 0) {
            mWebViewCore.sendMessage(EventHub.SPLIT_PICTURE_SET, content, 0);
        }
    }
    canvas.restoreToCount(saveCount);
    if (mSelectingText && USE_JAVA_TEXT_SELECTION) {
        drawTextSelectionHandles(canvas);
    }
    if (extras == DRAW_EXTRAS_CURSOR_RING) {
        if (mTouchMode == TOUCH_SHORTPRESS_START_MODE) {
            mTouchMode = TOUCH_SHORTPRESS_MODE;
        }
    }
    if (mFocusSizeChanged) {
        mFocusSizeChanged = false;
        // updates the WebTextView position in sync with page swapping
        if (!canvas.isHardwareAccelerated() && !animateZoom && inEditingMode()) {
            didUpdateWebTextViewDimensions(ANYWHERE);
        }
    }
}
Also used : HardwareCanvas(android.view.HardwareCanvas) DrawFilter(android.graphics.DrawFilter) PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter) Paint(android.graphics.Paint) Point(android.graphics.Point)

Aggregations

Paint (android.graphics.Paint)3 HardwareCanvas (android.view.HardwareCanvas)3 DrawFilter (android.graphics.DrawFilter)2 PaintFlagsDrawFilter (android.graphics.PaintFlagsDrawFilter)2 Point (android.graphics.Point)2 Rect (android.graphics.Rect)1 DynamicLayout (android.text.DynamicLayout)1 DisplayList (android.view.DisplayList)1