Efficient onDraw with bitmaps and hardware acceleration of complex clipping

I am looking for advice on the optimal rendering (and possibly caching) of animated content, the nature of which is determined at runtime and cannot be pre-computed.

I am developing my first Android application and have decided (currently) a β€œtoy” project that accepts relatively short alphanumeric codes and converts them into images and animations. (The SourceForge project is at http://sourceforge.net/projects/picturecode , and the project document is at https://docs.google.com/file/d/0B-yO-2scTVuRSkk2NDdiZ3YzTDg/edit?usp=sharing )

I am at the point where I am developing operations for embedding predefined and user-defined codes in other codes to make even more complex images with even shorter codes. I am also trying to develop related operations that will help similarly complex but interesting images with a relatively simple presentation of the code.

Thus, one of the operations that I thought would be useful is the ability to use a predefined or user-defined code as a mask to clip other drawing operations. I managed to get this working after I discovered that clipPath is not supported in hardware accelerated views and made the view be software-based. (My renderer checks to see if we are in a mode that defines a "clipping path" and adds operations to the path instead of drawing them on the canvas, but it was quite tedious and does not support all operations.)

I am considering alternatives for switching to hardware acceleration mode. One of them that comes to mind creates a bitmap ALPHA_888 and a picture for it instead of creating a clipping path when I'm in this clipping mode. One of the advantages of this is probably that it would be easier to support arbitrary operations; I just draw them on this bitmap and not on the main canvas when I'm in clipping mode. Once I have a bitmap, I assume that I can somehow use it with drawBitmap (to another intermediate bitmap) using Paint with the appropriate PorterDuff mode.

I expect that someday I (or anyone else, as the project is located on SourceForge), can reuse this component in a larger project as an easy way to present graphics that can be conveyed in plain text, but in a short / optimized format. I see it as an animated GIF, but it’s easier to create and transfer less.

My questions:

  • How important is hardware acceleration in general? Is this an important feature to save, or should I give it in favor of other functions? (If others will use this feature, I assume that they often want the component to be compatible with hardware acceleration.)
  • Does it mask a strong / important operation, or is there something better that I could use instead (for example, a clean filter filtered using a porter-duff right on the canvas)?
  • I think of the right way to implement complex disguise?

Finally, :

  • How to use and manage bitmaps, if at all (e.g. mask bitmap)? When I started the project, I noticed that it is not recommended to select any new objects during OnDraw. So I pre-selected everything I could - Paint, PointF, RectF, Path and some others so that I could use them during onDraw. At the moment, I'm still drawing directly on the canvas, but I wonder if I should display some kind of buffer, such as a bitmap, in a separate stream, and then just draw a buffer on the screen during onDraw. Will this affect the goal of hardware acceleration (and is it not necessary to disable hardware acceleration in the view at all)? And more importantly, how / when can I safely distribute these bitmaps without offensive villi and experienced Android developers who know that memory allocation during onDraw is bad? If I select a raster image in a separate drawing stream, I may need to select it once for each frame of each included / embedded image, because these images can be animations. Or, I just want to highlight a bitmap for the current frame to help crop or fit multiple fragments of the image.

It is difficult to narrow this down to a very specific question. What I have is somewhere between a mess of questions and asking for general advice about opportunities or ideas that I may not even know about. I am relatively new to Java and Android, but I am very familiar with C #, 2D graphics, and game development. Can my questions point to any obvious discoveries in my understanding of how 2D animation should work on Android?

+4
source share
1 answer

After reading an article on Android hardware acceleration , I came across a link to saveLayer functions on Canvas, which, I believe, are exact pieces that I was not here.

Update: I confirmed that saveLayer is what I need. Instead of applying a complex clipping region based on the path and then drawing into it, I call saveLayer to create an off-screen buffer into which to draw, draw a single image, switch Xfermode to SRC_IN, and then draw a second image. This gives the intersection of two images, the second image being visible content. When I invoke recovery, I essentially get a second image clipped with the contents of the first image, which is better than what I tried to accomplish in the first place.

0
source

All Articles