Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Hardware Layer in Custom View onDraw
    primarykey
    data
    text
    <p>So I'm trying to understand how I can properly use hardware acceleration (when available) in a custom <code>View</code> that is persistently animating. This is the basic premise of my <code>onDraw()</code>:</p> <pre><code>canvas.drawColor(mBackgroundColor); for (Layer layer : mLayers) { canvas.save(); canvas.translate(layer.x, layer.y); //Draw that number of images in a grid, offset by -1 for (int i = -1; i &lt; layer.xCount - 1; i++) { for (int j = -1; j &lt; layer.yCount - 1; j++) { canvas.drawBitmap(layer.bitmap, layer.w * i, layer.h * j, null); } } //If the layer's x has moved past its width, reset back to a seamless position layer.x += ((difference * layer.xSpeed) / 1000f); float xOverlap = layer.x % layer.w; if (xOverlap &gt; 0) { layer.x = xOverlap; } //If the layer's y has moved past its height, reset back to a seamless position layer.y += ((difference * layer.ySpeed) / 1000f); float yOverlap = layer.y % layer.h; if (yOverlap &gt; 0) { layer.y = yOverlap; } canvas.restore(); } //Redraw the view ViewCompat.postInvalidateOnAnimation(this); </code></pre> <p>I'm enabling hardware layers in <code>onAttachedToWindow()</code> and disabling them in <code>onDetachedFromWindow()</code>, but I'm trying to understand whether or not I'm actually using it. Essentially, the <code>i/j</code> loop that calls <code>drawBitmap()</code> never changes; the only thing that changes is the <code>Canvas</code> translation. Is the <code>Bitmap</code> automatically saved to the GPU as a texture behind the scenes, or is there something I need to do manually to do so?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload