Selected changes from the master branch

Pull in some changes from the master branch.  It omits a couple:
* Per #460 it doesn't include the changes to sprite scaling  (fe1460ff3f7d9f2a5290b09ca4c3c83dbd015ed7)
* Due to conflicts and my own concerns, it doesn't include the changes to the dirty rectangle merge algorithm: (9f8d25ead8049d840564d5abb5d943a5df9687cb  a3cc79b71964354e2a4e33024b411dbc05fd4f7f)

I cherry-picked the commits I wanted from the master branch, so I guess some history is lost?  Very open to alternate approaches here.