Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c40a046 authored by Igor Murashkin's avatar Igor Murashkin
Browse files

camera2: Update native<->managed camera metadata marshalers

* Improve existing marshalers:
 - each managed/native type combination can be queried marshal support
 - marshalers can recursively call other marshalers for nested types
 - support marshaling/unmarshaling generic classes by using super type tokens

* Add new marshalers for:
 - ColorSpaceTransform
 - MeteringRectangle
 - Parcelable
 - Range<T>
 - ReprocessFormatsMap
 - RggbChannelVector
 - SizeF
 - StreamConfiguration
 - StreamConfigurationDuration

Batteries included; so are unit tests.

Bug: 14628001
Change-Id: I38d3e646ccfb3953898cd6f750c33e4097328482
parent bee74c2b
Loading
Loading
Loading
Loading
+40 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.camera2;

import android.hardware.camera2.impl.CameraMetadataNative;
import android.hardware.camera2.utils.TypeReference;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -126,11 +127,13 @@ public abstract class CameraMetadata {
        return keyList;
    }

    // TODO: make final or abstract
    public static class Key<T> {

        private boolean mHasTag;
        private int mTag;
        private final Class<T> mType;
        private final TypeReference<T> mTypeReference;
        private final String mName;

        /**
@@ -144,6 +147,22 @@ public abstract class CameraMetadata {
            }
            mName = name;
            mType = type;
            mTypeReference = TypeReference.createSpecializedTypeReference(type);
        }

        /**
         * @hide
         */
        @SuppressWarnings("unchecked")
        public Key(String name, TypeReference<T> typeReference) {
            if (name == null) {
                throw new NullPointerException("Key needs a valid name");
            } else if (typeReference == null) {
                throw new NullPointerException("TypeReference needs to be non-null");
            }
            mName = name;
            mType = (Class<T>)typeReference.getRawType();
            mTypeReference = typeReference;
        }

        public final String getName() {
@@ -152,11 +171,10 @@ public abstract class CameraMetadata {

        @Override
        public final int hashCode() {
            return mName.hashCode();
            return mName.hashCode() ^ mTypeReference.hashCode();
        }

        @Override
        @SuppressWarnings("unchecked")
        public final boolean equals(Object o) {
            if (this == o) {
                return true;
@@ -166,9 +184,8 @@ public abstract class CameraMetadata {
                return false;
            }

            Key lhs = (Key) o;

            return mName.equals(lhs.mName) && mType.equals(lhs.mType);
            Key<?> lhs = (Key<?>)o;
            return mName.equals(lhs.mName) && mTypeReference.equals(lhs.mTypeReference);
        }

        /**
@@ -192,11 +209,29 @@ public abstract class CameraMetadata {
        }

        /**
         * Get the raw class backing the type {@code T} for this key.
         *
         * <p>The distinction is only important if {@code T} is a generic, e.g.
         * {@code Range<Integer>} since the nested type will be erased.</p>
         *
         * @hide
         */
        public final Class<T> getType() {
            // TODO: remove this; other places should use #getTypeReference() instead
            return mType;
        }

        /**
         * Get the type reference backing the type {@code T} for this key.
         *
         * <p>The distinction is only important if {@code T} is a generic, e.g.
         * {@code Range<Integer>} since the nested type will be retained.</p>
         *
         * @hide
         */
        public final TypeReference<T> getTypeReference() {
            return mTypeReference;
        }
    }

    /*@O~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
+2 −1
Original line number Diff line number Diff line
@@ -17,7 +17,8 @@
package android.hardware.camera2;

import static com.android.internal.util.Preconditions.*;
import android.hardware.camera2.impl.HashCodeHelpers;

import android.hardware.camera2.utils.HashCodeHelpers;

import java.util.Arrays;

+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ package android.hardware.camera2;
import static com.android.internal.util.Preconditions.*;
import static android.hardware.camera2.RggbChannelVector.*;

import android.hardware.camera2.impl.HashCodeHelpers;
import android.hardware.camera2.utils.HashCodeHelpers;

import java.util.Arrays;

+2 −5
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import static com.android.internal.util.Preconditions.*;

import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.camera2.impl.HashCodeHelpers;
import android.hardware.camera2.utils.HashCodeHelpers;

/**
 * An immutable class to represent a rectangle {@code (x,y, width, height)} with an
@@ -186,10 +186,7 @@ public final class MeteringRectangle {
     */
    @Override
    public boolean equals(final Object other) {
        if (other instanceof MeteringRectangle) {
            return equals(other);
        }
        return false;
        return other instanceof MeteringRectangle && equals((MeteringRectangle)other);
    }

    /**
+8 −9
Original line number Diff line number Diff line
@@ -91,14 +91,14 @@ public final class Rational {
     * <p>A reduced form of a Rational is calculated by dividing both the numerator and the
     * denominator by their greatest common divisor.</p>
     *
     * <pre>
     * <pre>{@code
     *      (new Rational(1, 2)).equals(new Rational(1, 2)) == true   // trivially true
     *      (new Rational(2, 3)).equals(new Rational(1, 2)) == false  // trivially false
     *      (new Rational(1, 2)).equals(new Rational(2, 4)) == true   // true after reduction
     *      (new Rational(0, 0)).equals(new Rational(0, 0)) == true   // NaN.equals(NaN)
     *      (new Rational(1, 0)).equals(new Rational(5, 0)) == true   // both are +infinity
     *      (new Rational(1, 0)).equals(new Rational(-1, 0)) == false // +infinity != -infinity
     * </pre>
     * }</pre>
     *
     * @param obj a reference to another object
     *
@@ -159,16 +159,15 @@ public final class Rational {
        return (float) mNumerator / (float) mDenominator;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        final long INT_MASK = 0xffffffffL;

        long asLong = INT_MASK & mNumerator;
        asLong <<= 32;

        asLong |= (INT_MASK & mDenominator);
        // Bias the hash code for the first (2^16) values for both numerator and denominator
        int numeratorFlipped = mNumerator << 16 | mNumerator >>> 16;

        return ((Long)asLong).hashCode();
        return mDenominator ^ numeratorFlipped;
    }

    /**
Loading