Подтвердить что ты не робот

Попытка инициализировать аппаратное ускорение вне основного потока, прервать

Есть ли у кого-нибудь представление о том, почему я получаю это предупреждение в 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" >
4b9b3361

Ответ 1

Вот как работает аппаратное ускорение в 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;
        }
    }
}

Оттуда вы увидите, что журнал, который вы получаете, - это когда аппаратное ускорение запрашивается вне основного потока (как говорит журнал).

В вашем случае вам нужно углубиться в свой код и увидеть все не основные потоки, которые вызываются аппаратным ускорением.

Я не могу помочь вам без каких-либо подробностей (некоторый код и т.д.).

Ответ 2

Как в документации

setRenderPriority

следует вызывать только один раз за процесс.

Устанавливает приоритет потока Render. В отличие от других настроек, это нужно только один раз на процесс. Значение по умолчанию НОРМАЛЬНО.

Возможная душа для вашей проблемы

  • Будет удаление websetting.setRenderPriority.
  • Будет ли доступ к другому потоку, который вы не использовали в приведенном выше коде, аппаратное обеспечение

Ответ 3

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

Ответ 4

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);

        }
    });