michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.gfx; michael@0: michael@0: import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI; michael@0: import org.mozilla.gecko.util.FloatUtils; michael@0: michael@0: import android.graphics.RectF; michael@0: michael@0: /* michael@0: * This class keeps track of the area we request Gecko to paint, as well michael@0: * as the resolution of the paint. The area may be different from the visible michael@0: * area of the page, and the resolution may be different from the resolution michael@0: * used in the compositor to render the page. This is so that we can ask Gecko michael@0: * to paint a much larger area without using extra memory, and then render some michael@0: * subsection of that with compositor scaling. michael@0: */ michael@0: public final class DisplayPortMetrics { michael@0: @WrapElementForJNI michael@0: public final float resolution; michael@0: @WrapElementForJNI michael@0: private final RectF mPosition; michael@0: michael@0: public DisplayPortMetrics() { michael@0: this(0, 0, 0, 0, 1); michael@0: } michael@0: michael@0: @WrapElementForJNI michael@0: public DisplayPortMetrics(float left, float top, float right, float bottom, float resolution) { michael@0: this.resolution = resolution; michael@0: mPosition = new RectF(left, top, right, bottom); michael@0: } michael@0: michael@0: public float getLeft() { michael@0: return mPosition.left; michael@0: } michael@0: michael@0: public float getTop() { michael@0: return mPosition.top; michael@0: } michael@0: michael@0: public float getRight() { michael@0: return mPosition.right; michael@0: } michael@0: michael@0: public float getBottom() { michael@0: return mPosition.bottom; michael@0: } michael@0: michael@0: public boolean contains(RectF rect) { michael@0: return mPosition.contains(rect); michael@0: } michael@0: michael@0: public boolean fuzzyEquals(DisplayPortMetrics metrics) { michael@0: return RectUtils.fuzzyEquals(mPosition, metrics.mPosition) michael@0: && FloatUtils.fuzzyEquals(resolution, metrics.resolution); michael@0: } michael@0: michael@0: public String toJSON() { michael@0: StringBuilder sb = new StringBuilder(256); michael@0: sb.append("{ \"left\": ").append(mPosition.left) michael@0: .append(", \"top\": ").append(mPosition.top) michael@0: .append(", \"right\": ").append(mPosition.right) michael@0: .append(", \"bottom\": ").append(mPosition.bottom) michael@0: .append(", \"resolution\": ").append(resolution) michael@0: .append('}'); michael@0: return sb.toString(); michael@0: } michael@0: michael@0: @Override michael@0: public String toString() { michael@0: return "DisplayPortMetrics v=(" + mPosition.left + "," + mPosition.top + "," + mPosition.right + "," michael@0: + mPosition.bottom + ") z=" + resolution; michael@0: } michael@0: }