mobile/android/base/gfx/DisplayPortMetrics.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 package org.mozilla.gecko.gfx;
michael@0 7
michael@0 8 import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
michael@0 9 import org.mozilla.gecko.util.FloatUtils;
michael@0 10
michael@0 11 import android.graphics.RectF;
michael@0 12
michael@0 13 /*
michael@0 14 * This class keeps track of the area we request Gecko to paint, as well
michael@0 15 * as the resolution of the paint. The area may be different from the visible
michael@0 16 * area of the page, and the resolution may be different from the resolution
michael@0 17 * used in the compositor to render the page. This is so that we can ask Gecko
michael@0 18 * to paint a much larger area without using extra memory, and then render some
michael@0 19 * subsection of that with compositor scaling.
michael@0 20 */
michael@0 21 public final class DisplayPortMetrics {
michael@0 22 @WrapElementForJNI
michael@0 23 public final float resolution;
michael@0 24 @WrapElementForJNI
michael@0 25 private final RectF mPosition;
michael@0 26
michael@0 27 public DisplayPortMetrics() {
michael@0 28 this(0, 0, 0, 0, 1);
michael@0 29 }
michael@0 30
michael@0 31 @WrapElementForJNI
michael@0 32 public DisplayPortMetrics(float left, float top, float right, float bottom, float resolution) {
michael@0 33 this.resolution = resolution;
michael@0 34 mPosition = new RectF(left, top, right, bottom);
michael@0 35 }
michael@0 36
michael@0 37 public float getLeft() {
michael@0 38 return mPosition.left;
michael@0 39 }
michael@0 40
michael@0 41 public float getTop() {
michael@0 42 return mPosition.top;
michael@0 43 }
michael@0 44
michael@0 45 public float getRight() {
michael@0 46 return mPosition.right;
michael@0 47 }
michael@0 48
michael@0 49 public float getBottom() {
michael@0 50 return mPosition.bottom;
michael@0 51 }
michael@0 52
michael@0 53 public boolean contains(RectF rect) {
michael@0 54 return mPosition.contains(rect);
michael@0 55 }
michael@0 56
michael@0 57 public boolean fuzzyEquals(DisplayPortMetrics metrics) {
michael@0 58 return RectUtils.fuzzyEquals(mPosition, metrics.mPosition)
michael@0 59 && FloatUtils.fuzzyEquals(resolution, metrics.resolution);
michael@0 60 }
michael@0 61
michael@0 62 public String toJSON() {
michael@0 63 StringBuilder sb = new StringBuilder(256);
michael@0 64 sb.append("{ \"left\": ").append(mPosition.left)
michael@0 65 .append(", \"top\": ").append(mPosition.top)
michael@0 66 .append(", \"right\": ").append(mPosition.right)
michael@0 67 .append(", \"bottom\": ").append(mPosition.bottom)
michael@0 68 .append(", \"resolution\": ").append(resolution)
michael@0 69 .append('}');
michael@0 70 return sb.toString();
michael@0 71 }
michael@0 72
michael@0 73 @Override
michael@0 74 public String toString() {
michael@0 75 return "DisplayPortMetrics v=(" + mPosition.left + "," + mPosition.top + "," + mPosition.right + ","
michael@0 76 + mPosition.bottom + ") z=" + resolution;
michael@0 77 }
michael@0 78 }

mercurial