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/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
index 80c13a5..3198247 100644
--- a/tools/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -309,9 +309,7 @@
         auto restore = testCtx->makeCurrentAndAutoRestore();
         // CONTEXT TODO: makeGrContext should return an sk_sp<GrDirectContext>
         auto tmp = testCtx->makeGrContext(grOptions);
-        if (tmp) {
-            grCtx = sk_ref_sp<GrDirectContext>(tmp->asDirectContext());
-        }
+        grCtx = sk_ref_sp(GrAsDirectContext(tmp.get()));
     }
     if (!grCtx.get()) {
         return ContextInfo();