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

时间:2013-01-18 06:26:55

标签: android

有没有人对我在LogCat中收到此警告的原因有任何见解?

  

01-18 01:18:17.475:W / HardwareRenderer(25992):试图   初始化主线程外的硬件加速,中止

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

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

我的清单中有这个:

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

4 个答案:

答案 0 :(得分:2)

以下是硬件加速在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;
        }
    }
}

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

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

如果没有更多细节(某些代码等),我无法帮助你。

答案 1 :(得分:0)

按照文件

  

setRenderPriority

每个进程只能调用一次。

  

设置渲染线程的优先级。与其他设置不同,   这个只需要每个进程调用一次。默认值   是正常的。

你的问题的可能灵魂

  • 将删除websetting.setRenderPriority。
  • 您在上述代码中未共享的另一个帖子是否会访问 硬件

答案 2 :(得分:-1)

webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);

答案 3 :(得分:-1)

LinearLayout.LayoutParams dfparams = new LinearLayout.LayoutParams(0, 0, 0);
    webview.setLayoutParams(dfparams);
    webview.loadDataWithBaseURL("url", content, "text/html", "utf-8", null);

    webview.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0);
            webview.setLayoutParams(params);

        }
    });