Doh! You've stumbled across a known missing optimization. No promises, but this has been identified as an future optimization.
The dirty details are that the current code has special optimizations for a straight drawBitmap when there is no matrix (other than translate). In addition, there is another optimization for SRC mode with 32bit bitmaps, where the blitter can literally call memcpy, since there is no need to inspect the src pixels for blending. Neither of these optimizations exist (yet) for the bitmapshader code. On Thu, Feb 5, 2009 at 5:41 PM, tomgibara <[email protected]> wrote: > > Romain, Thanks for the explanation. > > > On Feb 5, 10:26 pm, Romain Guy <[email protected]> wrote: >> Tom, >> >> A shader is a per-pixel operation, which lets you apply it to any >> shape, respecting alpha blending as well. As such it is not surprising >> that your first method is faster. >> >> >> >> On Thu, Feb 5, 2009 at 2:08 PM, tomgibara <[email protected]> wrote: >> >> > I'm experimenting with tiling a fullscreen image (480x320px ARGB >> > bitmap) with a square image (160x160px ARGB bitmap). My initial >> > implementation was naive: >> >> > public void render(Canvas canvas) { >> > final int size = tile.getWidth(); >> > final int w = canvas.getWidth(); >> > final int h = canvas.getHeight(); >> > for (int y = 0; y < h; y += size) { >> > for (int x = 0; x < w; x += size) { >> > canvas.drawBitmap(tile, x, y, null); >> > } >> > } >> > } >> >> > Then I remembered that Paint supports a Shader, so I swapped this >> > implementation for something much more satisfying: >> >> > public void render(Canvas canvas) { >> > canvas.drawPaint(paint); >> > } >> >> > Where paint is initialized outside this method with: >> >> > paint = new Paint(); >> > paint.setShader(new BitmapShader(tile, Shader.TileMode.REPEAT, >> > Shader.TileMode.REPEAT)); >> >> > I expected that using a BitmapShader would be competitive with the >> > first implementation and probably slightly faster. But initial >> > benchmarking indicates that the first method is more than twice as >> > fast (almost 3x as fast if PorterDuff.Mode.SRC is used for both). I >> > found that surprising. >> >> > Is there a good reason that the BitmapShader is necessarily much >> > slower, or does it point to a deficiency in its implementation? >> >> -- >> Romain Guy >> Android framework engineer >> [email protected] >> >> Note: please don't send private questions to me, as I don't have time >> to provide private support. All such questions should be posted on >> public forums, where I and others can see and answer them > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

