Проблема при рисовании на Textureview на Huawei P20 - PullRequest
1 голос
/ 03 июня 2019

У меня очень простое приложение с текстурным представлением и кодом визуализации, которое рисует красные пиксели на текстурном виде. Это работает, как и ожидалось, на всех тестовых устройствах, кроме Huawei P20. Может ли это быть связано с тем, как оборудование справляется с этим? Любая помощь, чтобы указать мне правильное направление, чтобы найти обходной путь, приветствуется.

Ниже вы можете увидеть ожидаемые результаты (слева) и результаты на P20 (справа):

enter image description here

Вот код в моей деятельности:

class MainActivity : AppCompatActivity() {

    private val handlerThread = HandlerThread("processing").also { it.start() }
    private val handler = Handler(handlerThread.looper)
    private lateinit var runnable: Runnable

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val textureView = findViewById<TextureView>(R.id.textureView)
        if(textureView.isAvailable) {
            start(textureView.width, textureView.height)
        } else {
            textureView.surfaceTextureListener = object : TextureView.SurfaceTextureListener {
                override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {
                    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
                }

                override fun onSurfaceTextureUpdated(surface: SurfaceTexture?) {
                }

                override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?): Boolean {
                    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
                }

                override fun onSurfaceTextureAvailable(surface: SurfaceTexture?, width: Int, height: Int) {
                    start(width, height)
                }
            }
        }
    }

    private fun start(width: Int, height: Int) {
        val rsContext = RenderScript.create(this, RenderScript.ContextType.DEBUG)
        val script = ScriptC_script(rsContext)
        val outputAllocation = Allocation.createTyped(
            rsContext,
            Type.Builder(rsContext, Element.RGBA_8888(rsContext)).apply {
                setX(width)
                setY(height)
            }.create(),
            Allocation.USAGE_IO_OUTPUT or Allocation.USAGE_SCRIPT
        )

        outputAllocation.surface = Surface(textureView.surfaceTexture)

        runnable = Runnable {
            script.forEach_drawRed(outputAllocation)
            outputAllocation.ioSend()
            handler.postDelayed(runnable, 100)
        }

        handler.post(runnable)
    }

    override fun onStop() {
        handler.removeCallbacks(runnable)
        handlerThread.quit()
        super.onStop()
    }
}

А вот код рендеринга:

#pragma version(1)
#pragma rs java_package_name(com.example.myapplication)
#pragma rs_fp_relaxed

uchar4  __attribute__((kernel)) drawRed(uint32_t x, uint32_t y) {
    uchar4 pixel;
    pixel.r = 255;
    pixel.g = 0;
    pixel.b = 0;
    pixel.a = 255;
    return pixel;
}
...