绘制路径和硬件加速 [英] Drawing paths and hardware acceleration

查看:256
本文介绍了绘制路径和硬件加速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我画在我看来,一个相当大的道路,我遇到了一些性能问题。路径是目前32,000个点长,但我的应用程序应扩展到至少128000个。我真的不能做任何事情的路径的大小,因为数据集只是大,我需要能够显示整个路径一次,并允许放大

我使用的是一台Nexus 10运行的是Android 4.2,默认情况下启用了应用程序的硬件加速功能,能够不明确禁用它。

该路径有以下code创建(我省略了一些设置和其他不相关的部分):

  dataPath.moveTo(0,偏移 - (浮点)数据[leftLimit] / scalingFactor);
        的for(int i = leftLimit; I< rightLimit ++我){
            X =(I  -  leftLimit)* DX;
            Y =偏移 - (浮点)数据[I] / scalingFactor;
            dataPath.lineTo(X,Y);
        }
 

然后在的OnDraw()方法得出:

  canvas.drawColor(Color.WHITE);
canvas.drawPath(数据通路,linePaint);
 

我测量需要使用亚行外壳dumpsys gfxinfo 带和不带硬件加速绘制我的观点,和我惊喜的硬件加速慢得多的时间:

随着硬件加速:

没有硬件加速:

硬件加速版本需要每帧左右200-300毫秒的,大部分花费在处理阶段。非加速版需要大约50毫秒,在这个过程阶段2/3的抽奖阶段和1/3。

显然,即使我快没有硬件加速版本仍然太慢实现60帧,或者当我移动到更大的数据集,甚至可以说勉强可用。

这个想法呈现的路径为位图,然后只转换位图以适应屏幕也是有问题的在我的案件。我需要支持在很远的放大到路径,使放大不带路径质量越来越差很多,我将不得不使路径的超大位图(和可能会遇到内存限制和纹理大小限制)。和缩放的时候为止,我将不得不要么创建的路径只有部分新图像,或切换到只呈现路径直接,这可能会导致比帧率延迟较大,如果表现依然相似,我有权现在。

现在什么我不知道是

  • 是画线/路径只是一些GPU的是坏的,而且人们不应该尝试的硬件加速,还是我可能这样做会导致糟糕的表现怎么了?
  • 有什么我可以做得出这样巨大的路径与可接受的性能?
解决方案
  

时的画线/路径只是一些GPU的是坏的和那一个   不应该试图硬件加速,还是我可能做的事情   错误导致的糟糕表现?

路径所使用的CPU始终呈现。当应用程序是硬件加速,这意味着渲染器将使用的CPU为位图先画你的路,然后上载该位图作为纹理到GPU,并最终在屏幕上绘制纹理。

行被完全硬件加速。而不是使用路径我推荐你使用 Canvas.drawLines()在这种情况下。

  

有什么我可以做的画可以接受这样巨大的路径   性能如何?

您应该要么使用 Canvas.drawLines()或自己渲染路径转换为位图您管理。

I'm drawing a rather large path in my view and I'm running into some performance problems. The path is currently 32,000 points long, but my application should scale to at least 128,000 points. I can't really do anything about the size of the path, as the datasets are just that large and I need to be able to display the whole path at once and allow zooming in.

I'm using a Nexus 10 running Android 4.2, which has hardware acceleration enabled by default for applications that don't explicitly disable it.

The path is created with the following code (I omitted some setup and other irrelevant parts):

dataPath.moveTo(0, offset - (float) data[leftLimit]/ scalingFactor);
        for (int i = leftLimit; i < rightLimit; ++i) {
            x = (i - leftLimit) * dx;
            y = offset - (float) data[i]/ scalingFactor;
            dataPath.lineTo(x, y);
        }

And then drawn in the onDraw() method:

canvas.drawColor(Color.WHITE);
canvas.drawPath(dataPath, linePaint);

I measured the time it takes to draw my view using adb shell dumpsys gfxinfo with and without hardware acceleration, and to my suprise the hardware acceleration is much slower:

With hardware acceleration:

Without hardware acceleration:

The hardware accelerated version takes around 200-300 ms per frame, most spent in the Process stage. The non-accelerated version takes around 50 ms, with 2/3 in the Draw stage and 1/3 in the process stage.

Obviously even my faster version without hardware acceleration is still too slow to achieve 60 fps, or to be even barely useable when I move to larger datasets.

The idea to render the path to a bitmap and then only transform that bitmap to fit the screen is also problematic in my case. I need to support zooming in very far onto the path, and to enable zooming in without the path quality getting much worse I would have to render oversized bitmaps of the path (and would likely run into memory limits and the texture size limits). And when zooming in far I would have to either create newer images of only parts of the path, or switch to just rendering the path directly, which likely would lead to delays greater than the framerate if the performance is still similar to what I have right now.

What I'm wondering now is

  • Is drawing lines/paths just something the GPU is bad at and that one should not try to hardware accelerate, or am I likely doing something wrong that causes the bad performance?
  • Is there anything I can do to draw such huge paths with acceptable performance?

解决方案

Is drawing lines/paths just something the GPU is bad at and that one should not try to hardware accelerate, or am I likely doing something wrong that causes the bad performance?

Paths are always rendered using the CPU. When the app is hardware accelerated this means the renderer will first draw your path using the CPU into a bitmap, then upload that bitmap as a texture to the GPU and finally draw the texture on screen.

Lines are entirely hardware accelerated. Instead of using a Path I recommend you use Canvas.drawLines() in this case.

Is there anything I can do to draw such huge paths with acceptable performance?

You should either use Canvas.drawLines() or render the path yourself into a Bitmap that you manage.

这篇关于绘制路径和硬件加速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆