Updated with viewport checks.

Change-Id: I6962d0454d5c7ef08a87ef8b28f62ea8805f9ae9