blob: 5c1f301369e1795e362effe3ee04a6d2c5563464 [file] [log] [blame]
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.camera2.marshal.impl;
import android.hardware.camera2.marshal.MarshalQueryable;
import android.hardware.camera2.marshal.Marshaler;
import android.hardware.camera2.params.CapabilityAndMaxSize;
import android.hardware.camera2.utils.TypeReference;
import android.util.Size;
import java.nio.ByteBuffer;
import static android.hardware.camera2.impl.CameraMetadataNative.TYPE_INT32;
import static android.hardware.camera2.marshal.MarshalHelpers.SIZEOF_INT32;
/**
* Marshal {@link CapabilityAndMaxSize} to/from {@link #TYPE_INT32} {@code x CapabilityAndMaxSize.COUNT}
*/
public class MarshalQueryableCapabilityAndMaxSize implements MarshalQueryable<CapabilityAndMaxSize> {
private static final int SIZE = SIZEOF_INT32 * CapabilityAndMaxSize.COUNT;
private class MarshalerCapabilityAndMaxSize extends Marshaler<CapabilityAndMaxSize> {
protected MarshalerCapabilityAndMaxSize(TypeReference<CapabilityAndMaxSize> typeReference,
int nativeType) {
super(MarshalQueryableCapabilityAndMaxSize.this, typeReference, nativeType);
}
@Override
public void marshal(CapabilityAndMaxSize value, ByteBuffer buffer) {
Size maxStreamingSize = value.getMaxStreamingSize();
buffer.putInt(value.getMode());
buffer.putInt(maxStreamingSize.getWidth());
buffer.putInt(maxStreamingSize.getHeight());
}
@Override
public CapabilityAndMaxSize unmarshal(ByteBuffer buffer) {
int mode = buffer.getInt();
int maxWidth = buffer.getInt();
int maxHeight = buffer.getInt();
return new CapabilityAndMaxSize(mode, maxWidth, maxHeight);
}
@Override
public int getNativeSize() {
return SIZE;
}
}
@Override
public Marshaler<CapabilityAndMaxSize> createMarshaler(
TypeReference<CapabilityAndMaxSize> managedType, int nativeType) {
return new MarshalerCapabilityAndMaxSize(managedType, nativeType);
}
@Override
public boolean isTypeMappingSupported(
TypeReference<CapabilityAndMaxSize> managedType, int nativeType) {
return nativeType == TYPE_INT32 &&
(CapabilityAndMaxSize.class.equals(managedType.getType()));
}
}