mobile/android/base/gfx/DisplayPortMetrics.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/gfx/DisplayPortMetrics.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +package org.mozilla.gecko.gfx;
    1.10 +
    1.11 +import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
    1.12 +import org.mozilla.gecko.util.FloatUtils;
    1.13 +
    1.14 +import android.graphics.RectF;
    1.15 +
    1.16 +/*
    1.17 + * This class keeps track of the area we request Gecko to paint, as well
    1.18 + * as the resolution of the paint. The area may be different from the visible
    1.19 + * area of the page, and the resolution may be different from the resolution
    1.20 + * used in the compositor to render the page. This is so that we can ask Gecko
    1.21 + * to paint a much larger area without using extra memory, and then render some
    1.22 + * subsection of that with compositor scaling.
    1.23 + */
    1.24 +public final class DisplayPortMetrics {
    1.25 +    @WrapElementForJNI
    1.26 +    public final float resolution;
    1.27 +    @WrapElementForJNI
    1.28 +    private final RectF mPosition;
    1.29 +
    1.30 +    public DisplayPortMetrics() {
    1.31 +        this(0, 0, 0, 0, 1);
    1.32 +    }
    1.33 +
    1.34 +    @WrapElementForJNI
    1.35 +    public DisplayPortMetrics(float left, float top, float right, float bottom, float resolution) {
    1.36 +        this.resolution = resolution;
    1.37 +        mPosition = new RectF(left, top, right, bottom);
    1.38 +    }
    1.39 +
    1.40 +    public float getLeft() {
    1.41 +        return mPosition.left;
    1.42 +    }
    1.43 +
    1.44 +    public float getTop() {
    1.45 +        return mPosition.top;
    1.46 +    }
    1.47 +
    1.48 +    public float getRight() {
    1.49 +        return mPosition.right;
    1.50 +    }
    1.51 +
    1.52 +    public float getBottom() {
    1.53 +        return mPosition.bottom;
    1.54 +    }
    1.55 +
    1.56 +    public boolean contains(RectF rect) {
    1.57 +        return mPosition.contains(rect);
    1.58 +    }
    1.59 +
    1.60 +    public boolean fuzzyEquals(DisplayPortMetrics metrics) {
    1.61 +        return RectUtils.fuzzyEquals(mPosition, metrics.mPosition)
    1.62 +            && FloatUtils.fuzzyEquals(resolution, metrics.resolution);
    1.63 +    }
    1.64 +
    1.65 +    public String toJSON() {
    1.66 +        StringBuilder sb = new StringBuilder(256);
    1.67 +        sb.append("{ \"left\": ").append(mPosition.left)
    1.68 +          .append(", \"top\": ").append(mPosition.top)
    1.69 +          .append(", \"right\": ").append(mPosition.right)
    1.70 +          .append(", \"bottom\": ").append(mPosition.bottom)
    1.71 +          .append(", \"resolution\": ").append(resolution)
    1.72 +          .append('}');
    1.73 +        return sb.toString();
    1.74 +    }
    1.75 +
    1.76 +    @Override
    1.77 +    public String toString() {
    1.78 +        return "DisplayPortMetrics v=(" + mPosition.left + "," + mPosition.top + "," + mPosition.right + ","
    1.79 +                + mPosition.bottom + ") z=" + resolution;
    1.80 +    }
    1.81 +}

mercurial