pull fixes for viewport-related code from base
Merge pull request #1247 from hwhw/master

pull fixes for viewport-related code from base