Modify SurfaceTest to only test readbacks from supported surfaces.

Dawn: support readbacks in caps only from Texture-based surfaces.
Change-Id: I3681b9418f592d9c511931cb422f0f8fb113ff73
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291973
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 1fd4a5a..7c3924d 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -21,6 +21,7 @@
 #include "src/gpu/GrGpu.h"
 #include "src/gpu/GrGpuResourcePriv.h"
 #include "src/gpu/GrImageInfo.h"
+#include "src/gpu/GrRenderTarget.h"
 #include "src/gpu/GrRenderTargetContext.h"
 #include "src/gpu/GrResourceProvider.h"
 #include "src/gpu/SkGpuDevice.h"
@@ -727,6 +728,16 @@
     return surface;
 }
 
+static bool supports_readpixels(const GrCaps* caps, SkSurface* surface) {
+    auto surfaceGpu = static_cast<SkSurface_Gpu*>(surface);
+    GrRenderTargetContext* context = surfaceGpu->getDevice()->accessRenderTargetContext();
+    GrRenderTarget* rt = context->accessRenderTarget();
+    if (!rt) {
+        return false;
+    }
+    return caps->surfaceSupportsReadPixels(rt) == GrCaps::SurfaceReadPixelsSupport::kSupported;
+}
+
 static sk_sp<SkSurface> create_gpu_surface_backend_texture_as_render_target(
     GrContext* ctx, int sampleCnt, const SkColor4f& color, GrBackendTexture* outTexture) {
 
@@ -897,6 +908,10 @@
         // This works only for non-multisampled case.
         GrBackendTexture backendTex;
         auto surface = surfaceFunc(context, 1, kOrigColor, &backendTex);
+        const GrCaps* caps = context->priv().caps();
+        if (!supports_readpixels(caps, surface.get())) {
+            continue;
+        }
         if (surface) {
             test_surface_draw_partially(reporter, surface, kOrigColor.toSkColor());
             surface.reset();