libhwcomposer: Make Rect utils generic.

Changes rect utility functions more generic.
Adds more sanity checks.

Change-Id: Ie935302592ac8eb5f7cfaffe03ac49da077a290d
(cherry picked from commit 77dab03bc671c6d4a46497eaecc594d17a4aee76)