1 /* 2 * Copyright 2019 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrDawnCaps_DEFINED 9 #define GrDawnCaps_DEFINED 10 11 #include "include/gpu/GrBackendSurface.h" 12 #include "include/gpu/GrContextOptions.h" 13 #include "src/gpu/ganesh/GrCaps.h" 14 #include "src/gpu/ganesh/dawn/GrDawnUtil.h" 15 16 class GrDawnCaps : public GrCaps { 17 public: 18 GrDawnCaps(const GrContextOptions& contextOptions); 19 20 bool isFormatSRGB(const GrBackendFormat&) const override; 21 22 bool isFormatRenderable(const GrBackendFormat& format, 23 int sampleCount = 1) const override; 24 bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, 25 int sampleCount = 1) const override; 26 27 isFormatCopyable(const GrBackendFormat & format)28 bool isFormatCopyable(const GrBackendFormat& format) const override { return true; } 29 30 bool isFormatTexturable(const GrBackendFormat& format, GrTextureType) const override; 31 supportedWritePixelsColorType(GrColorType surfaceColorType,const GrBackendFormat & surfaceFormat,GrColorType srcColorType)32 SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, 33 const GrBackendFormat& surfaceFormat, 34 GrColorType srcColorType) const override { 35 return {surfaceColorType, GrColorTypeBytesPerPixel(surfaceColorType)}; 36 } 37 38 SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override; 39 40 int getRenderTargetSampleCount(int requestedCount, 41 const GrBackendFormat&) const override; 42 43 int maxRenderTargetSampleCount(const GrBackendFormat& format) const override; 44 45 GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override; 46 47 skgpu::Swizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const override; 48 49 uint64_t computeFormatKey(const GrBackendFormat&) const override; 50 51 GrProgramDesc makeDesc(GrRenderTarget*, 52 const GrProgramInfo&, 53 ProgramDescOverrideFlags) const override; 54 55 #if GR_TEST_UTILS 56 std::vector<GrTest::TestFormatColorTypeCombination> getTestingCombinations() const override; 57 #endif 58 59 private: 60 bool onSurfaceSupportsWritePixels(const GrSurface* surface) const override; onCanCopySurface(const GrSurfaceProxy * dst,const SkIRect & dstRect,const GrSurfaceProxy * src,const SkIRect & srcRect)61 bool onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect, 62 const GrSurfaceProxy* src, const SkIRect& srcRect) const override { 63 // Dawn does not support scaling copies 64 return srcRect.size() == dstRect.size(); 65 } 66 GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override; 67 68 bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override; 69 onSupportedReadPixelsColorType(GrColorType srcColorType,const GrBackendFormat & backendFormat,GrColorType dstColorType)70 SupportedRead onSupportedReadPixelsColorType(GrColorType srcColorType, 71 const GrBackendFormat& backendFormat, 72 GrColorType dstColorType) const override { 73 return { srcColorType, GrColorTypeBytesPerPixel(srcColorType) }; 74 } 75 76 skgpu::Swizzle onGetReadSwizzle(const GrBackendFormat&, GrColorType) const override; 77 78 using INHERITED = GrCaps; 79 }; 80 81 #endif 82