gpt4 book ai didi

android - 尝试在主线程之外初始化硬件加速,中止

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:06 27 4
gpt4 key购买 nike

有人知道为什么我会在 LogCat 中收到此警告吗?

01-18 01:18:17.475: W/HardwareRenderer(25992): Attempting to initialize hardware acceleration outside of the main thread, aborting

我在主 Activity (主线程)中使用我的 WebView 执行此操作:

wv = (WebView) findViewById(R.id.main_webview);
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);

我的 list 中有这个:

<activity
android:name=".Main"
android:hardwareAccelerated="true"
android:label="@string/title_activity_main" >

最佳答案

以下是硬件加速在 Android 中的工作原理:

private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) {
mAttachInfo.mHardwareAccelerated = false;
mAttachInfo.mHardwareAccelerationRequested = false;

// Don't enable hardware acceleration when the application is in compatibility mode
if (mTranslator != null) return;

// Try to enable hardware acceleration if requested
final boolean hardwareAccelerated =
(attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;

if (hardwareAccelerated) {
if (!HardwareRenderer.isAvailable()) {
return;
}

// Persistent processes (including the system) should not do
// accelerated rendering on low-end devices. In that case,
// sRendererDisabled will be set. In addition, the system process
// itself should never do accelerated rendering. In that case, both
// sRendererDisabled and sSystemRendererDisabled are set. When
// sSystemRendererDisabled is set, PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED
// can be used by code on the system process to escape that and enable
// HW accelerated drawing. (This is basically for the lock screen.)

final boolean fakeHwAccelerated = (attrs.privateFlags &
WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED) != 0;
final boolean forceHwAccelerated = (attrs.privateFlags &
WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED) != 0;

if (!HardwareRenderer.sRendererDisabled || (HardwareRenderer.sSystemRendererDisabled
&& forceHwAccelerated)) {
// Don't enable hardware acceleration when we're not on the main thread
if (!HardwareRenderer.sSystemRendererDisabled
&& Looper.getMainLooper() != Looper.myLooper()) {
Log.w(HardwareRenderer.LOG_TAG, "Attempting to initialize hardware "
+ "acceleration outside of the main thread, aborting");
return;
}

final boolean translucent = attrs.format != PixelFormat.OPAQUE;
if (mAttachInfo.mHardwareRenderer != null) {
mAttachInfo.mHardwareRenderer.destroy(true);
}
mAttachInfo.mHardwareRenderer = HardwareRenderer.createGlRenderer(2, translucent);
mAttachInfo.mHardwareAccelerated = mAttachInfo.mHardwareAccelerationRequested
= mAttachInfo.mHardwareRenderer != null;
} else if (fakeHwAccelerated) {
// The window had wanted to use hardware acceleration, but this
// is not allowed in its process. By setting this flag, it can
// still render as if it was accelerated. This is basically for
// the preview windows the window manager shows for launching
// applications, so they will look more like the app being launched.
mAttachInfo.mHardwareAccelerationRequested = true;
}
}
}

从那里,您可以看到您获得的日志是在主线程之外请求硬件加速时(如日志所述)。

在您的情况下,您必须更深入地了解您的代码并查看所有非主线程,其中一个称为硬件加速。

如果没有更多详细信息(一些代码等),我无法为您提供帮助。

关于android - 尝试在主线程之外初始化硬件加速,中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14393516/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com