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>
This commit is contained in:
Stephen White 2020-05-26 17:00:32 -04:00 committed by Skia Commit-Bot
parent 5d7759e1f4
commit fdba6c8b76
3 changed files with 23 additions and 3 deletions

View File

@ -88,6 +88,13 @@ bool GrDawnCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFo
return isFormatRenderable(format, sampleCount);
}
GrCaps::SurfaceReadPixelsSupport GrDawnCaps::surfaceSupportsReadPixels(
const GrSurface* surface) const {
// We currently support readbacks only from Textures and TextureRenderTargets.
return surface->asTexture() ? SurfaceReadPixelsSupport::kSupported
: SurfaceReadPixelsSupport::kUnsupported;
}
size_t GrDawnCaps::bytesPerPixel(const GrBackendFormat& backendFormat) const {
wgpu::TextureFormat dawnFormat;
if (!backendFormat.asDawnFormat(&dawnFormat)) {

View File

@ -36,9 +36,7 @@ public:
return {surfaceColorType, GrColorTypeBytesPerPixel(surfaceColorType)};
}
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override {
return SurfaceReadPixelsSupport::kSupported;
}
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override;
size_t bytesPerPixel(const GrBackendFormat&) const override;

View File

@ -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 @@ static sk_sp<SkSurface> create_gpu_surface_backend_texture(
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 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo) {
// 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();