cherry-picked from v4 version biggest difference is formatting some type changes due to use of typedefs (ie struct canvas -> Canvas) Bug: #37206