*Takes a puff*
I wonder if birds evolved the ability to fly from the ground or from the trees? Did they glide and then fly or fly and then glide?
I can sort of answer that. Those are, indeed, the two competing theories. Phylogenetic evidence based on the last amazing decade of dinobird discoveries in China have shown that it's a little bit of both but mostly the latter. There's some evidence to suggest that maniraptor theropods were at least competantly arboreal. They certainly had the anatomical prerequesits for flight: small size, elongate feathers, near-avian metabolism, recurved claws (for climbin'), medially-facing glenoids and a large range of motion in the shoulder and wrists (oh, and medially-oriented palms).
If you're familiar with Kevin Dial's well-supported WAIR hypothesis, that's basically a good stepping-stone to flight. Animals who are already somewhat arboreal being using their arms and elongate feathers to create lift while running up trees and/or parachuting down from them (or between trees). But flight certainly didn't evolve in a wholly terrestrial setting--that's certainly not how it worked for bats or pterosaurs, who both came from highly arboreal gliding ancestors.*
Birds did a little bit of both, and their non-avian dinosaurian ancestors had a lot of the necessary equipment already. They just co-opted it for flight later on.
*Pterosaur origins are pretty mysterious, actually. It's pretty obvious that their immediate non-flying ancestors must have been gliders, but exactly WHO that ancestor is we can't say. Aside from telling you that pterosaurs are ornithodiran archosaurs closely related to dinosauriformes, it's pretty unclear. The most basal pterosaurs known(Dimorphodon and Preondactylus) are already fully capable of powered flight.