It's actually both of those things with a bunch more. This is how I've been explained how it works (based on what we do know).
Champion mastery is based on: KDA, CS, damage dealt to champions, damage dealt, your elo (MMR), and a collective pool of other scores played on that champion. So if you perform better on a champion than most other people at your elo, you'll get a higher grade. That also means that the less played a champion is, the easier it is to get a higher grade, but it's also easy to bomb.
Riot said there are a lot of hidden metrics that they won't disclose because "abuse" (that's always their excuse). So nobody really knows EXACTLY, but that short list of what's been confirmed to be factors.