In the US, at least, the law is reasonably clear. Child pornography, which is unlawful, is defined as
any visual depiction of sexually explicit conduct involving a minor
Sexually explicit conduct is in turn defined as
sexual intercourse, including genital-genital, oral-genital, anal-genital, or oral-anal, whether between persons of the same or opposite sex as well as bestiality, masturbation, sadistic or masochistic abuse, and the lascivious exhibition of the genitals or pubic area of any person.
But the action has to actually be shown. A boy looking down, moving his arm rhythmically, would not count.
Separately, a work could be be prosecuted as obscene if
the average person, applying contemporary community standards would find that the work, taken as a whole, appeals to the prurient interest; the work depicts or describes, in a patently offensive way, sexual conduct specifically defined by the applicable state law; and the work, taken as a whole, lacks serious literary, artistic, political, or scientific value.