public final class

SurfaceWrapper

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.activity.renderer.surface.SurfaceWrapper

Gradle dependencies

compile group: 'androidx.car.app', name: 'app-automotive', version: '1.2.0-rc01'

  • groupId: androidx.car.app
  • artifactId: app-automotive
  • version: 1.2.0-rc01

Artifact androidx.car.app:app-automotive:1.2.0-rc01 it located at Google repository (https://maven.google.com/)

Overview

A class holding the information needed to render the content on a surface.

Summary

Constructors
publicSurfaceWrapper(IBinder hostToken, int width, int height, int displayId, int densityDpi, Surface surface)

Creates a SurfaceWrapper.

Methods
public intgetDensityDpi()

Returns the screen density expressed as dots-per-inch of the for the contained .

public intgetDisplayId()

Returns the display id of the for the contained in this class.

public intgetHeight()

Returns the height of the contained in pixels.

public IBindergetHostToken()

Returns the host token corresponding to the contained in this class.

public SurfacegetSurface()

Returns the of the contained .

public intgetWidth()

Returns the width of the contained in pixels.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public SurfaceWrapper(IBinder hostToken, int width, int height, int displayId, int densityDpi, Surface surface)

Creates a SurfaceWrapper.

Parameters:

hostToken: a token used for constructing SurfaceControlViewHost. see for more details
width: the width of the surface view in pixels
height: the height of the surface view in pixels
displayId: the ID of the display showing the surface
densityDpi: the density of the display showing the surface expressed as dots-per-inch
surface: the surface for which the wrapper is created

Methods

public IBinder getHostToken()

Returns the host token corresponding to the contained in this class.

public int getWidth()

Returns the width of the contained in pixels.

public int getHeight()

Returns the height of the contained in pixels.

public int getDisplayId()

Returns the display id of the for the contained in this class.

public int getDensityDpi()

Returns the screen density expressed as dots-per-inch of the for the contained .

public Surface getSurface()

Returns the of the contained .

Source

/*
 * Copyright 2021 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 androidx.car.app.activity.renderer.surface;

import static java.util.Objects.requireNonNull;

import android.os.IBinder;
import android.view.Surface;
import android.view.SurfaceView;

import androidx.annotation.Dimension;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * A class holding the information needed to render the content on a surface.
 */
public final class SurfaceWrapper {
    @Keep
    @Nullable
    private IBinder mHostToken;
    @Keep
    @Dimension
    private int mWidth;
    @Keep
    @Dimension
    private int mHeight;
    @Keep
    private int mDisplayId;
    @Keep
    private int mDensityDpi;
    @Keep
    @Nullable
    private Surface mSurface;

    /**
     * Creates a {@link SurfaceWrapper}.
     *
     * @param hostToken  a token used for constructing SurfaceControlViewHost. see
     *                   {@link SurfaceView} for more details
     * @param width      the width of the surface view in pixels
     * @param height     the height of the surface view in pixels
     * @param displayId  the ID of the display showing the surface
     * @param densityDpi the density of the display showing the surface expressed as dots-per-inch
     * @param surface    the surface for which the wrapper is created
     */
    public SurfaceWrapper(@Nullable IBinder hostToken, @Dimension int width, @Dimension int height,
            int displayId, int densityDpi, @NonNull Surface surface) {
        mHostToken = hostToken;
        mWidth = width;
        mHeight = height;
        mDisplayId = displayId;
        mDensityDpi = densityDpi;
        mSurface = surface;
    }

    /** Empty constructor needed for serializations. **/
    private SurfaceWrapper() {
    }

    /**
     * Returns the host token corresponding to the {@link SurfaceView} contained in this class.
     */
    @Nullable
    public IBinder getHostToken() {
        return mHostToken;
    }

    /**
     * Returns the width of the contained {@link SurfaceView} in pixels.
     */
    @Dimension
    public int getWidth() {
        return mWidth;
    }

    /**
     * Returns the height of the contained {@link SurfaceView} in pixels.
     */
    @Dimension
    public int getHeight() {
        return mHeight;
    }

    /**
     * Returns the display id of the {@link android.view.Display} for the {@link SurfaceView}
     * contained in this class.
     */
    public int getDisplayId() {
        return mDisplayId;
    }

    /**
     * Returns the screen density expressed as dots-per-inch of the {@link android.view.Display}
     * for the contained {@link SurfaceView}.
     */
    public int getDensityDpi() {
        return mDensityDpi;
    }

    /**
     * Returns the {@link Surface} of the contained {@link SurfaceView}.
     */
    @NonNull
    public Surface getSurface() {
        return requireNonNull(mSurface);
    }
}