Add a convenience to downcast contexts into GrDirectContext

This pattern of needing a safe downcast will continue to grow as we
add more explicit use of GrDirectContext and it's causing long ternary
operations that span multiple lines.

Change-Id: I9e2ebe5156e4245524a52d7c92ed3a8509e53151
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/300901
Commit-Queue: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/gm/asyncrescaleandread.cpp b/gm/asyncrescaleandread.cpp
index 43e8167..f61ec15 100644
--- a/gm/asyncrescaleandread.cpp
+++ b/gm/asyncrescaleandread.cpp
@@ -133,11 +133,9 @@
                                           bool doYUV420,
                                           SkString* errorMsg,
                                           int pad = 0) {
-    if (doYUV420) {
-        if (!canvas->recordingContext() || !canvas->recordingContext()->asDirectContext()) {
-            errorMsg->printf("YUV420 only supported on direct GPU for now.");
-            return skiagm::DrawResult::kSkip;
-        }
+    if (doYUV420 && !GrAsDirectContext(canvas->recordingContext())) {
+        errorMsg->printf("YUV420 only supported on direct GPU for now.");
+        return skiagm::DrawResult::kSkip;
     }
     if (canvas->imageInfo().colorType() == kUnknown_SkColorType) {
         *errorMsg = "Not supported on recording/vector backends.";