Home | History | Annotate | Download | only in camera2proxy
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.camera.one.v2.camera2proxy;
     18 
     19 import android.graphics.Rect;
     20 import android.media.Image;
     21 
     22 import com.google.common.base.Objects;
     23 
     24 import java.util.List;
     25 
     26 import javax.annotation.concurrent.ThreadSafe;
     27 
     28 /**
     29  * Forwards all {@link ImageProxy} methods.
     30  */
     31 @ThreadSafe
     32 public abstract class ForwardingImageProxy implements ImageProxy {
     33     private final ImageProxy mImpl;
     34 
     35     public ForwardingImageProxy(ImageProxy proxy) {
     36         mImpl = proxy;
     37     }
     38 
     39     /**
     40      * @see {@link android.media.Image#getCropRect}
     41      */
     42     @Override
     43     public Rect getCropRect() {
     44         return mImpl.getCropRect();
     45     }
     46 
     47     /**
     48      * @see {@link android.media.Image#setCropRect}
     49      */
     50     @Override
     51     public void setCropRect(Rect cropRect) {
     52         mImpl.setCropRect(cropRect);
     53     }
     54 
     55     /**
     56      * @see {@link android.media.Image#getFormat}
     57      */
     58     @Override
     59     public int getFormat() {
     60         return mImpl.getFormat();
     61     }
     62 
     63     /**
     64      * @see {@link android.media.Image#getHeight}
     65      */
     66     @Override
     67     public int getHeight() {
     68         return mImpl.getHeight();
     69     }
     70 
     71     /**
     72      * @see {@link android.media.Image#getPlanes}
     73      */
     74     @Override
     75     public List<Plane> getPlanes() {
     76         return mImpl.getPlanes();
     77     }
     78 
     79     /**
     80      * @see {@link android.media.Image#getTimestamp}
     81      */
     82     @Override
     83     public long getTimestamp() {
     84         return mImpl.getTimestamp();
     85     }
     86 
     87     /**
     88      * @see {@link android.media.Image#getWidth}
     89      */
     90     @Override
     91     public int getWidth() {
     92         return mImpl.getWidth();
     93     }
     94 
     95     /**
     96      * @see {@link android.media.Image#close}
     97      */
     98     @Override
     99     public void close() {
    100         mImpl.close();
    101     }
    102 
    103     @Override
    104     public String toString() {
    105         return Objects.toStringHelper(this)
    106                 .add("timestamp", getTimestamp())
    107                 .add("width", getWidth())
    108                 .add("height", getHeight())
    109                 .toString();
    110     }
    111 
    112     @Override
    113     public boolean equals(Object other) {
    114         if (other == null) {
    115             return false;
    116         }
    117         if (!(other instanceof ImageProxy)) {
    118             return false;
    119         }
    120         ImageProxy otherImage = (ImageProxy) other;
    121         return otherImage.getFormat() == getFormat() &&
    122                 otherImage.getWidth() == getWidth() &&
    123                 otherImage.getHeight() == getHeight() &&
    124                 otherImage.getTimestamp() == getTimestamp();
    125     }
    126 
    127     @Override
    128     public int hashCode() {
    129         return Objects.hashCode(getFormat(), getWidth(), getHeight(), getTimestamp());
    130     }
    131 }
    132