Android Canvas SurfaceView -


i'm wondering 1 specific behavior drawing screen using surfaceview , canvas.

when i'm locking canvas manipulating pixels of screen in surfaceview, there 1 thing need do: overdraw previous pixels of canvas e.g. color black or so.

now happened me forgot , previous drawings visible in current frames.

furthermore each layer drawn again , again if there not one(or 2 because on android drawings tripple buffered) buffer there generated more buffers , pixel data seems loaded out them layer layer.

so drawings not overdrawn drawn layer layer mentioned. beside fact looks animated , not going "vsync" (refreshrate) of display plus leaving me wondering performance issues, fact annoys me because can't figure out why pixels set desperately.

it should this:

i draw circle @ x,y on first frame on 2nd draw circle @ x+1,y+1

now there 2 circles on canvas because haven't overwritten first frames pixels

now going on , drawing circle each frame @ position....

now lets assume on frame 1234th

it seems if every circle drawn separately starts draw @ time surfaceflinger comes , want buffer displaying catches 1 of backbuffers not ready drawing 1234 circles , displays it

(i hope understand mean when drawings animated)

he showing screen in different drawing states

why this?

a full description of various mechanisms can found in android graphics architecture document.

the surface double-buffered, can triple-buffered. if it's double-buffered, , draw 1000 circles, 1 buffer have of even-numbered circles, , 1 buffer have of odd-numbered circles. if it's triple-buffered, 1 buffer have circles 0, 3, 6, ..., have circles 1, 4, 7, ..., , on. every time draw, cycles next buffer, see circles "vibrate" or "animate" every time draw screen.

this behavior not guaranteed -- number of buffers not fixed, , there's no assurance given buffer continue used after swapped out -- wouldn't want rely on this.

if don't want clear screen each time, can specify "dirty" rect, , draw in area. system can reject dirty rect , replace larger one, should happen on first ever draw cycle (since there's no previous pixel data preserve).


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -