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 package android.hardware.camera2.marshal.impl; 17 18 import android.hardware.camera2.marshal.Marshaler; 19 import android.hardware.camera2.marshal.MarshalQueryable; 20 import android.hardware.camera2.utils.TypeReference; 21 import android.util.SizeF; 22 23 import static android.hardware.camera2.impl.CameraMetadataNative.*; 24 import static android.hardware.camera2.marshal.MarshalHelpers.*; 25 26 import java.nio.ByteBuffer; 27 28 /** 29 * Marshal {@link SizeF} to/from {@code TYPE_FLOAT} 30 */ 31 public class MarshalQueryableSizeF implements MarshalQueryable<SizeF> { 32 33 private static final int SIZE = SIZEOF_FLOAT * 2; 34 35 private class MarshalerSizeF extends Marshaler<SizeF> { 36 MarshalerSizeF(TypeReference<SizeF> typeReference, int nativeType)37 protected MarshalerSizeF(TypeReference<SizeF> typeReference, int nativeType) { 38 super(MarshalQueryableSizeF.this, typeReference, nativeType); 39 } 40 41 @Override marshal(SizeF value, ByteBuffer buffer)42 public void marshal(SizeF value, ByteBuffer buffer) { 43 buffer.putFloat(value.getWidth()); 44 buffer.putFloat(value.getHeight()); 45 } 46 47 @Override unmarshal(ByteBuffer buffer)48 public SizeF unmarshal(ByteBuffer buffer) { 49 float width = buffer.getFloat(); 50 float height = buffer.getFloat(); 51 52 return new SizeF(width, height); 53 } 54 55 @Override getNativeSize()56 public int getNativeSize() { 57 return SIZE; 58 } 59 } 60 61 @Override createMarshaler( TypeReference<SizeF> managedType, int nativeType)62 public Marshaler<SizeF> createMarshaler( 63 TypeReference<SizeF> managedType, int nativeType) { 64 return new MarshalerSizeF(managedType, nativeType); 65 } 66 67 @Override isTypeMappingSupported(TypeReference<SizeF> managedType, int nativeType)68 public boolean isTypeMappingSupported(TypeReference<SizeF> managedType, int nativeType) { 69 return nativeType == TYPE_FLOAT && (SizeF.class.equals(managedType.getType())); 70 } 71 } 72 73