Move setFrameRate calls into wrapper class
PiperOrigin-RevId: 388187294
This commit is contained in:
parent
181838168c
commit
ce7c04fac1
@ -27,6 +27,7 @@ import android.view.Choreographer.FrameCallback;
|
|||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import androidx.annotation.DoNotInline;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
@ -346,7 +347,7 @@ public final class VideoFrameReleaseHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.surfacePlaybackFrameRate = surfacePlaybackFrameRate;
|
this.surfacePlaybackFrameRate = surfacePlaybackFrameRate;
|
||||||
setSurfaceFrameRateV30(surface, surfacePlaybackFrameRate);
|
SurfaceApi30.setFrameRate(surface, surfacePlaybackFrameRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Clears the frame-rate of the current {@link #surface}. */
|
/** Clears the frame-rate of the current {@link #surface}. */
|
||||||
@ -355,20 +356,7 @@ public final class VideoFrameReleaseHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
surfacePlaybackFrameRate = 0;
|
surfacePlaybackFrameRate = 0;
|
||||||
setSurfaceFrameRateV30(surface, /* frameRate= */ 0);
|
SurfaceApi30.setFrameRate(surface, /* frameRate= */ 0);
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresApi(30)
|
|
||||||
private static void setSurfaceFrameRateV30(Surface surface, float frameRate) {
|
|
||||||
int compatibility =
|
|
||||||
frameRate == 0
|
|
||||||
? Surface.FRAME_RATE_COMPATIBILITY_DEFAULT
|
|
||||||
: Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE;
|
|
||||||
try {
|
|
||||||
surface.setFrameRate(frameRate, compatibility);
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
Log.e(TAG, "Failed to call Surface.setFrameRate", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display refresh rate and vsync logic.
|
// Display refresh rate and vsync logic.
|
||||||
@ -417,6 +405,24 @@ public final class VideoFrameReleaseHelper {
|
|||||||
return displayHelper;
|
return displayHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nested classes.
|
||||||
|
|
||||||
|
@RequiresApi(30)
|
||||||
|
private static final class SurfaceApi30 {
|
||||||
|
@DoNotInline
|
||||||
|
public static void setFrameRate(Surface surface, float frameRate) {
|
||||||
|
int compatibility =
|
||||||
|
frameRate == 0
|
||||||
|
? Surface.FRAME_RATE_COMPATIBILITY_DEFAULT
|
||||||
|
: Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE;
|
||||||
|
try {
|
||||||
|
surface.setFrameRate(frameRate, compatibility);
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
Log.e(TAG, "Failed to call Surface.setFrameRate", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Helper for listening to changes to the default display. */
|
/** Helper for listening to changes to the default display. */
|
||||||
private interface DisplayHelper {
|
private interface DisplayHelper {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user