diff --git a/gm/runtimeintrinsics.cpp b/gm/runtimeintrinsics.cpp index 5eb96b6c8a..180c1ede6f 100644 --- a/gm/runtimeintrinsics.cpp +++ b/gm/runtimeintrinsics.cpp @@ -206,8 +206,8 @@ DEF_SIMPLE_GPU_GM_CAN_FAIL(runtime_intrinsics_trig_es3, ctx, canvas, errorMsg, columns_to_width(3), rows_to_height(2)) { - if (!ctx->priv().caps()->shaderCaps()->supportsSkSLES3()) { - *errorMsg = "SkSL ES3 is not supported."; + if (ctx->priv().caps()->shaderCaps()->supportedSkSLVerion() < SkSL::Version::k300) { + *errorMsg = "SkSL 300 is not supported."; return skiagm::DrawResult::kSkip; } @@ -317,8 +317,8 @@ DEF_SIMPLE_GPU_GM_CAN_FAIL(runtime_intrinsics_common_es3, ctx, canvas, errorMsg, columns_to_width(6), rows_to_height(5)) { - if (!ctx->priv().caps()->shaderCaps()->supportsSkSLES3()) { - *errorMsg = "SkSL ES3 is not supported."; + if (ctx->priv().caps()->shaderCaps()->supportedSkSLVerion() < SkSL::Version::k300) { + *errorMsg = "SkSL 300 is not supported."; return skiagm::DrawResult::kSkip; } diff --git a/gn/core.gni b/gn/core.gni index 762b4f303f..009de9685a 100644 --- a/gn/core.gni +++ b/gn/core.gni @@ -14,6 +14,7 @@ skia_core_public = [ "$_include/core/SkBlender.h", "$_include/core/SkBlendMode.h", "$_include/core/SkBlurTypes.h", + "$_include/core/SkCapabilities.h", "$_include/core/SkCanvas.h", "$_include/core/SkCanvasVirtualEnforcer.h", "$_include/core/SkClipOp.h", @@ -148,6 +149,7 @@ skia_core_sources = [ "$_src/core/SkCanvas.cpp", "$_src/core/SkCanvasPriv.cpp", "$_src/core/SkCanvasPriv.h", + "$_src/core/SkCapabilities.cpp", "$_src/core/SkChromeRemoteGlyphCache.cpp", "$_src/core/SkClipStack.cpp", "$_src/core/SkClipStack.h", diff --git a/gn/sksl.gni b/gn/sksl.gni index b9b1c360d1..adce342200 100644 --- a/gn/sksl.gni +++ b/gn/sksl.gni @@ -36,6 +36,7 @@ skia_sksl_sources = [ "$_include/sksl/SkSLErrorReporter.h", "$_include/sksl/SkSLOperator.h", "$_include/sksl/SkSLPosition.h", + "$_include/sksl/SkSLVersion.h", "$_src/sksl/SkSLAnalysis.cpp", "$_src/sksl/SkSLAnalysis.h", "$_src/sksl/SkSLBuiltinMap.cpp", diff --git a/include/core/BUILD.bazel b/include/core/BUILD.bazel index aea2a8743c..f845e8a53c 100644 --- a/include/core/BUILD.bazel +++ b/include/core/BUILD.bazel @@ -970,3 +970,13 @@ generated_cc_atom( ":SkTypes_hdr", ], ) + +generated_cc_atom( + name = "SkCapabilities_hdr", + hdrs = ["SkCapabilities.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":SkRefCnt_hdr", + "//include/sksl:SkSLVersion_hdr", + ], +) diff --git a/include/core/SkCapabilities.h b/include/core/SkCapabilities.h new file mode 100644 index 0000000000..9f8b3402a6 --- /dev/null +++ b/include/core/SkCapabilities.h @@ -0,0 +1,31 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkCapabilities_DEFINED +#define SkCapabilities_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/sksl/SkSLVersion.h" + +namespace skgpu::graphite { class Caps; } + +class SK_API SkCapabilities : public SkNVRefCnt { +public: + static sk_sp RasterBackend(); + + SkSL::Version skslVersion() const { return fSkSLVersion; } + +private: + SkCapabilities() = default; + + SkSL::Version fSkSLVersion = SkSL::Version::k100; + + friend class GrCaps; + friend class skgpu::graphite::Caps; +}; + +#endif diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index 1e9b594fb6..65c0567fe7 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -26,6 +26,7 @@ #endif class SkCanvas; +class SkCapabilities; class SkDeferredDisplayList; class SkPaint; class SkSurfaceCharacterization; @@ -600,6 +601,12 @@ public: */ SkCanvas* getCanvas(); + /** Returns SkCapabilities that describes the capabilities of the SkSurface's device. + + @return SkCapabilities of SkSurface's device. + */ + sk_sp capabilities(); + /** Returns a compatible SkSurface, or nullptr. Returned SkSurface contains the same raster, GPU, or null properties as the original. Returned SkSurface does not share the same pixels. diff --git a/include/gpu/GrRecordingContext.h b/include/gpu/GrRecordingContext.h index 8b8b4fe5ba..8370a47646 100644 --- a/include/gpu/GrRecordingContext.h +++ b/include/gpu/GrRecordingContext.h @@ -30,6 +30,7 @@ class GrSurfaceProxy; class GrTextBlobRedrawCoordinator; class GrThreadSafeCache; class SkArenaAlloc; +class SkCapabilities; class SkJSONWriter; namespace sktext::gpu { @@ -97,6 +98,8 @@ public: return INHERITED::maxSurfaceSampleCountForColorType(colorType); } + SK_API sk_sp skCapabilities() const; + // Provides access to functions that aren't part of the public API. GrRecordingContextPriv priv(); const GrRecordingContextPriv priv() const; // NOLINT(readability-const-return-type) diff --git a/include/sksl/BUILD.bazel b/include/sksl/BUILD.bazel index 2983718011..02ac8d6544 100644 --- a/include/sksl/BUILD.bazel +++ b/include/sksl/BUILD.bazel @@ -191,3 +191,9 @@ generated_cc_atom( hdrs = ["SkSLOperator.h"], visibility = ["//:__subpackages__"], ) + +generated_cc_atom( + name = "SkSLVersion_hdr", + hdrs = ["SkSLVersion.h"], + visibility = ["//:__subpackages__"], +) diff --git a/include/sksl/SkSLVersion.h b/include/sksl/SkSLVersion.h new file mode 100644 index 0000000000..ad059d580e --- /dev/null +++ b/include/sksl/SkSLVersion.h @@ -0,0 +1,27 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkSLVersion_DEFINED +#define SkSLVersion_DEFINED + +namespace SkSL { + +enum class Version { + /** + * Desktop GLSL 1.10, GLSL ES 1.00, WebGL 1.0 + */ + k100, + + /** + * Desktop GLSL 3.30, GLSL ES 3.00, WebGL 2.0 + */ + k300, +}; + +} // namespace SkSL + +#endif diff --git a/src/core/BUILD.bazel b/src/core/BUILD.bazel index 676e23b720..462aa77aa3 100644 --- a/src/core/BUILD.bazel +++ b/src/core/BUILD.bazel @@ -36,6 +36,7 @@ cc_library( ":SkCachedData_src", ":SkCanvasPriv_src", ":SkCanvas_src", + ":SkCapabilities_src", ":SkChromeRemoteGlyphCache_src", ":SkClipStackDevice_src", ":SkClipStack_src", @@ -5771,3 +5772,10 @@ generated_cc_atom( visibility = ["//:__subpackages__"], deps = ["//include/core:SkTypes_hdr"], ) + +generated_cc_atom( + name = "SkCapabilities_src", + srcs = ["SkCapabilities.cpp"], + visibility = ["//:__subpackages__"], + deps = ["//include/core:SkCapabilities_hdr"], +) diff --git a/src/core/SkCapabilities.cpp b/src/core/SkCapabilities.cpp new file mode 100644 index 0000000000..4a329fd80e --- /dev/null +++ b/src/core/SkCapabilities.cpp @@ -0,0 +1,18 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "include/core/SkCapabilities.h" + +sk_sp SkCapabilities::RasterBackend() { + static SkCapabilities* sCaps = [](){ + SkCapabilities* caps = new SkCapabilities; + caps->fSkSLVersion = SkSL::Version::k100; + return caps; + }(); + + return sk_ref_sp(sCaps); +} diff --git a/src/gpu/ganesh/BUILD.bazel b/src/gpu/ganesh/BUILD.bazel index 55a361c947..a6fdd040cb 100644 --- a/src/gpu/ganesh/BUILD.bazel +++ b/src/gpu/ganesh/BUILD.bazel @@ -741,6 +741,7 @@ generated_cc_atom( ":GrSamplerState_hdr", ":GrShaderCaps_hdr", ":GrSurfaceProxy_hdr", + "//include/core:SkCapabilities_hdr", "//include/core:SkImageInfo_hdr", "//include/core:SkRefCnt_hdr", "//include/core:SkString_hdr", @@ -764,6 +765,7 @@ generated_cc_atom( ":GrSurface_hdr", ":GrTestUtils_hdr", ":GrWindowRectangles_hdr", + "//include/core:SkCapabilities_hdr", "//include/gpu:GrBackendSurface_hdr", "//include/gpu:GrContextOptions_hdr", "//include/private/gpu/ganesh:GrTypesPriv_hdr", @@ -2205,6 +2207,7 @@ generated_cc_atom( ":GrRecordingContextPriv_hdr", ":SkGr_hdr", ":SurfaceContext_hdr", + "//include/core:SkCapabilities_hdr", "//include/gpu:GrContextThreadSafeProxy_hdr", "//include/gpu:GrRecordingContext_hdr", "//src/core:SkArenaAlloc_hdr", diff --git a/src/gpu/ganesh/GrCaps.cpp b/src/gpu/ganesh/GrCaps.cpp index 9ffb75fe1d..e27050fcad 100644 --- a/src/gpu/ganesh/GrCaps.cpp +++ b/src/gpu/ganesh/GrCaps.cpp @@ -7,6 +7,7 @@ #include "src/gpu/ganesh/GrCaps.h" +#include "include/core/SkCapabilities.h" #include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrContextOptions.h" #include "include/private/gpu/ganesh/GrTypesPriv.h" @@ -103,6 +104,9 @@ void GrCaps::finishInitialization(const GrContextOptions& options) { // Our render targets are always created with textures as the color attachment, hence this min: fMaxRenderTargetSize = std::min(fMaxRenderTargetSize, fMaxTextureSize); fMaxPreferredRenderTargetSize = std::min(fMaxPreferredRenderTargetSize, fMaxRenderTargetSize); + + fSkCaps.reset(new SkCapabilities); + fSkCaps->fSkSLVersion = this->shaderCaps()->supportedSkSLVerion(); } void GrCaps::applyOptionsOverrides(const GrContextOptions& options) { @@ -480,3 +484,8 @@ std::tuple GrCaps::getFallbackColorTypeAndFormat( } while (ct != GrColorType::kUnknown); return {GrColorType::kUnknown, {}}; } + +sk_sp GrCaps::asSkCapabilities() const { + SkASSERTF(fSkCaps, "Calling asSkCapabilities before it's initialized"); + return fSkCaps; +} diff --git a/src/gpu/ganesh/GrCaps.h b/src/gpu/ganesh/GrCaps.h index 5ad1749d18..796cd1074f 100644 --- a/src/gpu/ganesh/GrCaps.h +++ b/src/gpu/ganesh/GrCaps.h @@ -8,6 +8,7 @@ #ifndef GrCaps_DEFINED #define GrCaps_DEFINED +#include "include/core/SkCapabilities.h" #include "include/core/SkImageInfo.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" @@ -41,6 +42,7 @@ class GrCaps : public SkRefCnt { public: GrCaps(const GrContextOptions&); + sk_sp asSkCapabilities() const; void dumpJSON(SkJSONWriter*) const; const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); } @@ -525,6 +527,7 @@ protected: virtual bool onSupportsDynamicMSAA(const GrRenderTargetProxy*) const { return false; } std::unique_ptr fShaderCaps; + sk_sp fSkCaps; bool fNPOTTextureTileSupport : 1; bool fMipmapSupport : 1; diff --git a/src/gpu/ganesh/GrRecordingContext.cpp b/src/gpu/ganesh/GrRecordingContext.cpp index 19498020dc..29c82205ee 100644 --- a/src/gpu/ganesh/GrRecordingContext.cpp +++ b/src/gpu/ganesh/GrRecordingContext.cpp @@ -7,6 +7,7 @@ #include "include/gpu/GrRecordingContext.h" +#include "include/core/SkCapabilities.h" #include "include/gpu/GrContextThreadSafeProxy.h" #include "src/core/SkArenaAlloc.h" #include "src/gpu/ganesh/GrAuditTrail.h" @@ -159,6 +160,10 @@ void GrRecordingContext::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlu //////////////////////////////////////////////////////////////////////////////// +sk_sp GrRecordingContext::skCapabilities() const { + return this->caps()->asSkCapabilities(); +} + int GrRecordingContext::maxTextureSize() const { return this->caps()->maxTextureSize(); } int GrRecordingContext::maxRenderTargetSize() const { return this->caps()->maxRenderTargetSize(); } diff --git a/src/gpu/ganesh/GrShaderCaps.h b/src/gpu/ganesh/GrShaderCaps.h index a2347c6fc7..0e0ca57201 100644 --- a/src/gpu/ganesh/GrShaderCaps.h +++ b/src/gpu/ganesh/GrShaderCaps.h @@ -54,14 +54,6 @@ struct GrShaderCaps : SkSL::ShaderCaps { // reduce the number of unique shaders generated. bool reducedShaderMode() const { return fReducedShaderMode; } - /** - * SkSL ES3 requires support for derivatives, nonsquare matrices and bitwise integer operations. - */ - bool supportsSkSLES3() const { - return fShaderDerivativeSupport && fNonsquareMatrixSupport && fIntegerSupport && - fGLSLGeneration >= SkSL::GLSLGeneration::k330; - } - // SkSL only. bool colorSpaceMathNeedsFloat() const { return fColorSpaceMathNeedsFloat; } diff --git a/src/gpu/graphite/BUILD.bazel b/src/gpu/graphite/BUILD.bazel index 1576f90c9e..7cca8e65ae 100644 --- a/src/gpu/graphite/BUILD.bazel +++ b/src/gpu/graphite/BUILD.bazel @@ -44,6 +44,7 @@ generated_cc_atom( visibility = ["//:__subpackages__"], deps = [ ":ResourceTypes_hdr", + "//include/core:SkCapabilities_hdr", "//include/core:SkImageInfo_hdr", "//include/core:SkRefCnt_hdr", "//src/core:SkEnumBitMask_hdr", @@ -58,6 +59,7 @@ generated_cc_atom( visibility = ["//:__subpackages__"], deps = [ ":Caps_hdr", + "//include/core:SkCapabilities_hdr", "//include/gpu/graphite:TextureInfo_hdr", "//src/sksl:SkSLUtil_hdr", ], @@ -673,9 +675,12 @@ generated_cc_atom( srcs = ["Surface_Graphite.cpp"], visibility = ["//:__subpackages__"], deps = [ + ":Caps_hdr", ":Device_hdr", ":Image_Graphite_hdr", + ":RecorderPriv_hdr", ":Surface_Graphite_hdr", + "//include/core:SkCapabilities_hdr", "//include/gpu/graphite:Recorder_hdr", "//include/gpu/graphite:SkStuff_hdr", ], diff --git a/src/gpu/graphite/Caps.cpp b/src/gpu/graphite/Caps.cpp index b128d267ec..e92ca8b8a2 100644 --- a/src/gpu/graphite/Caps.cpp +++ b/src/gpu/graphite/Caps.cpp @@ -7,6 +7,7 @@ #include "src/gpu/graphite/Caps.h" +#include "include/core/SkCapabilities.h" #include "include/gpu/graphite/TextureInfo.h" #include "src/sksl/SkSLUtil.h" @@ -52,4 +53,12 @@ skgpu::Swizzle Caps::getWriteSwizzle(SkColorType ct, const TextureInfo& info) co return colorTypeInfo->fWriteSwizzle; } +sk_sp Caps::asSkCapabilities() const { + if (!fSkCaps) { + fSkCaps.reset(new SkCapabilities); + fSkCaps->fSkSLVersion = this->shaderCaps()->supportedSkSLVerion(); + } + return fSkCaps; +} + } // namespace skgpu::graphite diff --git a/src/gpu/graphite/Caps.h b/src/gpu/graphite/Caps.h index 376d28f26e..5cd00a45a2 100644 --- a/src/gpu/graphite/Caps.h +++ b/src/gpu/graphite/Caps.h @@ -8,6 +8,7 @@ #ifndef skgpu_graphite_Caps_DEFINED #define skgpu_graphite_Caps_DEFINED +#include "include/core/SkCapabilities.h" #include "include/core/SkImageInfo.h" #include "include/core/SkRefCnt.h" #include "src/core/SkEnumBitMask.h" @@ -30,6 +31,7 @@ class Caps : public SkRefCnt { public: ~Caps() override; + sk_sp asSkCapabilities() const; const SkSL::ShaderCaps* shaderCaps() const { return fShaderCaps.get(); } virtual TextureInfo getDefaultSampledTextureInfo(SkColorType, @@ -103,6 +105,7 @@ protected: size_t fRequiredUniformBufferAlignment = 0; std::unique_ptr fShaderCaps; + mutable sk_sp fSkCaps; bool fClampToBorderSupport = true; diff --git a/src/gpu/graphite/Surface_Graphite.cpp b/src/gpu/graphite/Surface_Graphite.cpp index d79034084d..29e4811018 100644 --- a/src/gpu/graphite/Surface_Graphite.cpp +++ b/src/gpu/graphite/Surface_Graphite.cpp @@ -7,10 +7,13 @@ #include "src/gpu/graphite/Surface_Graphite.h" +#include "include/core/SkCapabilities.h" #include "include/gpu/graphite/Recorder.h" #include "include/gpu/graphite/SkStuff.h" +#include "src/gpu/graphite/Caps.h" #include "src/gpu/graphite/Device.h" #include "src/gpu/graphite/Image_Graphite.h" +#include "src/gpu/graphite/RecorderPriv.h" namespace skgpu::graphite { @@ -56,4 +59,8 @@ bool Surface::onReadPixels(Context* context, return fDevice->readPixels(context, recorder, dst, srcX, srcY); } +sk_sp Surface::onCapabilities() { + return fDevice->recorder()->priv().caps()->asSkCapabilities(); +} + } // namespace skgpu::graphite diff --git a/src/gpu/graphite/Surface_Graphite.h b/src/gpu/graphite/Surface_Graphite.h index b1f7b9bfb0..ccc87b4219 100644 --- a/src/gpu/graphite/Surface_Graphite.h +++ b/src/gpu/graphite/Surface_Graphite.h @@ -28,6 +28,7 @@ public: void onWritePixels(const SkPixmap&, int x, int y) override; bool onCopyOnWrite(ContentChangeMode) override; bool onReadPixels(Context*, Recorder*, const SkPixmap& dst, int srcX, int srcY); + sk_sp onCapabilities() override; private: sk_sp fDevice; diff --git a/src/image/BUILD.bazel b/src/image/BUILD.bazel index 6c8eccce80..102e2f72ca 100644 --- a/src/image/BUILD.bazel +++ b/src/image/BUILD.bazel @@ -382,6 +382,7 @@ generated_cc_atom( ":SkSurface_Base_hdr", ":SkSurface_Gpu_hdr", "//include/core:SkCanvas_hdr", + "//include/core:SkCapabilities_hdr", "//include/core:SkDeferredDisplayList_hdr", "//include/core:SkSurfaceCharacterization_hdr", "//include/gpu:GrBackendSurface_hdr", @@ -408,6 +409,7 @@ generated_cc_atom( deps = [ ":SkSurface_Base_hdr", "//include/core:SkCanvas_hdr", + "//include/core:SkCapabilities_hdr", "//include/core:SkMallocPixelRef_hdr", "//include/private:SkImageInfoPriv_hdr", "//src/core:SkDevice_hdr", @@ -424,6 +426,7 @@ generated_cc_atom( ":SkRescaleAndReadPixels_hdr", ":SkSurface_Base_hdr", "//include/core:SkCanvas_hdr", + "//include/core:SkCapabilities_hdr", "//include/gpu:GrBackendSurface_hdr", "//include/utils:SkNoDrawCanvas_hdr", "//src/core:SkAutoPixmapStorage_hdr", diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index 622e22c51c..6d37b8afdc 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -8,6 +8,7 @@ #include #include #include "include/core/SkCanvas.h" +#include "include/core/SkCapabilities.h" #include "src/core/SkAutoPixmapStorage.h" #include "src/core/SkImagePriv.h" #include "src/core/SkPaintPriv.h" @@ -205,6 +206,10 @@ SkCanvas* SkSurface::getCanvas() { return asSB(this)->getCachedCanvas(); } +sk_sp SkSurface::capabilities() { + return asSB(this)->onCapabilities(); +} + sk_sp SkSurface::makeImageSnapshot() { return asSB(this)->refCachedImage(); } @@ -410,6 +415,10 @@ protected: void onWritePixels(const SkPixmap&, int x, int y) override {} void onDraw(SkCanvas*, SkScalar, SkScalar, const SkSamplingOptions&, const SkPaint*) override {} bool onCopyOnWrite(ContentChangeMode) override { return true; } + sk_sp onCapabilities() override { + // Not really, but we have to return *something* + return SkCapabilities::RasterBackend(); + } }; sk_sp SkSurface::MakeNull(int width, int height) { diff --git a/src/image/SkSurface_Base.h b/src/image/SkSurface_Base.h index f018d9472e..a6d5e6f236 100644 --- a/src/image/SkSurface_Base.h +++ b/src/image/SkSurface_Base.h @@ -137,6 +137,8 @@ public: return false; } + virtual sk_sp onCapabilities() = 0; + inline SkCanvas* getCachedCanvas(); inline sk_sp refCachedImage(); diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 6fd6c8b5ae..4c50ac2b57 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -8,6 +8,7 @@ #include "src/image/SkSurface_Gpu.h" #include "include/core/SkCanvas.h" +#include "include/core/SkCapabilities.h" #include "include/core/SkDeferredDisplayList.h" #include "include/core/SkSurfaceCharacterization.h" #include "include/gpu/GrBackendSurface.h" @@ -391,6 +392,10 @@ bool SkSurface_Gpu::onDraw(sk_sp ddl, SkIPoint offs return true; } +sk_sp SkSurface_Gpu::onCapabilities() { + return fDevice->recordingContext()->skCapabilities(); +} + /////////////////////////////////////////////////////////////////////////////// sk_sp SkSurface::MakeRenderTarget(GrRecordingContext* rContext, diff --git a/src/image/SkSurface_Gpu.h b/src/image/SkSurface_Gpu.h index 39e5ed76e1..ea9d5190b9 100644 --- a/src/image/SkSurface_Gpu.h +++ b/src/image/SkSurface_Gpu.h @@ -57,6 +57,7 @@ public: const SkPaint* paint) override; bool onDraw(sk_sp, SkIPoint offset) override; + sk_sp onCapabilities() override; skgpu::BaseDevice* getDevice(); private: diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index 4376d9c483..f02fd809f2 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp @@ -6,6 +6,7 @@ */ #include "include/core/SkCanvas.h" +#include "include/core/SkCapabilities.h" #include "include/core/SkMallocPixelRef.h" #include "include/private/SkImageInfoPriv.h" #include "src/core/SkDevice.h" @@ -26,6 +27,7 @@ public: void onDraw(SkCanvas*, SkScalar, SkScalar, const SkSamplingOptions&, const SkPaint*) override; bool onCopyOnWrite(ContentChangeMode) override; void onRestoreBackingMutability() override; + sk_sp onCapabilities() override; private: SkBitmap fBitmap; @@ -153,6 +155,10 @@ bool SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { return true; } +sk_sp SkSurface_Raster::onCapabilities() { + return SkCapabilities::RasterBackend(); +} + /////////////////////////////////////////////////////////////////////////////// sk_sp SkSurface::MakeRasterDirectReleaseProc(const SkImageInfo& info, void* pixels, diff --git a/src/sksl/BUILD.bazel b/src/sksl/BUILD.bazel index 98b7e611b6..932f893b52 100644 --- a/src/sksl/BUILD.bazel +++ b/src/sksl/BUILD.bazel @@ -875,6 +875,7 @@ generated_cc_atom( deps = [ ":SkSLGLSL_hdr", "//include/core:SkTypes_hdr", + "//include/sksl:SkSLVersion_hdr", "//src/core:SkSLTypeShared_hdr", ], ) diff --git a/src/sksl/SkSLUtil.h b/src/sksl/SkSLUtil.h index f9095f2278..3c5e2f2240 100644 --- a/src/sksl/SkSLUtil.h +++ b/src/sksl/SkSLUtil.h @@ -8,6 +8,7 @@ #ifndef SKSL_UTIL #define SKSL_UTIL +#include "include/sksl/SkSLVersion.h" #include "src/core/SkSLTypeShared.h" #include "src/sksl/SkSLGLSL.h" @@ -180,6 +181,17 @@ struct ShaderCaps { return fSecondExternalTextureExtensionString; } + /** + * SkSL 300 requires support for derivatives, nonsquare matrices and bitwise integer operations. + */ + SkSL::Version supportedSkSLVerion() const { + if (fShaderDerivativeSupport && fNonsquareMatrixSupport && fIntegerSupport && + fGLSLGeneration >= SkSL::GLSLGeneration::k330) { + return SkSL::Version::k300; + } + return SkSL::Version::k100; + } + SkSL::GLSLGeneration generation() const { return fGLSLGeneration; } SkSL::GLSLGeneration fGLSLGeneration = SkSL::GLSLGeneration::k330; diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index 85f7807054..f550f5ce28 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -5965,6 +5965,7 @@ generated_cc_atom( "//include/private:SkSLProgramElement_hdr", "//include/private:SkSLProgramKind_hdr", "//include/sksl:DSLCore_hdr", + "//include/sksl:SkSLVersion_hdr", "//src/core:SkRuntimeEffectPriv_hdr", "//src/gpu/ganesh:GrCaps_hdr", "//src/gpu/ganesh:GrDirectContextPriv_hdr", diff --git a/tests/SkSLTest.cpp b/tests/SkSLTest.cpp index 913d842b25..9c34e9520b 100644 --- a/tests/SkSLTest.cpp +++ b/tests/SkSLTest.cpp @@ -24,6 +24,7 @@ #include "include/private/SkSLProgramElement.h" #include "include/private/SkSLProgramKind.h" #include "include/sksl/DSLCore.h" +#include "include/sksl/SkSLVersion.h" #include "src/core/SkRuntimeEffectPriv.h" #include "src/gpu/ganesh/GrCaps.h" #include "src/gpu/ganesh/GrDirectContextPriv.h" @@ -232,8 +233,9 @@ static void test_cpu(skiatest::Reporter* r, const char* testFile, int flags) { static void test_gpu(skiatest::Reporter* r, GrDirectContext* ctx, const char* testFile, int flags) { // If this is an ES3-only test on a GPU which doesn't support SkSL ES3, return immediately. bool shouldRunGPU = (flags & SkSLTestFlags::GPU); - bool shouldRunGPU_ES3 = (flags & SkSLTestFlags::GPU_ES3) && - ctx->priv().caps()->shaderCaps()->supportsSkSLES3(); + bool shouldRunGPU_ES3 = + (flags & SkSLTestFlags::GPU_ES3) && + (ctx->priv().caps()->shaderCaps()->supportedSkSLVerion() >= SkSL::Version::k300); if (!shouldRunGPU && !shouldRunGPU_ES3) { return; }