package com.google.maps.android.compose;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.View;
import android.view.ViewGroup;
import androidx.compose.runtime.ComposablesKt;
import androidx.compose.runtime.Composer;
import androidx.compose.runtime.ComposerKt;
import androidx.compose.runtime.CompositionContext;
import androidx.compose.runtime.ProvidableCompositionLocal;
import androidx.compose.runtime.SnapshotStateKt;
import androidx.compose.runtime.State;
import androidx.compose.ui.platform.AndroidCompositionLocals_androidKt;
import androidx.compose.ui.platform.ComposeView;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.SpreadBuilder;

/* JADX INFO: compiled from: RememberComposeBitmapDescriptor.kt */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u00008\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0011\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\u001a4\u0010\u0000\u001a\u00020\u00012\u0012\u0010\u0002\u001a\n\u0012\u0006\b\u0001\u0012\u00020\u00040\u0003\"\u00020\u00042\u0011\u0010\u0005\u001a\r\u0012\u0004\u0012\u00020\u00070\u0006¢\u0006\u0002\b\bH\u0001¢\u0006\u0002\u0010\t\u001a0\u0010\f\u001a\u00020\u00012\u0006\u0010\r\u001a\u00020\u000e2\u0006\u0010\u000f\u001a\u00020\u00102\u0011\u0010\u0005\u001a\r\u0012\u0004\u0012\u00020\u00070\u0006¢\u0006\u0002\b\bH\u0002¢\u0006\u0002\u0010\u0011\"\u000e\u0010\n\u001a\u00020\u000bX\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0012²\u0006\u0015\u0010\u0013\u001a\r\u0012\u0004\u0012\u00020\u00070\u0006¢\u0006\u0002\b\bX\u008a\u0084\u0002"}, d2 = {"rememberComposeBitmapDescriptor", "Lcom/google/android/gms/maps/model/BitmapDescriptor;", "keys", "", "", "content", "Lkotlin/Function0;", "", "Landroidx/compose/runtime/Composable;", "([Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;I)Lcom/google/android/gms/maps/model/BitmapDescriptor;", "measureSpec", "", "renderComposableToBitmapDescriptor", "parent", "Landroid/view/ViewGroup;", "compositionContext", "Landroidx/compose/runtime/CompositionContext;", "(Landroid/view/ViewGroup;Landroidx/compose/runtime/CompositionContext;Lkotlin/jvm/functions/Function2;)Lcom/google/android/gms/maps/model/BitmapDescriptor;", "maps-compose_release", "currentContent"}, k = 2, mv = {2, 0, 0}, xi = 48)
public final class RememberComposeBitmapDescriptorKt {
    private static final int measureSpec = View.MeasureSpec.makeMeasureSpec(0, 0);

    public static final BitmapDescriptor rememberComposeBitmapDescriptor(Object[] keys, Function2<? super Composer, ? super Integer, Unit> content, Composer composer, int i) {
        Intrinsics.checkNotNullParameter(keys, "keys");
        Intrinsics.checkNotNullParameter(content, "content");
        composer.startReplaceableGroup(1871105836);
        ProvidableCompositionLocal<View> localView = AndroidCompositionLocals_androidKt.getLocalView();
        ComposerKt.sourceInformationMarkerStart(composer, 2023513938, "CC:CompositionLocal.kt#9igjgp");
        Object objConsume = composer.consume(localView);
        ComposerKt.sourceInformationMarkerEnd(composer);
        Intrinsics.checkNotNull(objConsume, "null cannot be cast to non-null type android.view.ViewGroup");
        ViewGroup viewGroup = (ViewGroup) objConsume;
        CompositionContext compositionContextRememberCompositionContext = ComposablesKt.rememberCompositionContext(composer, 0);
        State stateRememberUpdatedState = SnapshotStateKt.rememberUpdatedState(content, composer, (i >> 3) & 14);
        SpreadBuilder spreadBuilder = new SpreadBuilder(4);
        spreadBuilder.add(viewGroup);
        spreadBuilder.add(compositionContextRememberCompositionContext);
        spreadBuilder.add(rememberComposeBitmapDescriptor$lambda$0(stateRememberUpdatedState));
        spreadBuilder.addSpread(keys);
        Object[] array = spreadBuilder.toArray(new Object[spreadBuilder.size()]);
        composer.startReplaceableGroup(-568225417);
        ComposerKt.sourceInformation(composer, "CC(remember)P(1):Composables.kt#9igjgp");
        boolean zChanged = false;
        for (Object obj : array) {
            zChanged |= composer.changed(obj);
        }
        Object objRememberedValue = composer.rememberedValue();
        if (zChanged || objRememberedValue == Composer.INSTANCE.getEmpty()) {
            objRememberedValue = renderComposableToBitmapDescriptor(viewGroup, compositionContextRememberCompositionContext, rememberComposeBitmapDescriptor$lambda$0(stateRememberUpdatedState));
            composer.updateRememberedValue(objRememberedValue);
        }
        composer.endReplaceableGroup();
        BitmapDescriptor bitmapDescriptor = (BitmapDescriptor) objRememberedValue;
        composer.endReplaceableGroup();
        return bitmapDescriptor;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final BitmapDescriptor renderComposableToBitmapDescriptor(ViewGroup viewGroup, CompositionContext compositionContext, Function2<? super Composer, ? super Integer, Unit> function2) {
        Canvas canvas = new Canvas();
        Context context = viewGroup.getContext();
        Intrinsics.checkNotNullExpressionValue(context, "getContext(...)");
        ComposeView composeView = new ComposeView(context, null, 0, 6, null);
        composeView.setLayoutParams(new ViewGroup.LayoutParams(-2, -2));
        composeView.setParentCompositionContext(compositionContext);
        composeView.setContent(function2);
        ComposeView composeView2 = composeView;
        viewGroup.addView(composeView2);
        composeView.draw(canvas);
        int i = measureSpec;
        composeView.measure(i, i);
        if (composeView.getMeasuredWidth() == 0 || composeView.getMeasuredHeight() == 0) {
            throw new IllegalStateException("The ComposeView was measured to have a width or height of zero. Make sure that the content has a non-zero size.");
        }
        composeView.layout(0, 0, composeView.getMeasuredWidth(), composeView.getMeasuredHeight());
        Bitmap bitmapCreateBitmap = Bitmap.createBitmap(composeView.getMeasuredWidth(), composeView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
        Intrinsics.checkNotNullExpressionValue(bitmapCreateBitmap, "createBitmap(...)");
        composeView.draw(new Canvas(bitmapCreateBitmap));
        viewGroup.removeView(composeView2);
        BitmapDescriptor bitmapDescriptorFromBitmap = BitmapDescriptorFactory.fromBitmap(bitmapCreateBitmap);
        Intrinsics.checkNotNullExpressionValue(bitmapDescriptorFromBitmap, "fromBitmap(...)");
        return bitmapDescriptorFromBitmap;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final Function2<Composer, Integer, Unit> rememberComposeBitmapDescriptor$lambda$0(State<? extends Function2<? super Composer, ? super Integer, Unit>> state) {
        return (Function2) state.getValue();
    }
}