Example usage for android.graphics PointF offset

List of usage examples for android.graphics PointF offset

Introduction

In this page you can find the example usage for android.graphics PointF offset.

Prototype

public final void offset(float dx, float dy) 

Source Link

Usage

From source file:org.mozilla.gecko.gfx.ViewportMetrics.java

public void scaleTo(float newZoomFactor, PointF focus) {
    float scaleFactor = newZoomFactor / mZoomFactor;

    mPageSize = mPageSize.scale(scaleFactor);

    PointF origin = getOrigin();
    origin.offset(focus.x, focus.y);
    origin = PointUtils.scale(origin, scaleFactor);
    origin.offset(-focus.x, -focus.y);//from w  w w.j a  v  a  2 s  . c  o m
    setOrigin(origin);

    mZoomFactor = newZoomFactor;

    // Similar to setOrigin, set the viewport bias based on the focal point
    // of the zoom so that a viewport based on these metrics will have a
    // larger buffer based on the direction of movement when scaling.
    //
    // This is biased towards scaling outwards, as zooming in doesn't
    // really require a viewport bias.
    mViewportBias.set(((focus.x / mViewportRect.width()) * (2.0f * MAX_BIAS)) - MAX_BIAS,
            ((focus.y / mViewportRect.height()) * (2.0f * MAX_BIAS)) - MAX_BIAS);
}

From source file:org.mozilla.gecko.gfx.GeckoSoftwareLayerClient.java

public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight, String metadata,
        boolean hasDirectTexture) {
    setHasDirectTexture(hasDirectTexture);

    // Make sure the tile-size matches. If it doesn't, we could crash trying
    // to access invalid memory.
    if (mHasDirectTexture) {
        if (tileWidth != 0 || tileHeight != 0) {
            Log.e(LOGTAG, "Aborting draw, incorrect tile size of " + tileWidth + "x" + tileHeight);
            return null;
        }/*from   ww w.j a  v  a 2  s.  c  o  m*/
    } else {
        if (tileWidth != TILE_SIZE.width || tileHeight != TILE_SIZE.height) {
            Log.e(LOGTAG, "Aborting draw, incorrect tile size of " + tileWidth + "x" + tileHeight);
            return null;
        }
    }

    LayerController controller = getLayerController();

    try {
        JSONObject viewportObject = new JSONObject(metadata);
        mNewGeckoViewport = new ViewportMetrics(viewportObject);

        // Update the background color, if it's present.
        String backgroundColorString = viewportObject.optString("backgroundColor");
        if (backgroundColorString != null) {
            controller.setCheckerboardColor(parseColorFromGecko(backgroundColorString));
        }
    } catch (JSONException e) {
        Log.e(LOGTAG, "Aborting draw, bad viewport description: " + metadata);
        return null;
    }

    // Make sure we don't spend time painting areas we aren't interested in.
    // Only do this if the Gecko viewport isn't going to override our viewport.
    Rect bufferRect = new Rect(0, 0, width, height);

    if (!mUpdateViewportOnEndDraw) {
        // First, find out our ideal displayport. We do this by taking the
        // clamped viewport origin and taking away the optimum viewport offset.
        // This would be what we would send to Gecko if adjustViewport were
        // called now.
        ViewportMetrics currentMetrics = controller.getViewportMetrics();
        PointF currentBestOrigin = RectUtils.getOrigin(currentMetrics.getClampedViewport());
        PointF viewportOffset = currentMetrics.getOptimumViewportOffset(new IntSize(width, height));
        currentBestOrigin.offset(-viewportOffset.x, -viewportOffset.y);

        Rect currentRect = RectUtils.round(new RectF(currentBestOrigin.x, currentBestOrigin.y,
                currentBestOrigin.x + width, currentBestOrigin.y + height));

        // Second, store Gecko's displayport.
        PointF currentOrigin = mNewGeckoViewport.getDisplayportOrigin();
        bufferRect = RectUtils.round(
                new RectF(currentOrigin.x, currentOrigin.y, currentOrigin.x + width, currentOrigin.y + height));

        // Take the intersection of the two as the area we're interested in rendering.
        if (!bufferRect.intersect(currentRect)) {
            // If there's no intersection, we have no need to render anything,
            // but make sure to update the viewport size.
            beginTransaction(mTileLayer);
            try {
                updateViewport(true);
            } finally {
                endTransaction(mTileLayer);
            }
            return null;
        }
        bufferRect.offset(Math.round(-currentOrigin.x), Math.round(-currentOrigin.y));
    }

    beginTransaction(mTileLayer);

    // Synchronise the buffer size with Gecko.
    if (mBufferSize.width != width || mBufferSize.height != height) {
        mBufferSize = new IntSize(width, height);

        // Reallocate the buffer if necessary
        if (mTileLayer instanceof MultiTileLayer) {
            int bpp = CairoUtils.bitsPerPixelForCairoFormat(mFormat) / 8;
            int size = mBufferSize.getArea() * bpp;
            if (mBuffer == null || mBuffer.capacity() != size) {
                // Free the old buffer
                if (mBuffer != null) {
                    GeckoAppShell.freeDirectBuffer(mBuffer);
                    mBuffer = null;
                }

                mBuffer = GeckoAppShell.allocateDirectBuffer(size);
            }
        }
    }

    return bufferRect;
}